# HG changeset patch # User fabio # Date 1547824339 18000 # Node ID ba9d0fc8657fedd077aa4604060d51d4f477adb4 # Parent 9d2b9e65d73e1cc0e1cd36daddf7e164c01d1cfe Uploaded 20190118 diff -r 9d2b9e65d73e -r ba9d0fc8657f ._.shed.yml Binary file ._.shed.yml has changed diff -r 9d2b9e65d73e -r ba9d0fc8657f ._create.py Binary file ._create.py has changed diff -r 9d2b9e65d73e -r ba9d0fc8657f ._create.xml Binary file ._create.xml has changed diff -r 9d2b9e65d73e -r ba9d0fc8657f ._query.py Binary file ._query.py has changed diff -r 9d2b9e65d73e -r ba9d0fc8657f ._query.xml Binary file ._query.xml has changed diff -r 9d2b9e65d73e -r ba9d0fc8657f create.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/create.py Fri Jan 18 10:12:19 2019 -0500 @@ -0,0 +1,132 @@ +#!/usr/bin/env python + +# https://github.com/ross/requests-futures +# http://docs.python-requests.org/en/master/user/quickstart/#more-complicated-post-requests + +import sys, os, uuid, optparse, requests, json, time +#from requests_futures.sessions import FuturesSession + +#### NN14 #### +SERVICE_URL = "http://nn14.galaxyproject.org:8080/"; +#service_url = "http://127.0.0.1:8082/"; +CREATE_URL = SERVICE_URL+"tree/create"; +STATUS_URL = SERVICE_URL+"status/"; +############## +# query delay in seconds +QUERY_DELAY = 30; +############## + +__version__ = "1.0.0"; +ERR_EXIT_CODE = 1; +OK_EXIT_CODE = 0; + +def raiseException( exitcode, message, errorfilepath ): + with open(errorfilepath, 'w') as out: + out.write(message); + sys.exit(exitcode); + +def create_request( options, args, data ): + outfilepath = options.outfile; + cluster_id_2_query_id = { }; + + for cluster_id in data: + payload = { }; + payload["accessions"] = data[cluster_id]; + # add additional parameters to the payload + payload["qualitycontrol"] = int(options.qualitycontrol); + payload["qualitythreshold"] = float(options.qualitythreshold); + payload["klen"] = int(options.klen); + payload["minabundance"] = int(options.minabundance); + # set the content type to application/json + headers = {'Content-type': 'application/json'}; + # create a session + session = requests.Session(); + # make a synchronous post request to the create route + req = session.post(CREATE_URL, headers=headers, json=payload); + resp_code = req.status_code; + #print(str(req.content)+"\n\n"); + if resp_code == requests.codes.ok: + resp_content = str(req.content); + # convert out to json + json_content = json.loads(resp_content); + # retrieve query id + query_id = json_content['query_id']; + cluster_id_2_query_id[cluster_id] = query_id; + else: + with open(outfilepath, 'a+') as outfile: + outfile.write( "An error has occurred while submitting data to the /tree/create endpoint for the cluster " + cluster_id + "\n\n" ); + + build_flags = [ ] + while len(build_flags) < len(cluster_id_2_query_id): + for idx, cluster_id in enumerate( cluster_id_2_query_id ): + if cluster_id not in build_flags: + query_id = cluster_id_2_query_id[ cluster_id ]; + # create a new session + session = requests.Session(); + # make a synchronous get request to the status route + status_query_url = STATUS_URL.replace("", query_id); + status_req = session.get(status_query_url); + status_resp_content = str(status_req.content); + #print(status_resp_content+"\n\n"); + # convert out to json + json_status_content = json.loads(status_resp_content); + # take a look at the state + # state attribute is always available + if json_status_content['state'] == 'SUCCESS': + build_flags.append( cluster_id ); + built_tree_id = json_status_content['results']['tree_id']; + with open(outfilepath, 'a+') as outfile: + outfile.write( "Query ID: " + str(query_id) + "\n" + "Query status: " + str(json_status_content['state']) + "\n" + "Cluster ID: " + cluster_id + "\n" + "Sequence Bloom Tree ID: " + built_tree_id + "\n\n" ); + elif json_status_content['state'] in ['FAILURE', 'REVOKED']: + build_flags.append( cluster_id ); + with open(outfilepath, 'a+') as outfile: + outfile.write( "Query ID: " + str(query_id) + "\n" + "Query status: " + str(json_status_content['state']) + "\n" + "Cluster ID: " + cluster_id + "\n\n" ); + if len(build_flags) < len(cluster_id_2_query_id): + time.sleep(QUERY_DELAY); # in seconds + return sys.exit(OK_EXIT_CODE); + +def create( options, args ): + multiple_data = {}; + experiment_list_file_path = options.explist; + with open(experiment_list_file_path) as explist: + for line in explist: + if line.strip() != "": + line_split = line.strip().split("\t"); # split on tab + if len(line_split) == 2: # 0:accession , 1:cluster_id , otherwise skip line + accession = line_split[0]; + cluster_id = line_split[1]; + if cluster_id in multiple_data: + multiple_data[cluster_id].append( accession ); + else: + multiple_data[cluster_id] = [ accession ]; + if len(multiple_data) > 0: + return create_request( options, args, multiple_data ); + else: + return raiseException( ERR_EXIT_CODE, "An error has occurred. Please be sure that your input file is valid.", options.outfile ); + +def __main__(): + # Parse the command line options + usage = "Usage: create.py --explist experiment_list --qualitycontrol quality_control --qualitythreshold quality_threshold --klen kmer_len --minabundance min_abundance --outfile output_file_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("-l", "--explist", type="string", + action="store", dest="explist", help="tabular file with a list of SRA accessions and their cluster label"); + parser.add_option("-q", "--qualitycontrol", type="int", default=0 + action="store", dest="qualitycontrol", help="flag to enable or disable the experiment quality control"); + parser.add_option("-t", "--qualitythreshold", type="float", default=0.0 + action="store", dest="qualitythreshold", help="quality threshold, if quality control is enabled only"); + parser.add_option("-k", "--klen", type="int", default=21, + action="store", dest="klen", help="k-mer length"); + parser.add_option("-m", "--minabundance", type="int", default=2, + action="store", dest="minabundance", help="minimum abundance"); + parser.add_option("-o", "--outfile", type="string", default="outfile_txt", + action="store", dest="outfile", help="output file path"); + + (options, args) = parser.parse_args(); + if options.version: + print __version__; + else: + return create( options, args ); + +if __name__ == "__main__": __main__() diff -r 9d2b9e65d73e -r ba9d0fc8657f create.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/create.xml Fri Jan 18 10:12:19 2019 -0500 @@ -0,0 +1,104 @@ + + + a Sequence Bloom Tree + + macros.xml + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 9d2b9e65d73e -r ba9d0fc8657f macros.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/macros.xml Fri Jan 18 10:12:19 2019 -0500 @@ -0,0 +1,14 @@ + + + + python + requests + + + + + + 10.1101/090464 + + + \ No newline at end of file diff -r 9d2b9e65d73e -r ba9d0fc8657f query.py --- a/query.py Tue Apr 24 13:29:16 2018 -0400 +++ b/query.py Fri Jan 18 10:12:19 2019 -0500 @@ -42,7 +42,6 @@ # create a session session = requests.Session(); # make a synchronous post request to the query route - QUERY_URL.replace("", str(options.treeid)); req = session.post(QUERY_URL.replace("", str(options.treeid)), headers=headers, json=payload); resp_code = req.status_code; #print(str(req.content)+"\n\n"); @@ -193,7 +192,7 @@ action="store", dest="search", help="search mode"); parser.add_option("-e", "--exact", type="int", default=0, action="store", dest="exact", help="exact algorithm (required if search is 1 only)"); - parser.add_option("-k", "--tree", type="int", default=0, + parser.add_option("-k", "--tree", type="string", default=0, action="store", dest="treeid", help="the id of the tree that will be queried"); parser.add_option("-t", "--sthreshold", type="float", action="store", dest="sthreshold", help="threshold applied to the search algrithm"); diff -r 9d2b9e65d73e -r ba9d0fc8657f query.xml --- a/query.xml Tue Apr 24 13:29:16 2018 -0400 +++ b/query.xml Fri Jan 18 10:12:19 2019 -0500 @@ -1,15 +1,15 @@ - the Sequence Bloom Tree - - python - requests - + a Sequence Bloom Tree + + macros.xml + + + + + @@ -52,7 +55,7 @@ - - 10.1101/090464 - +