# HG changeset patch # User iuc # Date 1525356998 14400 # Node ID 973f03d82c86b5aeb0c34216feb6c86a1d274cd2 # Parent 1ea4e668bf73c9ac63dd363fd14d040e7ff82147 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/query_tabular commit 6a362345c31764c28bb6328da1f0d81ef8f35d40 diff -r 1ea4e668bf73 -r 973f03d82c86 macros.xml --- a/macros.xml Mon Nov 06 23:20:29 2017 -0500 +++ b/macros.xml Thu May 03 10:16:38 2018 -0400 @@ -106,6 +106,13 @@ + + + By default: tables are named: t1,t2,...,tn and columns in each table: c1,c2,...,cn + + ^(?ims)\s*select\s+.*\s+from\s+.*$ + + diff -r 1ea4e668bf73 -r 973f03d82c86 query_db.py --- a/query_db.py Mon Nov 06 23:20:29 2017 -0500 +++ b/query_db.py Thu May 03 10:16:38 2018 -0400 @@ -59,9 +59,13 @@ def run_query(conn, query, outputFile, no_header=False, comment_char='#'): cur = conn.cursor() results = cur.execute(query) - if not no_header: - outputFile.write("%s%s\n" % (comment_char, '\t'.join( - [str(col[0]) for col in cur.description]))) - for i, row in enumerate(results): - outputFile.write("%s\n" % '\t'.join( - [str(val) if val is not None else '' for val in row])) + if outputFile is not None: + if not no_header: + outputFile.write("%s%s\n" % (comment_char, '\t'.join( + [str(col[0]) for col in cur.description]))) + for i, row in enumerate(results): + outputFile.write("%s\n" % '\t'.join( + [str(val) if val is not None else '' for val in row])) + else: + conn.commit() + return results diff -r 1ea4e668bf73 -r 973f03d82c86 query_tabular.py --- a/query_tabular.py Mon Nov 06 23:20:29 2017 -0500 +++ b/query_tabular.py Thu May 03 10:16:38 2018 -0400 @@ -59,6 +59,9 @@ help='comment character to prefix column header line') parser.add_option('-o', '--output', dest='output', default=None, help='Output file for query results') + parser.add_option('-d', '--debug', dest='debug', default=False, + action='store_true', + help='Output info to stderr') (options, args) = parser.parse_args() # determine output destination @@ -109,9 +112,35 @@ try: with open(options.jsonfile) as fh: tdef = json.load(fh) + if options.debug: + print('JSON: %s' % tdef, file=sys.stderr) if 'tables' in tdef: for ti, table in enumerate(tdef['tables']): _create_table(ti, table) + if 'sql_stmts' in tdef: + for si, stmt in enumerate(tdef['sql_stmts']): + rowcount = run_query(get_connection(options.sqlitedb), stmt, None) + if options.debug: + print('\nDB modification: %s \nrowcount: %s' % + (stmt, rowcount), file=sys.stderr) + if 'queries' in tdef: + for qi, qstmt in enumerate(tdef['queries']): + if 'header' in qstmt: + no_header = False + comment_char = qstmt['header'] + else: + no_header = True + comment_char = None + with open(qstmt['result_file'], 'w') as fh: + query = qstmt['query'] + rowcount = run_query(get_connection(options.sqlitedb), + query, + fh, + no_header=no_header, + comment_char=comment_char) + if options.debug: + print('\nSQL: %s \nrowcount: %s' % + (query, rowcount), file=sys.stderr) except Exception as e: exit('Error: %s' % (e)) @@ -131,9 +160,13 @@ exit('Error: %s' % (e)) else: try: - run_query(get_connection(options.sqlitedb), query, outputFile, - no_header=options.no_header, - comment_char=options.comment_char) + rowcount = run_query(get_connection(options.sqlitedb), + query, outputFile, + no_header=options.no_header, + comment_char=options.comment_char) + if options.debug: + print('\nSQL: %s \nrowcount: %s' % + (query, rowcount), file=sys.stderr) except Exception as e: exit('Error: %s' % (e)) diff -r 1ea4e668bf73 -r 973f03d82c86 query_tabular.xml --- a/query_tabular.xml Mon Nov 06 23:20:29 2017 -0500 +++ b/query_tabular.xml Thu May 03 10:16:38 2018 -0400 @@ -1,4 +1,4 @@ - + using sqlite sql @@ -17,7 +17,7 @@ cp '$add_to_database.withdb' '$workdb' && #end if #end if - python '$__tool_directory__/query_tabular.py' + python '$__tool_directory__/query_tabular.py' -d #if $save_db -s '$sqlitedb' #else @@ -88,6 +88,30 @@ #end if #set $jtbls += [$jtbl] #end for +#set $jstmts = [] +#for $i,$stmt in enumerate($modify_database.sql_stmts): + #set $jstmts += [str($stmt.sqlstmt)] +#end for +#if len($jstmts) > 0: + #set $jtbldef['sql_stmts'] = $jstmts +#end if +#set $jqueries = [] +#for $i,$query in enumerate($addqueries.queries): + #set $jquery = dict() + #set $jquery['query'] = str($query.sqlquery) + #set $jquery['result_file'] = 'results' + str($i) + '.tsv' + #if $query.query_result.header == 'yes': + #set $header_prefix = '' + #if $query.query_result.header_prefix: + #set $header_prefix = chr(int(str($query.query_result.header_prefix))) + #end if + #set $jquery['header'] = $header_prefix + #end if + #set $jqueries += [$jquery] +#end for +#if len($jqueries) > 0: + #set $jtbldef['queries'] = $jqueries +#end if #echo $json.dumps($jtbldef) @@ -132,14 +156,24 @@ +
+ + + These modify the SQLite database + + + +
- - By default: tables are named: t1,t2,...,tn and columns in each table: c1,c2,...,cn - - ^(?ims)\s*select\s+.*\s+from\s+.*$ - + +
+ + + + +
@@ -148,6 +182,15 @@ not save_db or (sqlquery and len(sqlquery.strip()) > 0) + + len(addqueries['queries']) > 0 + + + len(addqueries['queries']) > 1 + + + len(addqueries['queries']) > 2 + @@ -448,6 +491,46 @@ + + + +
+ + + + + + +
+
+ + + +
+
+
+ + + +
+ + + + + +
+ + + + + + + +
+ + +
+