Mercurial > repos > fabio > sbtas_se
comparison query.py @ 6:97dd57f81d77 draft
Uploaded 20180131
author | fabio |
---|---|
date | Wed, 31 Jan 2018 15:58:36 -0500 |
parents | 35593423c2e2 |
children | 256d015d69f9 |
comparison
equal
deleted
inserted
replaced
5:5e2877685afc | 6:97dd57f81d77 |
---|---|
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/0/query"; | 12 query_url = service_url+"tree/0/query"; |
13 status_url = service_url+"status/<task_id>"; | 13 status_url = service_url+"status/<task_id>"; |
14 ############## | |
15 # query delay in seconds | |
16 query_delay = 30; | |
14 ############## | 17 ############## |
15 | 18 |
16 def query_request( options, args, payload ): | 19 def query_request( options, args, payload ): |
17 # add additional parameters to the payload | 20 # add additional parameters to the payload |
18 #payload["tree_id"] = str(options.treeid); | 21 #payload["tree_id"] = str(options.treeid); |
25 # create a session | 28 # create a session |
26 session = requests.Session(); | 29 session = requests.Session(); |
27 # make a synchronous post request to the query route | 30 # make a synchronous post request to the query route |
28 req = session.post(query_url, headers=headers, json=payload); | 31 req = session.post(query_url, headers=headers, json=payload); |
29 resp_code = req.status_code; | 32 resp_code = req.status_code; |
30 #print(str(req.content)+"\n\n"); | 33 print(str(req.content)+"\n\n"); |
31 if resp_code == requests.codes.ok: | 34 if resp_code == requests.codes.ok: |
32 resp_content = str(req.content); | 35 resp_content = str(req.content); |
33 # convert out to json | 36 # convert out to json |
34 json_content = json.loads(resp_content); | 37 json_content = json.loads(resp_content); |
35 # retrieve task id | 38 # retrieve task id |
43 session = requests.Session(); | 46 session = requests.Session(); |
44 # make a synchronous get request to the status route | 47 # make a synchronous get request to the status route |
45 status_query_url = status_url.replace("<task_id>", task_id); | 48 status_query_url = status_url.replace("<task_id>", task_id); |
46 status_req = session.get(status_query_url); | 49 status_req = session.get(status_query_url); |
47 status_resp_content = str(status_req.content); | 50 status_resp_content = str(status_req.content); |
48 #print(status_resp_content+"\n\n"); | 51 print(status_resp_content+"\n\n"); |
49 # convert out to json | 52 # convert out to json |
50 json_status_content = json.loads(status_resp_content); | 53 json_status_content = json.loads(status_resp_content); |
51 # take a look at the state | 54 # take a look at the state |
52 # state attribute is always available | 55 # state attribute is always available |
53 if json_status_content['state'] == 'SUCCESS': | 56 if json_status_content['state'] == 'SUCCESS': |
54 task_processed = True; | 57 task_processed = True; |
55 break; | 58 break; |
56 elif json_status_content['state'] in ['FAILURE', 'REVOKED']: | 59 elif json_status_content['state'] in ['FAILURE', 'REVOKED']: |
57 return "Task status: "+str(json_status_content['state']); | 60 return "Task status: "+str(json_status_content['state']); |
58 else: | 61 else: |
59 time.sleep(60); # in seconds | 62 time.sleep(query_delay); # in seconds |
60 | 63 |
61 # get output dir (collection) path | 64 # get output dir (collection) path |
62 output_dir_path = options.outputdir; | 65 output_dir_path = options.outputdir; |
63 if not os.path.exists(output_dir_path): | 66 if not os.path.exists(output_dir_path): |
64 os.makedirs(output_dir_path); | 67 os.makedirs(output_dir_path); |
100 seq_text = line_split[1]; | 103 seq_text = line_split[1]; |
101 if seq_id in multiple_data: | 104 if seq_id in multiple_data: |
102 return "Error: the id '"+seq_id+"' is duplicated"; | 105 return "Error: the id '"+seq_id+"' is duplicated"; |
103 multiple_data[seq_id] = seq_text; | 106 multiple_data[seq_id] = seq_text; |
104 if len(multiple_data) > 0: | 107 if len(multiple_data) > 0: |
105 return async_request( options, args, multiple_data ); | 108 return query_request( options, args, multiple_data ); |
106 #return echo( options, args ); | 109 #return echo( options, args ); |
107 else: | 110 else: |
108 return "An error has occurred. Please be sure that your input files are valid."; | 111 return "An error has occurred. Please be sure that your input files are valid."; |
109 else: | 112 else: |
110 # try with the sequence in --sequence | 113 # try with the sequence in --sequence |
124 seq_text = line_split[1]; | 127 seq_text = line_split[1]; |
125 if seq_id in multiple_data: | 128 if seq_id in multiple_data: |
126 return "Error: the id '"+seq_id+"' is duplicated"; | 129 return "Error: the id '"+seq_id+"' is duplicated"; |
127 multiple_data[seq_id] = seq_text; | 130 multiple_data[seq_id] = seq_text; |
128 if len(multiple_data) > 0: | 131 if len(multiple_data) > 0: |
129 return async_request( options, args, multiple_data ); | 132 return query_request( options, args, multiple_data ); |
130 #return echo( options, args ); | 133 #return echo( options, args ); |
131 else: | 134 else: |
132 return "An error has occurred. Please be sure that your input files are valid."; | 135 return "An error has occurred. Please be sure that your input files are valid."; |
133 else: | 136 else: |
134 return "You have to insert at least one row formatted as a tab delimited <id, sequence> touple"; | 137 return "You have to insert at least one row formatted as a tab delimited <id, sequence> touple"; |
162 #--search 'rrr' | 165 #--search 'rrr' |
163 #--sthreshold 0.5 | 166 #--sthreshold 0.5 |
164 #--exact 0 | 167 #--exact 0 |
165 #--sequences 'id0__tc__CAATTAATGATAAATATTTTATAAGGTGCGGAAATAAAGTGAGGAATATCTTTTAAATTCAAGTTCAATTCTGAAAGC' | 168 #--sequences 'id0__tc__CAATTAATGATAAATATTTTATAAGGTGCGGAAATAAAGTGAGGAATATCTTTTAAATTCAAGTTCAATTCTGAAAGC' |
166 #--outputdir 'collection_content' | 169 #--outputdir 'collection_content' |
167 #sequences = 'id0__tc__CAATTAATGATAAATATTTTATAAGGTGCGGAAATAAAGTGAGGAATATCTTTTAAATTCAAGTTCAATTCTGAAAGC'; | 170 #sequences = 'NM_001169378.2__tc__atttcggatgctttggagggaggaactctagtgctgcattgattggggcgtgtgttaatgatattcccagttcgcatggcgagcatcgattcctggtacgtatgtgggccccttgactcccacttatcgcacttgtcgttcgcaatttgcatgaattccgcttcgtctgaaacgcacttgcgccagacttctccggctggtctgatctggtctgtgatccggtctggtggggcgccagttgcgtttcgagctcatcaccagtcactccgcagtcgcattctgccagaggtctccgatcaagagcgcttctccattcgagattcaaacgcagcgcggtctgacgccgccacatcgagtgaaatccatatcgatggccacattcacacaggacgagatcgacttcctgcgcagccatggcaacgagctgtgtgccaagacctggctgggattgtgggatccgaagcgggctgtgcaccagcaggagcagcgcgaactgatgatggacaagtatgagcggaagcgatactacctggagccggccagtcctcttaagtcgctggccaatgcggtcaacctgaagtcgtctgctccggcgacgaaccacactcagaatggccaccaaaatgggtatgccagcatccatttgacgcctcctgctgcccagcggacctcggccaatggattgcagaaggtggccaactcgtcgagtaactcttctggaaagacctcatcctcgatcagtaggccacactataatcaccagaacaacagccaaaacaacaatcacgatgcctttggcctgggtggcggattgagcagcctgaacagcgccggttccacatccactggagctctttccgacaccagcagttgtgctagcaatggcttcggtgcggactgcgactttgtggctgactttggctcggccaacattttcgacgccacatcggcgcgttccacaggatcgccggcggtgtcgtccgtgtcctcagtgggttccagcaatggctacgccaaggtgcagcccatccgggcagctcatctccagcagcaacagcagttgcagcagcagctgcatcagcagcagctcctcaatggcaatggtcatcagggcactgagaactttgccgacttcgatcacgctcccatctacaatgcagtggctccaccgacttttaacgattggatcagcgactggagcaggcggggcttccacgatcccttcgacgattgcgatgactcgccaccaggtgcccgccctccagcacctgcgccagctcctgctcaagttcccgcagtatcatcaccattgccaaccgtccgagaagaaccagagcttgcgtggaatttttgggaggacgagatgcgaatagaggcgcaggaaaaggagtcccaaactaaacagccggagttgggctactccttttcgattagtactactacgcccctttccccttcgaatcccttcctgccctaccttgtcagtgaggagcagcatcgaaatcatccagagaagccctccttttcgtattcgttgttcagctccatatcaaatagttcgcaagaagatcaggcggatgatcatgagatgaatgttttaaatgccaatttccatgatttctttacgtggagtgctcccttgcagaacggccatacgaccagtccgcccaagggcggaaatgcagcgatggcgcccagtgaggatcgatatgccgctcttaaggatctcgacgagcagctgcgagaactgaaggccagcgaaagcgccacagagacgcccacgcccaccagtggcaatgttcaggccacagatgcctttggtggagccctcaacaacaatccaaatcccttcaagggccagcaacagcagcagctcagcagccatgtggtgaatccattccagcagcagcaacagcagcagcaccagcagaatctctatggccagttgacgctcataccaaatgcctacggcagcagttcccagcagcagatggggcaccatctcctccagcagcagcagcagcaacagcagagcttcttcaacttcaacaacaacgggttcgccatctcgcagggtctgcccaacggctgcggcttcggcagcatgcaacccgctcctgtgatggccaacaatccctttgcagccagcggcgccatgaacaccaacaatccattcttatgagactcaacccgggagaatccgcctcgcgccacctggcagaggcgctgagccagcgaacaaagagcagacgcggaggaaccgaaccgaaattagtccattttactaacaatagcgttaatctatgtatacataatgcacgccggagagcactctttgtgtacatagcccaaatatgtacacccgaaaggctccacgctgacgctagtcctcgcggatggcggaggcggactggggcgttgatatattcttttacatggtaactctactctaacgtttacggatacggatatttgtatttgccgtttgccctagaactctatacttgtactaagcgcccatgaacacttcatccactaacatagctactaatcctcatcctagtggaggatgcagttggtccagacactctgttatttgttttatccatcctcgtacttgtctttgtcccatttagcactttcgttgcggataagaactttgtcagttattgattgtgtggccttaataagattataaaactaaatattataacgtacgactatacatatacggatacagatacagattcagacacagttagtacagatacagatatacatatacgcttttgtacctaatgaattgcttcttgtttccattgctaatcatctgcttttcgtgtgctaattttatacactagtacgtgcgatatcggccgtgcagatagattgctcagctcgcgagtcaagcctcttttggttgcacccacggcagacatttgtacatatactgtctgattgtaagcctcgtgtaatacctccattaacaccactcccccaccacccatccatcgaaccccgaatccatgactcaattcactgctcacatgtccatgcccatgccttaacgtgtcaaacattatcgaagccttaaagttatttaaaactacgaaatttcaataaaaacaaataagaacgctatc'; |
168 #print(sequences); | 171 #print(sequences); |
169 #(options, args) = parser.parse_args(['-x', 'rrr', '-t', 0.5, '-s', sequences, '-o', 'collection_content']); | 172 #(options, args) = parser.parse_args(['-x', 'rrr', '-t', 0.5, '-s', sequences, '-o', 'collection_content']); |
170 | 173 |
171 (options, args) = parser.parse_args(); | 174 (options, args) = parser.parse_args(); |
172 return query( options, args ); | 175 return query( options, args ); |