# HG changeset patch # User fabio # Date 1517520197 18000 # Node ID 039e8e1e8b1febe479356b7990e5bca8b605c48d # Parent 0d0f7080b55c57aaee9a22e9d533cdef938e5061 Uploaded 20180201 diff -r 0d0f7080b55c -r 039e8e1e8b1f ._.shed.yml Binary file ._.shed.yml has changed diff -r 0d0f7080b55c -r 039e8e1e8b1f ._example.tsv Binary file ._example.tsv has changed diff -r 0d0f7080b55c -r 039e8e1e8b1f ._query.py Binary file ._query.py has changed diff -r 0d0f7080b55c -r 039e8e1e8b1f ._query.xml Binary file ._query.xml has changed diff -r 0d0f7080b55c -r 039e8e1e8b1f query.py --- a/query.py Wed Jan 31 17:29:13 2018 -0500 +++ b/query.py Thu Feb 01 16:23:17 2018 -0500 @@ -3,7 +3,7 @@ # https://github.com/ross/requests-futures # http://docs.python-requests.org/en/master/user/quickstart/#more-complicated-post-requests -import os, uuid, optparse, requests, json, time +import sys, os, uuid, optparse, requests, json, time #from requests_futures.sessions import FuturesSession #### NN14 #### @@ -16,9 +16,17 @@ QUERY_DELAY = 30; ############## +__version__ = "1.0.0"; VALID_CHARS = '.-()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ' +# in the case of collections, exitcodes equal to 0 and 1 are not considered errors +def raiseException( exitcode, message, errorfilepath ): + with open(errorfilepath, 'w') as out: + out.write(message); + sys.exit(exitcode); + def query_request( options, args, payload ): + output_dir_path = options.outputdir; # add additional parameters to the payload #payload["tree_id"] = str(options.treeid); payload["search_mode"] = str(options.search); @@ -32,7 +40,7 @@ # make a synchronous post request to the query route req = session.post(QUERY_URL, headers=headers, json=payload); resp_code = req.status_code; - print(str(req.content)+"\n\n"); + #print(str(req.content)+"\n\n"); if resp_code == requests.codes.ok: resp_content = str(req.content); # convert out to json @@ -42,7 +50,6 @@ task_processed = False; # results json content json_status_content = None; - task_status = None; while task_processed is False: # create a new session session = requests.Session(); @@ -50,7 +57,7 @@ status_query_url = STATUS_URL.replace("", task_id); status_req = session.get(status_query_url); status_resp_content = str(status_req.content); - print(status_resp_content+"\n\n"); + #print(status_resp_content+"\n\n"); # convert out to json json_status_content = json.loads(status_resp_content); # take a look at the state @@ -59,16 +66,11 @@ task_processed = True; break; elif json_status_content['state'] in ['FAILURE', 'REVOKED']: - return "Task status: "+str(json_status_content['state']); + return raiseException( 1, "Task ID: "+str(task_id)+"\nTask status: "+str(json_status_content['state']), str(options.errorfile) ); else: time.sleep(QUERY_DELAY); # in seconds - # get output dir (collection) path - output_dir_path = options.outputdir; - if not os.path.exists(output_dir_path): - os.makedirs(output_dir_path); out_file_format = "tabular"; - for block in json_status_content['results']: seq_id = block['sequence_id']; accessions = block['accession_numbers']; @@ -79,10 +81,12 @@ accessions_list = accessions_list + accession_number + "\n"; with open(output_file_path, 'w') as out: out.write(accessions_list.strip()); + return sys.exit(0); else: - return "Unable to query the remote server. Please try again in a while."; + return raiseException( 1, "Unable to query the remote server. Please try again in a while.", str(options.errorfile) ); def query( options, args ): + output_dir_path = options.outputdir; multiple_data = {}; comma_sep_file_paths = options.files; #print("files: "+str(comma_sep_file_paths)+" - "+str(type(comma_sep_file_paths))); @@ -106,13 +110,13 @@ seq_id = ''.join(e for e in seq_id if e in VALID_CHARS) seq_text = line_split[1]; if seq_id in multiple_data: - return "Error: the id '"+seq_id+"' is duplicated"; + return raiseException( 1, "Error: the id '"+seq_id+"' is duplicated", str(options.errorfile) ); multiple_data[seq_id] = seq_text; if len(multiple_data) > 0: return query_request( options, args, multiple_data ); #return echo( options, args ); else: - return "An error has occurred. Please be sure that your input files are valid."; + return raiseException( 1, "An error has occurred. Please be sure that your input files are valid.", str(options.errorfile) ); else: # try with the sequence in --sequence text_content = options.sequences; @@ -132,21 +136,23 @@ seq_id = ''.join(e for e in seq_id if e in VALID_CHARS) seq_text = line_split[1]; if seq_id in multiple_data: - return "Error: the id '"+seq_id+"' is duplicated"; + return raiseException( 1, "Error: the id '"+seq_id+"' is duplicated", str(options.errorfile) ); multiple_data[seq_id] = seq_text; if len(multiple_data) > 0: return query_request( options, args, multiple_data ); #return echo( options, args ); else: - return "An error has occurred. Please be sure that your input files are valid."; + return raiseException( 1, "An error has occurred. Please be sure that your input files are valid.", str(options.errorfile) ); else: - return "You have to insert at least one row formatted as a tab delimited touple"; - return -1; + return raiseException( 1, "You have to insert at least one row formatted as a tab delimited (ID, SEQUENCE) couple", str(options.errorfile) ); + return 1; def __main__(): # Parse the command line options usage = "Usage: query.py --files comma_sep_file_paths --names comma_seq_file_names --sequences sequences_text --search search_mode --exact exact_alg --sthreshold threshold --outputdir output_dir_path"; parser = optparse.OptionParser(usage = usage); + parser.add_option("-v", "--version", action="store_true", dest="version", + default=False, help="display version and exit") parser.add_option("-f", "--files", type="string", action="store", dest="files", help="comma separated files path"); parser.add_option("-n", "--names", type="string", @@ -161,23 +167,24 @@ action="store", dest="exact", help="exact algorithm (required if search is 1 only)"); parser.add_option("-t", "--sthreshold", type="float", action="store", dest="sthreshold", help="threshold applied to the search algrithm"); - parser.add_option("-o", "--outputdir", type="string", + parser.add_option("-o", "--outputdir", type="string", default="output", action="store", dest="outputdir", help="output directory (collection) path"); + parser.add_option("-r", "--errorfile", type="string", default="error.log", + action="store", dest="errorfile", help="error file name containing error messages"); - #parser.add_option("-k", "--outfile", type="string", - #action="store", dest="outfile", help="output file"); - # TEST - #--search 'rrr' - #--sthreshold 0.5 - #--exact 0 - #--sequences 'id0__tc__CAATTAATGATAAATATTTTATAAGGTGCGGAAATAAAGTGAGGAATATCTTTTAAATTCAAGTTCAATTCTGAAAGC' - #--outputdir 'collection_content' #sequences = 'NM_001169378.2__tc__atttcggatgctttggagggaggaactctagtgctgcattgattggggcgtgtgttaatgatattcccagttcgcatggcgagcatcgattcctggtacgtatgtgggccccttgactcccacttatcgcacttgtcgttcgcaatttgcatgaattccgcttcgtctgaaacgcacttgcgccagacttctccggctggtctgatctggtctgtgatccggtctggtggggcgccagttgcgtttcgagctcatcaccagtcactccgcagtcgcattctgccagaggtctccgatcaagagcgcttctccattcgagattcaaacgcagcgcggtctgacgccgccacatcgagtgaaatccatatcgatggccacattcacacaggacgagatcgacttcctgcgcagccatggcaacgagctgtgtgccaagacctggctgggattgtgggatccgaagcgggctgtgcaccagcaggagcagcgcgaactgatgatggacaagtatgagcggaagcgatactacctggagccggccagtcctcttaagtcgctggccaatgcggtcaacctgaagtcgtctgctccggcgacgaaccacactcagaatggccaccaaaatgggtatgccagcatccatttgacgcctcctgctgcccagcggacctcggccaatggattgcagaaggtggccaactcgtcgagtaactcttctggaaagacctcatcctcgatcagtaggccacactataatcaccagaacaacagccaaaacaacaatcacgatgcctttggcctgggtggcggattgagcagcctgaacagcgccggttccacatccactggagctctttccgacaccagcagttgtgctagcaatggcttcggtgcggactgcgactttgtggctgactttggctcggccaacattttcgacgccacatcggcgcgttccacaggatcgccggcggtgtcgtccgtgtcctcagtgggttccagcaatggctacgccaaggtgcagcccatccgggcagctcatctccagcagcaacagcagttgcagcagcagctgcatcagcagcagctcctcaatggcaatggtcatcagggcactgagaactttgccgacttcgatcacgctcccatctacaatgcagtggctccaccgacttttaacgattggatcagcgactggagcaggcggggcttccacgatcccttcgacgattgcgatgactcgccaccaggtgcccgccctccagcacctgcgccagctcctgctcaagttcccgcagtatcatcaccattgccaaccgtccgagaagaaccagagcttgcgtggaatttttgggaggacgagatgcgaatagaggcgcaggaaaaggagtcccaaactaaacagccggagttgggctactccttttcgattagtactactacgcccctttccccttcgaatcccttcctgccctaccttgtcagtgaggagcagcatcgaaatcatccagagaagccctccttttcgtattcgttgttcagctccatatcaaatagttcgcaagaagatcaggcggatgatcatgagatgaatgttttaaatgccaatttccatgatttctttacgtggagtgctcccttgcagaacggccatacgaccagtccgcccaagggcggaaatgcagcgatggcgcccagtgaggatcgatatgccgctcttaaggatctcgacgagcagctgcgagaactgaaggccagcgaaagcgccacagagacgcccacgcccaccagtggcaatgttcaggccacagatgcctttggtggagccctcaacaacaatccaaatcccttcaagggccagcaacagcagcagctcagcagccatgtggtgaatccattccagcagcagcaacagcagcagcaccagcagaatctctatggccagttgacgctcataccaaatgcctacggcagcagttcccagcagcagatggggcaccatctcctccagcagcagcagcagcaacagcagagcttcttcaacttcaacaacaacgggttcgccatctcgcagggtctgcccaacggctgcggcttcggcagcatgcaacccgctcctgtgatggccaacaatccctttgcagccagcggcgccatgaacaccaacaatccattcttatgagactcaacccgggagaatccgcctcgcgccacctggcagaggcgctgagccagcgaacaaagagcagacgcggaggaaccgaaccgaaattagtccattttactaacaatagcgttaatctatgtatacataatgcacgccggagagcactctttgtgtacatagcccaaatatgtacacccgaaaggctccacgctgacgctagtcctcgcggatggcggaggcggactggggcgttgatatattcttttacatggtaactctactctaacgtttacggatacggatatttgtatttgccgtttgccctagaactctatacttgtactaagcgcccatgaacacttcatccactaacatagctactaatcctcatcctagtggaggatgcagttggtccagacactctgttatttgttttatccatcctcgtacttgtctttgtcccatttagcactttcgttgcggataagaactttgtcagttattgattgtgtggccttaataagattataaaactaaatattataacgtacgactatacatatacggatacagatacagattcagacacagttagtacagatacagatatacatatacgcttttgtacctaatgaattgcttcttgtttccattgctaatcatctgcttttcgtgtgctaattttatacactagtacgtgcgatatcggccgtgcagatagattgctcagctcgcgagtcaagcctcttttggttgcacccacggcagacatttgtacatatactgtctgattgtaagcctcgtgtaatacctccattaacaccactcccccaccacccatccatcgaaccccgaatccatgactcaattcactgctcacatgtccatgcccatgccttaacgtgtcaaacattatcgaagccttaaagttatttaaaactacgaaatttcaataaaaacaaataagaacgctatc'; - #print(sequences); #(options, args) = parser.parse_args(['-x', 'rrr', '-t', 0.5, '-s', sequences, '-o', 'collection_content']); - + (options, args) = parser.parse_args(); - return query( options, args ); + if options.version: + print __version__; + else: + # create output dir (collection) + output_dir_path = options.outputdir; + if not os.path.exists(output_dir_path): + os.makedirs(output_dir_path); + + return query( options, args ); if __name__ == "__main__": __main__() diff -r 0d0f7080b55c -r 039e8e1e8b1f query.xml --- a/query.xml Wed Jan 31 17:29:13 2018 -0500 +++ b/query.xml Thu Feb 01 16:23:17 2018 -0500 @@ -34,17 +34,17 @@ - + - + - + @@ -54,9 +54,7 @@ ---- -**Example** - -The input for this tool is a list of (ID, TRANSCRIPT) touples, one for each line, +The input for this tool is a list of (ID, TRANSCRIPT) couples, one for each line, in a tab delimited format:: id0 CCAACCAAAGGGAAAACTTTTTTCCGACTTTGGCCTAAAGGGTTTAACGGCCAAGTCAGAAGGGAAAAAGTTGCGCCA