script_util.runProgram(self.__LOGGER, "bowtie2-build", bowtie_index_cmd, None, bowtie_dir) except Exception, e: raise KBaseRNASeqException("Error while running BowtieIndex {0},{1}".format(params["reference"], e)) ## Zip the Index files try: script_util.zip_files(self.__LOGGER, bowtie_dir, "%s.zip" % params["output_obj_name"]) except Exception, e: raise KBaseRNASeqException("Failed to compress the index: {0}".format(e)) ## Upload the file using handle service try: bowtie_handle = script_util.create_shock_handle( self.__LOGGER, "%s.zip" % params["output_obj_name"], self.__SHOCK_URL, self.__HS_URL, "Zip", user_token, ) except Exception, e: raise KBaseRNASeqException("Failed to upload the index: {0}".format(e)) bowtie2index = {"handle": bowtie_handle} ## Save object to workspace self.__LOGGER.info("Saving bowtie indexes object to workspace") res = ws_client.save_objects( { "workspace": params["ws_id"], "objects": [ {"type": "KBaseRNASeq.Bowtie2Indexes", "data": bowtie_handle, "name": params["output_obj_name"]} ], }
def rplotandupload2 (system_params, fparams, rparams, roptstr): """ Prepare URIs and call R script to generate image, json files. Upload the generated image and json files to Shock Get Shock handles and prepare cummerbundplotset object and append to user provided list. """ logger = system_params['logger'] scratch = system_params['scratch'] shock_url = system_params['shock_url'] hs_url = system_params['hs_url'] ws_url = system_params['ws_url'] token = system_params['token'] workspace = system_params['workspace'] rscripts = system_params['rscripts'] logger=system_params['logger'] #Check if data directory exists. # if exists(cuffdiff_dir) == False: # logger.info("Cuffdiff directory does not exists") # return False # # Generated image location # outpng = join(scratch, plotscript) + ".png" # #Need to check if its already present # if exists(outpng): # logger.info("PNG file already exists") # return False # # Generated json location # outjson = join(scratch, plotscript) + ".json" # #Need to check if its already present # if exists(outjson): # logger.info("JSON file already exists") # return False logger.info(roptstr) openedprocess = subprocess.Popen(roptstr, shell=True, stdout=subprocess.PIPE) openedprocess.wait() #Make sure the openedprocess.returncode is zero (0) if openedprocess.returncode != 0: logger.info("R script did not return normally, return code - " + str(openedprocess.returncode)) return False # Upload image file and get the shock handle png_handle = script_util.create_shock_handle( logger, rparams['outpng'], system_params['shock_url'], system_params['hs_url'], "png", system_params['token'] ) #Check for the return value and if error take measure. if png_handle["id"] == "": logger.info("Could not create Shock handle") return False #TODO Removed all json handle related stuff. fix it later # Upload json file and get the shock handle # json_handle = script_util.create_shock_handle( logger, # outjson, shock_url, hs_url, "json", token ) #Check for the return value and if error take measure. # if json_handle["id"] == "": # logger.info("Could not create Shock handle") # return False # Create a return list #TODO fix this "png_json_handle" : json_handle, cummerbundplot = { "png_handle" : png_handle, "plot_title" : fparams['title'], "plot_description" : fparams['description'] } fparams['cummerbundplotset'].append(cummerbundplot) TSV_to_FeatureValue = "trns_transform_TSV_Exspression_to_KBaseFeatureValues_ExpressionMatrix" outmatrix = rparams['outmatrix'] #outmatrixparse = join (scratch, scriptfile) + ".matrix.parse.txt" outjson = "out.json" matrix_parse = parse_expression_matrix_separate_comma(outmatrix) cmd_expression_json = [TSV_to_FeatureValue, '--workspace_service_url', ws_url, '--workspace_name', workspace, '--object_name', matrix_parse, '--working_directory', scratch, '--input_directory', scratch, '--output_file_name', outjson ] logger.info (" ".join(cmd_expression_json)) tool_process = subprocess.Popen (" ".join (cmd_expression_json), stderr=subprocess.PIPE, shell=True) stdout, stderr = tool_process.communicate() # os.remove(matrix_parse) if stdout is not None and len(stdout) > 0: logger.info(stdout) if stderr is not None and len(stderr) > 0: logger.info(stderr) if tool_process.returncode != 0: return False return outjson
def rplotandupload2(system_params, fparams, rparams, roptstr): """ Prepare URIs and call R script to generate image, json files. Upload the generated image and json files to Shock Get Shock handles and prepare cummerbundplotset object and append to user provided list. """ logger = system_params['logger'] scratch = system_params['scratch'] shock_url = system_params['shock_url'] hs_url = system_params['hs_url'] ws_url = system_params['ws_url'] token = system_params['token'] workspace = system_params['workspace'] rscripts = system_params['rscripts'] logger = system_params['logger'] #Check if data directory exists. # if exists(cuffdiff_dir) == False: # logger.info("Cuffdiff directory does not exists") # return False # # Generated image location # outpng = join(scratch, plotscript) + ".png" # #Need to check if its already present # if exists(outpng): # logger.info("PNG file already exists") # return False # # Generated json location # outjson = join(scratch, plotscript) + ".json" # #Need to check if its already present # if exists(outjson): # logger.info("JSON file already exists") # return False logger.info(roptstr) openedprocess = subprocess.Popen(roptstr, shell=True, stdout=subprocess.PIPE) openedprocess.wait() #Make sure the openedprocess.returncode is zero (0) if openedprocess.returncode != 0: logger.info("R script did not return normally, return code - " + str(openedprocess.returncode)) return False # Upload image file and get the shock handle png_handle = script_util.create_shock_handle(logger, rparams['outpng'], system_params['shock_url'], system_params['hs_url'], "png", system_params['token']) #Check for the return value and if error take measure. if png_handle["id"] == "": logger.info("Could not create Shock handle") return False #TODO Removed all json handle related stuff. fix it later # Upload json file and get the shock handle # json_handle = script_util.create_shock_handle( logger, # outjson, shock_url, hs_url, "json", token ) #Check for the return value and if error take measure. # if json_handle["id"] == "": # logger.info("Could not create Shock handle") # return False # Create a return list #TODO fix this "png_json_handle" : json_handle, cummerbundplot = { "png_handle": png_handle, "plot_title": fparams['title'], "plot_description": fparams['description'] } fparams['cummerbundplotset'].append(cummerbundplot) TSV_to_FeatureValue = "trns_transform_TSV_Exspression_to_KBaseFeatureValues_ExpressionMatrix" outmatrix = rparams['outmatrix'] #outmatrixparse = join (scratch, scriptfile) + ".matrix.parse.txt" outjson = "out.json" matrix_parse = parse_expression_matrix_separate_comma(outmatrix) cmd_expression_json = [ TSV_to_FeatureValue, '--workspace_service_url', ws_url, '--workspace_name', workspace, '--object_name', matrix_parse, '--working_directory', scratch, '--input_directory', scratch, '--output_file_name', outjson ] logger.info(" ".join(cmd_expression_json)) tool_process = subprocess.Popen(" ".join(cmd_expression_json), stderr=subprocess.PIPE, shell=True) stdout, stderr = tool_process.communicate() # os.remove(matrix_parse) if stdout is not None and len(stdout) > 0: logger.info(stdout) if stderr is not None and len(stderr) > 0: logger.info(stderr) if tool_process.returncode != 0: return False return outjson
def rplotandupload (logger, scratch, rscripts, plotscript, shock_url, hs_url, token, cummerbundplotset, title, description, cuffdiff_dir): """ Prepare URIs and call R script to generate image, json files. Upload the generated image and json files to Shock Get Shock handles and prepare cummerbundplotset object and append to user provided list. """ #Check if data directory exists. if exists(cuffdiff_dir) == False: logger.info("Cuffdiff directory does not exists") return False # Generated image location outpng = join(scratch, plotscript) + ".png" #Need to check if its already present if exists(outpng): logger.info("PNG file already exists") return False # Generated json location outjson = join(scratch, plotscript) + ".json" #Need to check if its already present if exists(outjson): logger.info("JSON file already exists") return False # Location of the R script to be executed computescript = join(rscripts, plotscript) #Check if it exists if exists(computescript) == False: logger.info("R script does not exists") return False # Generate command to be executed. ropts = ["Rscript", computescript] ropts.append("--cuffdiff_dir") ropts.append(cuffdiff_dir) ropts.append("--outpng") ropts.append(outpng) ropts.append("--outjson") ropts.append(outjson) # Make call to execute the system. roptstr = " ".join(str(x) for x in ropts) openedprocess = subprocess.Popen(roptstr, shell=True, stdout=subprocess.PIPE) openedprocess.wait() #Make sure the openedprocess.returncode is zero (0) if openedprocess.returncode != 0: logger.info("R script did not return normally, return code - " + str(openedprocess.returncode)) return False # Upload image file and get the shock handle png_handle = script_util.create_shock_handle( logger, outpng, shock_url, hs_url, "png", token ) #Check for the return value and if error take measure. if png_handle["id"] == "": logger.info("Could not create Shock handle") return False #TODO Removed all json handle related stuff. fix it later # Upload json file and get the shock handle # json_handle = script_util.create_shock_handle( logger, # outjson, shock_url, hs_url, "json", token ) #Check for the return value and if error take measure. # if json_handle["id"] == "": # logger.info("Could not create Shock handle") # return False # Create a return list #TODO fix this "png_json_handle" : json_handle, cummerbundplot = { "png_handle" : png_handle, "plot_title" : title, "plot_description" : description } cummerbundplotset.append(cummerbundplot) return True
def rplotandupload(logger, scratch, rscripts, plotscript, shock_url, hs_url, token, cummerbundplotset, title, description, cuffdiff_dir): """ Prepare URIs and call R script to generate image, json files. Upload the generated image and json files to Shock Get Shock handles and prepare cummerbundplotset object and append to user provided list. """ #Check if data directory exists. if exists(cuffdiff_dir) == False: logger.info("Cuffdiff directory does not exists") return False # Generated image location outpng = join(scratch, plotscript) + ".png" #Need to check if its already present if exists(outpng): logger.info("PNG file already exists") return False # Generated json location outjson = join(scratch, plotscript) + ".json" #Need to check if its already present if exists(outjson): logger.info("JSON file already exists") return False # Location of the R script to be executed computescript = join(rscripts, plotscript) #Check if it exists if exists(computescript) == False: logger.info("R script does not exists") return False # Generate command to be executed. ropts = ["Rscript", computescript] ropts.append("--cuffdiff_dir") ropts.append(cuffdiff_dir) ropts.append("--outpng") ropts.append(outpng) ropts.append("--outjson") ropts.append(outjson) # Make call to execute the system. roptstr = " ".join(str(x) for x in ropts) openedprocess = subprocess.Popen(roptstr, shell=True, stdout=subprocess.PIPE) openedprocess.wait() #Make sure the openedprocess.returncode is zero (0) if openedprocess.returncode != 0: logger.info("R script did not return normally, return code - " + str(openedprocess.returncode)) return False # Upload image file and get the shock handle png_handle = script_util.create_shock_handle(logger, outpng, shock_url, hs_url, "png", token) #Check for the return value and if error take measure. if png_handle["id"] == "": logger.info("Could not create Shock handle") return False #TODO Removed all json handle related stuff. fix it later # Upload json file and get the shock handle # json_handle = script_util.create_shock_handle( logger, # outjson, shock_url, hs_url, "json", token ) #Check for the return value and if error take measure. # if json_handle["id"] == "": # logger.info("Could not create Shock handle") # return False # Create a return list #TODO fix this "png_json_handle" : json_handle, cummerbundplot = { "png_handle": png_handle, "plot_title": title, "plot_description": description } cummerbundplotset.append(cummerbundplot) return True