def run_mp_and_delete(manager): """main method to run igblast through multiprocessing protocol, takes in a list of dictionaires each with a seperate set of arguments""" # blast options blast_options = manager["blast_options"] # bools _zip_bool = manager["zip_bool"] # file name outputs, these will all be temp files to be parsed later _file = manager["split_file"] _blast_out = _file + ".blast_out" if not _zip_bool: _json_out = _file + ".json" else: _json_out = _file + ".json.gz" # set the filename in the instance: blast_options["-query"] = _file blast_options["-out"] = _blast_out # temporary path _temporary_path = manager["temporary_path"] # output options _output_options = manager["output_options"] # set up the command line _cline = [manager["executable"]] # we know its in this directory since we copied it here to make this executable for argument in blast_options: arg = blast_options[argument] if arg.startswith("C"): arg = '"' + arg + '"' current_argument = [argument, arg] _cline += current_argument print "Running BLAST on processor {0} for split file {1}".format(manager["proc_number"], _file) print " ".join(_cline) sub = sp.Popen(_cline, stdout=sp.PIPE, stderr=sp.PIPE) stdout, stderr = sub.communicate() # if we have output, lets print it if stdout: print stdout if stderr: raise Exception("ERROR FROM BLAST {0}".format(stderr)) _output_type = manager["output_type"] print "Parsing BLAST output to {0} on Processor {1}".format(_output_type, manager["proc_number"]) if _output_type == "blast_out": os.remove(_file) print "Removing {0}".format(_file) else: print _blast_out, _file, _temporary_path op = output_parser.igblast_output( _blast_out, _file, _temporary_path, _output_options, species="human", gui=True, zip_bool=_zip_bool ) op.parse_blast_file_to_type(_json_out, _output_type) print "Done parsing {0} type\nRemoving {1} and {2}".format(_output_type, _file, _blast_out) os.remove(_file) os.remove(_blast_out)
def run_mp_and_delete(manager): '''main method to run igblast through multiprocessing protocol, takes in a list of dictionaires each with a seperate set of arguments''' # bools _zip_bool = manager['zip_bool'] _json_bool = manager['json_bool'] _concat_bool = manager['concat_bool'] _output_options = manager['output_options'] if _json_bool: _output_type = "json" else: _output_type = "csv" # file name outputs, these will all be temp files to be parsed later _file = manager['split_file'] _blast_out = _file.split('.')[0] + ".blast_out" _output_file = _file.split('.')[0] + "." + _output_type # temporary path _temporary_path = manager['tmp_path'] # check on internal data _internal_data = manager['internal_data'] _current_directory = os.getcwd() _species = manager['species'] if not os.path.exists(os.path.join(_current_directory, os.path.basename(_internal_data))): print "Copying internal data to current directory" copytree(_internal_data, os.getcwd()) # set up the command line _blast_options = manager['blast_options'] # add executable _cline = [manager['executable']] # add all blast options for argument in _blast_options: arg = _blast_options[argument] current_argument = [argument, arg] _cline += current_argument # change them to strings _cline = [str(i) for i in _cline] # add query and output to command line _cline += ["-query", _file] _cline += ["-out", _blast_out] # run command line print "Running BLAST on processor {0} for split file {1}".format(manager['proc_number'], _file) sub = sp.Popen(_cline, stdout=sp.PIPE, stderr=sp.PIPE) # If we have stderr and stdout, lets print it stderr, stdout = sub.communicate() if stderr or stdout: print stderr, stdout # Now parse the output print "Parsing BLAST output to {0} on Processor {1}".format(_output_type, manager['proc_number']) op = output_parser.igblast_output(_blast_out, _file, _temporary_path, _output_options, species=_species, gui=False, zip_bool=_zip_bool, germ_properties=manager['germ_properties']) op.parse_blast_file_to_type(_output_file, _output_type) print "Done parsing {0} type".format(_output_type) if _concat_bool: print "Removing {0} and {1}".format(_file, _blast_out) os.remove(_file) os.remove(_blast_out)