Mercurial > repos > fabio > btman
comparison query.py @ 4:69a3505ac594 draft
Uploaded 20180405
author | fabio |
---|---|
date | Wed, 04 Apr 2018 18:54:40 -0400 |
parents | 315246810bfa |
children | 300e4932bad6 |
comparison
equal
deleted
inserted
replaced
3:557d09d81807 | 4:69a3505ac594 |
---|---|
7 #from requests_futures.sessions import FuturesSession | 7 #from requests_futures.sessions import FuturesSession |
8 | 8 |
9 #### NN14 #### | 9 #### NN14 #### |
10 SERVICE_URL = "http://nn14.galaxyproject.org:8080/"; | 10 SERVICE_URL = "http://nn14.galaxyproject.org:8080/"; |
11 #service_url = "http://127.0.0.1:8082/"; | 11 #service_url = "http://127.0.0.1:8082/"; |
12 QUERY_URL = SERVICE_URL+"tree/1/query"; | 12 QUERY_URL = SERVICE_URL+"tree/<tree_id>/query"; |
13 STATUS_URL = SERVICE_URL+"status/<query_id>"; | 13 STATUS_URL = SERVICE_URL+"status/<query_id>"; |
14 ############## | 14 ############## |
15 # query delay in seconds | 15 # query delay in seconds |
16 QUERY_DELAY = 30; | 16 QUERY_DELAY = 30; |
17 ############## | 17 ############## |
39 headers = {'Content-type': 'application/json'}; | 39 headers = {'Content-type': 'application/json'}; |
40 | 40 |
41 # create a session | 41 # create a session |
42 session = requests.Session(); | 42 session = requests.Session(); |
43 # make a synchronous post request to the query route | 43 # make a synchronous post request to the query route |
44 req = session.post(QUERY_URL, headers=headers, json=payload); | 44 QUERY_URL.replace("<tree_id>", str(options.treeid)); |
45 req = session.post(QUERY_URL.replace("<tree_id>", str(options.treeid)), headers=headers, json=payload); | |
45 resp_code = req.status_code; | 46 resp_code = req.status_code; |
46 #print(str(req.content)+"\n\n"); | 47 #print(str(req.content)+"\n\n"); |
47 if resp_code == requests.codes.ok: | 48 if resp_code == requests.codes.ok: |
48 resp_content = str(req.content); | 49 resp_content = str(req.content); |
49 # convert out to json | 50 # convert out to json |
78 seq_id = block['sequence_id']; | 79 seq_id = block['sequence_id']; |
79 # put response block in the output collection | 80 # put response block in the output collection |
80 output_file_path = os.path.join(output_dir_path, seq_id + "_" + out_file_format); | 81 output_file_path = os.path.join(output_dir_path, seq_id + "_" + out_file_format); |
81 accessions_list = ""; | 82 accessions_list = ""; |
82 hits_block = block['hits']; | 83 hits_block = block['hits']; |
84 accessions_dict = { }; | |
85 is_sabutan = False; | |
83 for hit in hits_block: | 86 for hit in hits_block: |
84 if type(hit) is dict: # sabutan | 87 if type(hit) is dict: # sabutan |
85 accessions_list = accessions_list + hit['accession_number'] + "\t" + hit['score'] + "\n"; | 88 #accessions_list = accessions_list + str(hit['accession_number']) + "\t" + str(hit['score']) + "\n"; |
89 accession_number = hit['accession_number']; | |
90 score = hit['score']; | |
91 score_split = score.split("/"); | |
92 accessions_dict[accession_number] = "{0:.6f}".format(float(score_split[0])/float(score_split[1])); | |
93 is_sabutan = True; | |
86 else: # all-some | 94 else: # all-some |
87 accessions_list = accessions_list + str(hit) + "\n"; | 95 accessions_list = accessions_list + str(hit) + "\n"; |
96 if is_sabutan: | |
97 sorted_accessions = sorted(accessions_dict, key=lambda i: float(accessions_dict[i])); | |
98 for acc in sorted_accessions: | |
99 accessions_list = accessions_list + str(acc) + "\t" + str(accessions_dict[acc]) + "\n"; | |
88 with open(output_file_path, 'w') as out: | 100 with open(output_file_path, 'w') as out: |
89 out.write(accessions_list.strip()); | 101 out.write(accessions_list.strip()); |
90 return sys.exit(OK_EXIT_CODE); | 102 return sys.exit(OK_EXIT_CODE); |
91 else: | 103 else: |
92 return raiseException( ERR_EXIT_CODE, "Unable to query the remote server. Please try again in a while.", output_dir_path, str(options.errorfile) ); | 104 return raiseException( ERR_EXIT_CODE, "Unable to query the remote server. Please try again in a while.", output_dir_path, str(options.errorfile) ); |
165 action="store", dest="names", help="comma separated names associated to the files specified in --files"); | 177 action="store", dest="names", help="comma separated names associated to the files specified in --files"); |
166 parser.add_option("-s", "--sequences", type="string", | 178 parser.add_option("-s", "--sequences", type="string", |
167 action="store", dest="sequences", help="contains a list of sequences (one for each row)"); | 179 action="store", dest="sequences", help="contains a list of sequences (one for each row)"); |
168 parser.add_option("-a", "--fasta", type="string", | 180 parser.add_option("-a", "--fasta", type="string", |
169 action="store", dest="fasta", help="contains the content of a fasta file"); | 181 action="store", dest="fasta", help="contains the content of a fasta file"); |
170 parser.add_option("-x", "--search", type="string", default=0, | 182 parser.add_option("-x", "--search", type="string", default="rrr", |
171 action="store", dest="search", help="search mode"); | 183 action="store", dest="search", help="search mode"); |
172 parser.add_option("-e", "--exact", type="int", default=0, | 184 parser.add_option("-e", "--exact", type="int", default=0, |
173 action="store", dest="exact", help="exact algorithm (required if search is 1 only)"); | 185 action="store", dest="exact", help="exact algorithm (required if search is 1 only)"); |
186 parser.add_option("-k", "--tree", type="int", default=0, | |
187 action="store", dest="treeid", help="the id of the tree that will be queried"); | |
174 parser.add_option("-t", "--sthreshold", type="float", | 188 parser.add_option("-t", "--sthreshold", type="float", |
175 action="store", dest="sthreshold", help="threshold applied to the search algrithm"); | 189 action="store", dest="sthreshold", help="threshold applied to the search algrithm"); |
176 parser.add_option("-o", "--outputdir", type="string", default="output", | 190 parser.add_option("-o", "--outputdir", type="string", default="output", |
177 action="store", dest="outputdir", help="output directory (collection) path"); | 191 action="store", dest="outputdir", help="output directory (collection) path"); |
178 parser.add_option("-r", "--errorfile", type="string", default="error.log", | 192 parser.add_option("-r", "--errorfile", type="string", default="error_txt", |
179 action="store", dest="errorfile", help="error file name containing error messages"); | 193 action="store", dest="errorfile", help="error file name containing error messages"); |
180 | 194 |
181 # TEST | 195 # TEST |
182 #sequences = 'NM_001169378.2__tc__atttcggatgctttggagggaggaactctagtgctgcattgattggggcgtgtgttaatgatattcccagttcgcatggcgagcatcgattcctggtacgtatgtgggccccttgactcccacttatcgcacttgtcgttcgcaatttgcatgaattccgcttcgtctgaaacgcacttgcgccagacttctccggctggtctgatctggtctgtgatccggtctggtggggcgccagttgcgtttcgagctcatcaccagtcactccgcagtcgcattctgccagaggtctccgatcaagagcgcttctccattcgagattcaaacgcagcgcggtctgacgccgccacatcgagtgaaatccatatcgatggccacattcacacaggacgagatcgacttcctgcgcagccatggcaacgagctgtgtgccaagacctggctgggattgtgggatccgaagcgggctgtgcaccagcaggagcagcgcgaactgatgatggacaagtatgagcggaagcgatactacctggagccggccagtcctcttaagtcgctggccaatgcggtcaacctgaagtcgtctgctccggcgacgaaccacactcagaatggccaccaaaatgggtatgccagcatccatttgacgcctcctgctgcccagcggacctcggccaatggattgcagaaggtggccaactcgtcgagtaactcttctggaaagacctcatcctcgatcagtaggccacactataatcaccagaacaacagccaaaacaacaatcacgatgcctttggcctgggtggcggattgagcagcctgaacagcgccggttccacatccactggagctctttccgacaccagcagttgtgctagcaatggcttcggtgcggactgcgactttgtggctgactttggctcggccaacattttcgacgccacatcggcgcgttccacaggatcgccggcggtgtcgtccgtgtcctcagtgggttccagcaatggctacgccaaggtgcagcccatccgggcagctcatctccagcagcaacagcagttgcagcagcagctgcatcagcagcagctcctcaatggcaatggtcatcagggcactgagaactttgccgacttcgatcacgctcccatctacaatgcagtggctccaccgacttttaacgattggatcagcgactggagcaggcggggcttccacgatcccttcgacgattgcgatgactcgccaccaggtgcccgccctccagcacctgcgccagctcctgctcaagttcccgcagtatcatcaccattgccaaccgtccgagaagaaccagagcttgcgtggaatttttgggaggacgagatgcgaatagaggcgcaggaaaaggagtcccaaactaaacagccggagttgggctactccttttcgattagtactactacgcccctttccccttcgaatcccttcctgccctaccttgtcagtgaggagcagcatcgaaatcatccagagaagccctccttttcgtattcgttgttcagctccatatcaaatagttcgcaagaagatcaggcggatgatcatgagatgaatgttttaaatgccaatttccatgatttctttacgtggagtgctcccttgcagaacggccatacgaccagtccgcccaagggcggaaatgcagcgatggcgcccagtgaggatcgatatgccgctcttaaggatctcgacgagcagctgcgagaactgaaggccagcgaaagcgccacagagacgcccacgcccaccagtggcaatgttcaggccacagatgcctttggtggagccctcaacaacaatccaaatcccttcaagggccagcaacagcagcagctcagcagccatgtggtgaatccattccagcagcagcaacagcagcagcaccagcagaatctctatggccagttgacgctcataccaaatgcctacggcagcagttcccagcagcagatggggcaccatctcctccagcagcagcagcagcaacagcagagcttcttcaacttcaacaacaacgggttcgccatctcgcagggtctgcccaacggctgcggcttcggcagcatgcaacccgctcctgtgatggccaacaatccctttgcagccagcggcgccatgaacaccaacaatccattcttatgagactcaacccgggagaatccgcctcgcgccacctggcagaggcgctgagccagcgaacaaagagcagacgcggaggaaccgaaccgaaattagtccattttactaacaatagcgttaatctatgtatacataatgcacgccggagagcactctttgtgtacatagcccaaatatgtacacccgaaaggctccacgctgacgctagtcctcgcggatggcggaggcggactggggcgttgatatattcttttacatggtaactctactctaacgtttacggatacggatatttgtatttgccgtttgccctagaactctatacttgtactaagcgcccatgaacacttcatccactaacatagctactaatcctcatcctagtggaggatgcagttggtccagacactctgttatttgttttatccatcctcgtacttgtctttgtcccatttagcactttcgttgcggataagaactttgtcagttattgattgtgtggccttaataagattataaaactaaatattataacgtacgactatacatatacggatacagatacagattcagacacagttagtacagatacagatatacatatacgcttttgtacctaatgaattgcttcttgtttccattgctaatcatctgcttttcgtgtgctaattttatacactagtacgtgcgatatcggccgtgcagatagattgctcagctcgcgagtcaagcctcttttggttgcacccacggcagacatttgtacatatactgtctgattgtaagcctcgtgtaatacctccattaacaccactcccccaccacccatccatcgaaccccgaatccatgactcaattcactgctcacatgtccatgcccatgccttaacgtgtcaaacattatcgaagccttaaagttatttaaaactacgaaatttcaataaaaacaaataagaacgctatc'; | 196 #sequences = 'NM_001169378.2__tc__atttcggatgctttggagggaggaactctagtgctgcattgattggggcgtgtgttaatgatattcccagttcgcatggcgagcatcgattcctggtacgtatgtgggccccttgactcccacttatcgcacttgtcgttcgcaatttgcatgaattccgcttcgtctgaaacgcacttgcgccagacttctccggctggtctgatctggtctgtgatccggtctggtggggcgccagttgcgtttcgagctcatcaccagtcactccgcagtcgcattctgccagaggtctccgatcaagagcgcttctccattcgagattcaaacgcagcgcggtctgacgccgccacatcgagtgaaatccatatcgatggccacattcacacaggacgagatcgacttcctgcgcagccatggcaacgagctgtgtgccaagacctggctgggattgtgggatccgaagcgggctgtgcaccagcaggagcagcgcgaactgatgatggacaagtatgagcggaagcgatactacctggagccggccagtcctcttaagtcgctggccaatgcggtcaacctgaagtcgtctgctccggcgacgaaccacactcagaatggccaccaaaatgggtatgccagcatccatttgacgcctcctgctgcccagcggacctcggccaatggattgcagaaggtggccaactcgtcgagtaactcttctggaaagacctcatcctcgatcagtaggccacactataatcaccagaacaacagccaaaacaacaatcacgatgcctttggcctgggtggcggattgagcagcctgaacagcgccggttccacatccactggagctctttccgacaccagcagttgtgctagcaatggcttcggtgcggactgcgactttgtggctgactttggctcggccaacattttcgacgccacatcggcgcgttccacaggatcgccggcggtgtcgtccgtgtcctcagtgggttccagcaatggctacgccaaggtgcagcccatccgggcagctcatctccagcagcaacagcagttgcagcagcagctgcatcagcagcagctcctcaatggcaatggtcatcagggcactgagaactttgccgacttcgatcacgctcccatctacaatgcagtggctccaccgacttttaacgattggatcagcgactggagcaggcggggcttccacgatcccttcgacgattgcgatgactcgccaccaggtgcccgccctccagcacctgcgccagctcctgctcaagttcccgcagtatcatcaccattgccaaccgtccgagaagaaccagagcttgcgtggaatttttgggaggacgagatgcgaatagaggcgcaggaaaaggagtcccaaactaaacagccggagttgggctactccttttcgattagtactactacgcccctttccccttcgaatcccttcctgccctaccttgtcagtgaggagcagcatcgaaatcatccagagaagccctccttttcgtattcgttgttcagctccatatcaaatagttcgcaagaagatcaggcggatgatcatgagatgaatgttttaaatgccaatttccatgatttctttacgtggagtgctcccttgcagaacggccatacgaccagtccgcccaagggcggaaatgcagcgatggcgcccagtgaggatcgatatgccgctcttaaggatctcgacgagcagctgcgagaactgaaggccagcgaaagcgccacagagacgcccacgcccaccagtggcaatgttcaggccacagatgcctttggtggagccctcaacaacaatccaaatcccttcaagggccagcaacagcagcagctcagcagccatgtggtgaatccattccagcagcagcaacagcagcagcaccagcagaatctctatggccagttgacgctcataccaaatgcctacggcagcagttcccagcagcagatggggcaccatctcctccagcagcagcagcagcaacagcagagcttcttcaacttcaacaacaacgggttcgccatctcgcagggtctgcccaacggctgcggcttcggcagcatgcaacccgctcctgtgatggccaacaatccctttgcagccagcggcgccatgaacaccaacaatccattcttatgagactcaacccgggagaatccgcctcgcgccacctggcagaggcgctgagccagcgaacaaagagcagacgcggaggaaccgaaccgaaattagtccattttactaacaatagcgttaatctatgtatacataatgcacgccggagagcactctttgtgtacatagcccaaatatgtacacccgaaaggctccacgctgacgctagtcctcgcggatggcggaggcggactggggcgttgatatattcttttacatggtaactctactctaacgtttacggatacggatatttgtatttgccgtttgccctagaactctatacttgtactaagcgcccatgaacacttcatccactaacatagctactaatcctcatcctagtggaggatgcagttggtccagacactctgttatttgttttatccatcctcgtacttgtctttgtcccatttagcactttcgttgcggataagaactttgtcagttattgattgtgtggccttaataagattataaaactaaatattataacgtacgactatacatatacggatacagatacagattcagacacagttagtacagatacagatatacatatacgcttttgtacctaatgaattgcttcttgtttccattgctaatcatctgcttttcgtgtgctaattttatacactagtacgtgcgatatcggccgtgcagatagattgctcagctcgcgagtcaagcctcttttggttgcacccacggcagacatttgtacatatactgtctgattgtaagcctcgtgtaatacctccattaacaccactcccccaccacccatccatcgaaccccgaatccatgactcaattcactgctcacatgtccatgcccatgccttaacgtgtcaaacattatcgaagccttaaagttatttaaaactacgaaatttcaataaaaacaaataagaacgctatc'; |
183 #(options, args) = parser.parse_args(['-x', 'rrr', '-t', 0.5, '-s', sequences, '-o', 'collection_content']); | 197 #(options, args) = parser.parse_args(['-x', 'rrr', '-t', 0.5, '-s', sequences, '-o', 'collection_content']); |