def createLogos(self, input_commstruct): db_file_path = [] for index in range(len(self.dbFiles)): db_file_path.append(os.path.join(self.dbPath, self.dbFiles[index])) motif_name_list = input_commstruct.motifStatistics.keys() motif_definition = MotifUtils.getMotifsDefinitionFromTF( motif_name_list, db_file_path) logos_path = os.path.join(self.outPath, FinalOutputProcessor.LOGOS_DIR_NAME) FileUtils.createDirectory(logos_path) for motif_name in motif_name_list: if motif_name in motif_definition.keys(): file_name = motif_name + ".tf" def_file_path = os.path.join(logos_path, file_name) def_file = open(def_file_path, "w") for line in motif_definition[motif_name]: def_file.write(line) def_file.flush def_file.close() RSATUtils.createLogoFromTF(logos_path, file_name, motif_name) else: Log.log( "FinalOutputProcessor.createLogos : No definition found to create logo for motif : " + motif_name)
def copyWorkflowResultFileToFinalOutput(self, stats_param, stats_param_attribute, local_attribute, file_pathes): if stats_param_attribute in stats_param.keys(): dir_path = os.path.join( self.outPath, stats_param_attribute) file_path = stats_param[ stats_param_attribute] FileUtils.createDirectory( dir_path) FileUtils.copyFile( file_path, dir_path) final_path = os.path.join( stats_param_attribute, os.path.basename( file_path)) file_pathes[ local_attribute] = final_path
def copyMotifResultFileToFinalOutput(self, motif_stats, motifStatistics_attribute, local_attribute, file_pathes): if motif_stats.hasAttribute( motifStatistics_attribute): if not local_attribute in file_pathes.keys(): file_pathes[ local_attribute] = {} dir_path = os.path.join( self.outPath, motifStatistics_attribute) file_path = motif_stats.getAttribute( motifStatistics_attribute) FileUtils.createDirectory( dir_path) FileUtils.copyFile( file_path, dir_path) final_path = os.path.join( motifStatistics_attribute, os.path.basename( file_path)) file_pathes[ local_attribute][ motif_stats.motifName] = final_path
def initVariables(self, output_dir): # Define and create the output directory parameter as the provided output_dir if non null # or as the RSAT path + base output dir path retrieved from the manager.props if output_dir != None: self.config[PFConstants.BASE_OUTPUT_DIR_PARAM] = output_dir else: self.config[PFConstants.BASE_OUTPUT_DIR_PARAM] = os.path.join( self.getParameter(PFConstants.RSAT_DIR_PARAM), self.getParameter(PFConstants.BASE_OUTPUT_DIR_PARAM)) FileUtils.createDirectory( self.config[PFConstants.BASE_OUTPUT_DIR_PARAM], 0777) # Initialize the output directory self.config[PFConstants.OUTPUT_DIR_PARAM] = os.path.join( self.getParameter(PFConstants.BASE_OUTPUT_DIR_PARAM), PFConstants.OUTPUT_DIR_NAME) FileUtils.createDirectory(self.config[PFConstants.OUTPUT_DIR_PARAM], 0777) # Define the path to the listening dir according situations if self.getParameter(PFConstants.SERVER_QUEUE_DIR_PARAM) != None: queue_path = os.path.join( self.getParameter(PFConstants.RSAT_DIR_PARAM), self.getParameter(PFConstants.SERVER_QUEUE_DIR_PARAM)) FileUtils.createDirectory(queue_path, 0777) self.config[PFConstants.LISTENING_DIR_PARAM] = os.path.join( queue_path, self.getParameter(PFConstants.LISTENING_DIR_PARAM)) else: self.config[PFConstants.LISTENING_DIR_PARAM] = os.path.join( self.getParameter(PFConstants.INSTALL_DIR_PARAM), self.getParameter(PFConstants.LISTENING_DIR_PARAM)) FileUtils.createDirectory(self.config[PFConstants.LISTENING_DIR_PARAM], 0777) # Set the path for the job queue directory if self.getParameter(PFConstants.SERVER_QUEUE_DIR_PARAM) != None: queue_path = os.path.join( self.getParameter(PFConstants.RSAT_DIR_PARAM), self.getParameter(PFConstants.SERVER_QUEUE_DIR_PARAM)) FileUtils.createDirectory(queue_path, 0777) self.config[PFConstants.QUEUE_DIR_PARAM] = os.path.join( queue_path, PFConstants.QUEUE_DIR_NAME) else: self.config[PFConstants.QUEUE_DIR_PARAM] = os.path.join( self.getParameter(PFConstants.INSTALL_DIR_PARAM), PFConstants.QUEUE_DIR_NAME) FileUtils.createDirectory(self.config[PFConstants.QUEUE_DIR_PARAM]) # Set the RSAT_PATH RSATUtils.RSAT_PATH = self.getParameter(PFConstants.RSAT_DIR_PARAM) # Set the path to the jaspar database. This is used to create the motif logo RSATUtils.RSAT_JASPAR_MOTIF_DATABASE = os.path.join( RSATUtils.RSAT_PATH, "public_html/data/motif_databases/JASPAR/jaspar_core_vertebrates_2009_10.tf" ) # Set the path to the Jaspar TF details files. Those files contains information on TF like family, class... MotifUtils.JASPAR_FLAT_DB_PATH = os.path.join( self.getParameter(PFConstants.INSTALL_DIR_PARAM), "resources/jaspar/motif")
def execute(self, input_commstructs): if input_commstructs == None or len(input_commstructs) == 0: raise ExecutionException( "FinalOutputProcessor.execute : No inputs") input_commstruct = input_commstructs[0] # Get all the pipeline parameters parameter_dic = self.collectAllParameters() # Retrieve the processor parameters self.dbPath = self.getParameter( FinalOutputProcessor.MOTIF_DATABASE_PATH_PARAM) # Retrieve the list of motif database files to use and count motifs in the list database_file_line = self.getParameter( FinalOutputProcessor.MOTIF_DATABASE_FILE_LIST_PARAM) if database_file_line != None and not database_file_line.isspace(): file_list = database_file_line.split() self.dbFiles = [] count_motif_in_db = 0 for file_path in file_list: current_path = os.path.join(self.dbPath, file_path) current_size = MotifUtils.getMotifsNumberFromTransfac( current_path) if current_size != None: count_motif_in_db = count_motif_in_db + current_size self.dbFiles.append(current_path) parameter_dic[ FinalOutputProcessor.PARAM_MotifDatabaseFileListSize] = str( count_motif_in_db) else: raise ExecutionException( "FinalOutputProcessor.getMethodParameters : No motif database file specified in parameter '" + FinalOutputProcessor.MOTIF_DATABASE_FILE_LIST_PARAM + "'") # Add the custom motif database files if any custom_database_file_line = self.getParameter( FinalOutputProcessor.CUSTOM_MOTIF_DATABASE_FILE_PARAM, False) if custom_database_file_line != None and not custom_database_file_line.isspace( ): self.dbFiles.append(custom_database_file_line) # Retrieve the ID and the name of the reference motif motif_name = parameter_dic[FinalOutputProcessor.PARAM_ReferenceMotif] for current_database in self.dbFiles: motif_ID = MotifUtils.getMotifIDFromTransfac( motif_name, current_database) if motif_ID != None: break parameter_dic[FinalOutputProcessor.PARAM_ReferenceMotifID] = motif_ID # Retrieve the Hypergeometric e/p-value threshold limit_value = self.getParameter( FinalOutputProcessor.DISPLAY_LIMIT_VALUE, False) if limit_value == None: limit_value = 1.0 # Prepare the processor output dir self.outPath = os.path.join(self.component.outputDir, self.component.getComponentPrefix()) shutil.rmtree(self.outPath, True) FileUtils.createDirectory(self.outPath, 0777) # Copy motif graph and stats files analysis = self.AnalyseMotifStats(input_commstruct) # Create motif logos self.createLogos(input_commstruct) # Copy input BED and custom motif files input_bed_file_destination_path = os.path.join( self.outPath, FinalOutputProcessor.PARAM_BEDFile) FileUtils.createDirectory(input_bed_file_destination_path) FileUtils.copyFile(parameter_dic[FinalOutputProcessor.PARAM_BEDFile], input_bed_file_destination_path) parameter_dic[FinalOutputProcessor.PARAM_BEDFile] = os.path.join( input_bed_file_destination_path, os.path.basename( parameter_dic[FinalOutputProcessor.PARAM_BEDFile])) # Copy the custom motif file (if any) to output location and count motifs in this db if FinalOutputProcessor.PARAM_CustomMotifDatabaseFile in parameter_dic.keys( ) and parameter_dic[ FinalOutputProcessor.PARAM_CustomMotifDatabaseFile] != None: custom_db_file_destination_path = os.path.join( self.outPath, FinalOutputProcessor.PARAM_CustomMotifDatabaseFile) FileUtils.createDirectory(custom_db_file_destination_path) FileUtils.copyFile( parameter_dic[ FinalOutputProcessor.PARAM_CustomMotifDatabaseFile], custom_db_file_destination_path) parameter_dic[ FinalOutputProcessor. PARAM_CustomMotifDatabaseFile] = os.path.join( custom_db_file_destination_path, os.path.basename(parameter_dic[ FinalOutputProcessor.PARAM_CustomMotifDatabaseFile])) count_custom_motif = MotifUtils.getMotifsNumberFromTransfac( parameter_dic[ FinalOutputProcessor.PARAM_CustomMotifDatabaseFile]) if (count_custom_motif != None): parameter_dic[FinalOutputProcessor. PARAM_CustomMotifDatabaseFileSize] = str( count_custom_motif) else: parameter_dic[FinalOutputProcessor. PARAM_CustomMotifDatabaseFileSize] = "0" # Output Results self.outputClassification(input_commstruct, analysis, limit_value, parameter_dic) # Copy other information FileUtils.copyFile( os.path.join(self.component.outputDir, Constants.PROGRESSION_XSL_FILE), self.outPath) FileUtils.copyFile( os.path.join(self.component.outputDir, Constants.PROGRESSION_XML_FILE), self.outPath) # Zip the complete result self.zipdir(self.outPath)