def run_RenameAtoms(self): """ Get the PDB file and run the renaming @type self: koala.CheckPDBStructure.CheckPDBStructure """ try: self.path_runs.set_path_execute() self.path_runs.set_execution_directory() self.opts.pdbName = self.opts.pdbName.replace(" ", "-").replace("(", "").replace(")", "") link_name = os.path.join(self.opts.outputdir, os.path.basename(self.opts.pdbName)) if not os.path.exists(link_name): os.symlink(self.opts.inputPDB, link_name) os.system("cp %s %s" % (link_name, self.path_runs.get_path_execution())) self.rename_atoms_structure( os.path.join(self.path_runs.get_path_execution(), self.opts.pdbName), get_path_gromacs(), self.opts.forceField, ) path_output, file_output = os.path.split(self.opts.output) send_output_results( path_output, file_output, os.path.join(self.path_runs.get_path_execution(), self.opts.pdbName) ) except Exception, e: show_error_message(str(e))
def check_pdb(path_execution, path_galaxy): """ Create a subprocess to check the PDB structure using pdb2gmx @type self: koala.CalculateRMSD.CalculateRMSD @type path: string @type path_gromacs: string """ try: cl = [ '%s/scripts/check_structures_gromacs.py' % path_galaxy, path_execution, get_path_gromacs(), '&'] retProcess = subprocess.Popen(cl, 0, None, None, None, False) pvalue = retProcess.wait() if pvalue != 0: return False directory = os.path.join(path_execution, 'no_accepted_by_pdb2gmx') if os.path.exists(directory): pdbs = os.listdir(directory) show_message('These files could not be accepted by Gromacs.\n%s\n\n' % pdbs) return True except Exception, e: show_error_message("Error while checking PDBs:\n%s" % e)
def run_SortByFront(self): """ Run the 2PG Sort algorithm to calculate the Pareto fronts and sorting @type self: koala.SortByFront.SortByFront """ self.path_runs.set_path_execute() self.path_runs.set_execution_directory() copy_necessary_files( self.path_runs.get_path_execute(), self.path_runs.get_path_execution(), self.framework.get_framework()) self.framework.set_parameter( 'objective_analisys_dimo_source', '/home/%s/programs/dimo/DIMO2' % get_logged_user()) self.framework.set_parameter('Local_Execute', self.path_runs.get_path_execution()) self.framework.set_parameter( 'Path_Gromacs_Programs', get_path_gromacs()) self.framework.set_parameter( 'NativeProtein', '%s1VII.pdb' % self.path_runs.get_path_execution()) NumberObjective, Fitness_Energy = format_fitness(self.opts.inputFitness) self.framework.set_parameter('NumberObjective', NumberObjective) self.framework.set_parameter('Fitness_Energy', Fitness_Energy) create_configuration_file( self.path_runs.get_path_execution(), self.framework) config = 'configuration.conf' if self.opts.compressedFile == '1': inputFiles = self.opts.inputPDBs.split(",") for input_f in inputFiles: if zipfile.is_zipfile(input_f): extract_zip_file(input_f, self.path_runs.get_path_execution()) else: try: inF = gzip.GzipFile(input_f, 'rb') f = inF.read() inF.close() if f: extract_gz_file(input_f, self.path_runs.get_path_execution()) except Exception, e: raise Exception("The input file could not be read.\n%s" % e)
def run_SortByFront(self): """ Run the 2PG Sort Method algorithm to calculate the Pareto fronts and sorting @type self: koala.SortByFront.SortByFront """ self.path_runs.set_path_execute() self.path_runs.set_execution_directory() copy_necessary_files( self.path_runs.get_path_execute(), self.path_runs.get_path_execution(), self.framework.get_framework()) self.framework.set_parameter( 'objective_analisys_dimo_source', '/home/%s/programs/dimo/DIMO2' % get_logged_user()) self.framework.set_parameter('Local_Execute', self.path_runs.get_path_execution()) self.framework.set_parameter( 'Path_Gromacs_Programs', get_path_gromacs()) self.framework.set_parameter( 'NativeProtein', '%s1VII.pdb' % self.path_runs.get_path_execution()) create_configuration_file( self.path_runs.get_path_execution(), self.framework) self.loadMatrixFile(self.opts.inputTxt) objFile = os.path.join(self.path_runs.get_path_execution(), 'objectivies.txt') self.framework.set_command( self.path_runs.get_path_execution(), 'protpred-Gromacs-Sort_Method_by_Front_Dominance') cl = ['nohup', self.framework.get_command(), objFile, '&'] retProcess = subprocess.Popen(cl, 0, None, None, None, False) retProcess.wait() self.getBetterPDBs(self.path_runs.get_path_execution()) result, filesHtml = get_result_files( self.path_runs.get_path_execution(), self.opts.toolname) send_output_files_html(self.opts.htmlfiledir, filesHtml) send_output_files_html(self.opts.htmlfiledir, [result]) self.makeHtml()
def residue_renumber(path_execution, path_galaxy): try: cl = [ '%s/scripts/residue_renumber_all_pdbs.py' % path_galaxy, path_execution, get_path_gromacs(), '&'] retProcess = subprocess.Popen(cl, 0, None, None, None, False) pvalue = retProcess.wait() if pvalue != 0: return False return True except Exception, e: show_error_message("Error while renumbering PDBs:\n%s" % e)
def minimization(path_execution, path_galaxy, pdbPrefix=''): try: cl = ['%s/min.sh' % path_execution, path_execution, get_path_gromacs(), pdbPrefix, '&'] shutil.copy( os.path.join( '%s/scripts/%s' % (path_galaxy, 'min.sh')), path_execution) retProcess = subprocess.Popen(cl, 0, None, None, None, False) pvalue = retProcess.wait() if pvalue != 0: return False return True except Exception, e: show_error_message("Error while minimization PDBs:\n%s" % e)
def build_rankingDominance(self): """ Create the 2PG Sort configuration file and build the dominance @type self: koala.DominanceRanking.DominanceRanking """ self.path_runs.set_path_execute() self.path_runs.set_execution_directory() copy_necessary_files( self.path_runs.get_path_execute(), self.path_runs.get_path_execution(), self.framework.get_framework()) self.framework.set_parameter( 'objective_analisys_dimo_source', '/home/%s/programs/dimo/DIMO2' % get_logged_user()) self.framework.set_parameter('Local_Execute', self.path_runs.get_path_execution()) self.framework.set_parameter('Path_Gromacs_Programs', get_path_gromacs()) self.framework.set_parameter( 'NativeProtein', '%s1VII.pdb' % self.path_runs.get_path_execution()) self.combinations = format_fitness(self.opts.inputFitness, self.opts.toolname) if self.opts.compressedFile == '1': inputFiles = self.opts.inputPDBs.split(",") for input_f in inputFiles: if zipfile.is_zipfile(input_f): extract_zip_file(input_f, self.path_runs.get_path_execution()) else: try: inF = gzip.GzipFile(input_f, 'rb') f = inF.read() inF.close() if f: extract_gz_file(input_f, self.path_runs.get_path_execution()) except Exception, e: raise Exception("The input file could not be read.\n%s" % e)
def rename_atoms(path_execution, path_galaxy): """ Create a subprocess to rename the missing atoms in a PDB file using pdb2gmx @type self: koala.CalculateRMSD.CalculateRMSD @type path: string @type path_gromacs: string """ try: cl = [ '%s/scripts/rename_atoms.py' % path_galaxy, path_execution, get_path_gromacs(), '&'] retProcess = subprocess.Popen(cl, 0, None, None, None, False) pvalue = retProcess.wait() if pvalue != 0: return False return True except Exception, e: show_error_message("Error while renaming atoms.\n%s" % e)
def run_Random(self): """ Create the 2PG Random configuration file and begin the execution. @type self: koala.Random2PG.Random2PG """ try: self.path_runs.set_path_execute() if self.opts.inputEmail: email = validate_email(self.opts.inputEmail) self.path_runs.set_execution_directory(email) else: self.path_runs.set_execution_directory() self.sequence = create_local_fasta_file( self.path_runs.get_path_execution(), self.opts.fromFasta, self.opts.inputFasta, self.opts.toolname, self.framework) SizePopulation = create_local_pop_file( self.path_runs.get_path_execution(), self.opts.inputPop, self.framework) if SizePopulation > 1: show_error_message( "Error: The population file must contain only one model") copy_necessary_files( self.path_runs.get_path_execute(), self.path_runs.get_path_execution(), self.framework.get_framework()) self.framework.set_parameter( 'rotamer_library', self.opts.rotamerLibrary) self.framework.set_parameter( 'StepNumber', self.opts.stepNumber) self.framework.set_parameter( 'How_Many_Rotation', self.opts.howManyRotation) self.framework.set_parameter( 'force_field', self.opts.forceField) self.framework.set_parameter( 'SequenceAminoAcidsPathFileName', self.path_runs.get_path_execution() + 'fasta.txt') self.framework.set_parameter( 'Local_Execute', self.path_runs.get_path_execution()) self.framework.set_parameter( 'Path_Gromacs_Programs', get_path_gromacs()) self.framework.set_parameter( 'NativeProtein', '%s1VII.pdb' % self.path_runs.get_path_execution()) self.framework.set_parameter( 'Database', '%s/Database/' % get_path_algorithms('2pg_build_conformation')) create_configuration_file( self.path_runs.get_path_execution(), self.framework) self.framework.set_command( self.path_runs.get_path_execution(), 'protpred-Gromacs-Random_Algorithm') config = 'configuration.conf' cl = [self.framework.get_command(), config, '&'] retProcess = subprocess.Popen( cl, 0, stdout=None, stderr=subprocess.STDOUT, shell=False) retCode = retProcess.wait() if(retCode != 0): show_error_message( "The 2PG framework finished wrong.\nContact the system administrator.") parse_pdb( self.path_runs.get_path_execution(), 'random_algorithm_solutions.pdb', 20, 'randomSolution') if(self.opts.runMinimization == 'true'): self.do_minimization("randomSolution") pdbs = list_directory( self.path_runs.get_path_execution(), 'randomSolution-M*.pdb') build_images(pdbs, self.path_runs.get_path_execution()) path_output, file_output = os.path.split(self.opts.filehtml) name, ext = os.path.splitext(self.opts.filehtml) htmldir = os.path.join(path_output, '%s_files' % name) if not os.path.exists(htmldir): os.makedirs(htmldir) self.opts.htmlfiledir = htmldir result, filesHtml = get_result_files( self.path_runs.get_path_execution(), self.opts.toolname, 'randomSolution-M') send_output_files_html(self.opts.htmlfiledir, filesHtml) send_output_files_html(self.opts.htmlfiledir, [result]) if self.opts.createCompressFile == "True": if compress_files(pdbs, self.path_runs.get_path_execution(), "2PGRandom"): path_output, file_output = os.path.split(self.opts.outputZip) send_output_results( path_output, file_output, os.path.join(self.path_runs.get_path_execution(), '2PGRandom.zip')) self.makeHtml() if(self.opts.useJmol in ('True', 'true')): self.makeHtmlWithJMol(pdbs[0]) if(self.opts.inputEmail): send_email( '*****@*****.**', email, '%s Execution on Galaxy - Cloud USP' % self.opts.toolname, get_message_email(self.opts.toolname), [], 'smtp.gmail.com') except Exception, e: show_error_message(str(e))
def run_NSGAII(self): """ Create the 2PG NSGA-II configuration file and begin the execution. @type self: koala.NSGAII2PG.NSGAII2PG """ try: self.path_runs.set_path_execute() if self.opts.inputEmail: email = validate_email(self.opts.inputEmail) self.path_runs.set_execution_directory(email) else: self.path_runs.set_execution_directory() self.sequence = create_local_fasta_file( self.path_runs.get_path_execution(), self.opts.fromFasta, self.opts.inputFasta, self.opts.toolname, self.framework, ) SizePopulation = create_local_pop_file( self.path_runs.get_path_execution(), self.opts.inputPop, self.framework ) copy_necessary_files( self.path_runs.get_path_execute(), self.path_runs.get_path_execution(), self.framework.get_framework() ) self.framework.set_parameter("NumberGeration", self.opts.numberGeration) self.framework.set_parameter("SizePopulation", SizePopulation) self.framework.set_parameter( "SequenceAminoAcidsPathFileName", self.path_runs.get_path_execution() + "fasta.txt" ) self.framework.set_parameter("How_Many_Rotation", self.opts.howManyRotation) self.framework.set_parameter("rotamer_library", self.opts.rotamerLibrary) self.framework.set_parameter("Local_Execute", self.path_runs.get_path_execution()) self.framework.set_parameter("Path_Gromacs_Programs", get_path_gromacs()) self.framework.set_parameter("NativeProtein", "%s1VII.pdb" % self.path_runs.get_path_execution()) self.framework.set_parameter("Database", "%sDatabase/" % get_path_algorithms("2pg_build_conformation")) NumberObjective, Fitness_Energy = format_fitness(self.opts.inputFitness, self.opts.toolname) self.framework.set_parameter("NumberObjective", NumberObjective) self.framework.set_parameter("Fitness_Energy", Fitness_Energy) create_configuration_file(self.path_runs.get_path_execution(), self.framework) self.framework.set_command(self.path_runs.get_path_execution(), "protpred-Gromacs-NSGA2") config = "configuration.conf" cl = [self.framework.get_command(), config, "&"] retProcess = subprocess.Popen(cl, 0, stdout=None, stderr=subprocess.STDOUT, shell=False) retCode = retProcess.wait() if retCode != 0: show_error_message("The 2PG framework finished wrong.\nContact the system administrator.") parse_pdb( self.path_runs.get_path_execution(), "pop_NON_DOMINATED_%s.pdb" % self.opts.numberGeration, 20, "NSGAIISolutions", ) if self.opts.runMinimization == "true": self.do_minimization("NSGAIISolutions") pdbs = list_directory(self.path_runs.get_path_execution(), "NSGAIISolutions-M*.pdb") build_images(pdbs, self.path_runs.get_path_execution()) path_output, file_output = os.path.split(self.opts.filehtml) name, ext = os.path.splitext(self.opts.filehtml) htmldir = os.path.join(path_output, "%s_files" % name) if not os.path.exists(htmldir): os.makedirs(htmldir) self.opts.htmlfiledir = htmldir result, filesHtml = get_result_files( self.path_runs.get_path_execution(), self.opts.toolname, "NSGAIISolutions-M" ) send_output_results(path_output, file_output, result) send_output_files_html(self.opts.htmlfiledir, filesHtml) send_output_files_html(self.opts.htmlfiledir, [result]) if self.opts.createCompressFile == "True": if compress_files(pdbs, self.path_runs.get_path_execution(), "2PGNSGAII"): path_output, file_output = os.path.split(self.opts.outputZip) send_output_results( path_output, file_output, os.path.join(self.path_runs.get_path_execution(), "2PGNSGAII.zip") ) self.makeHtml() if self.opts.useJmol in ("True", "true"): self.makeHtmlWithJMol(pdbs[0]) if self.opts.inputEmail: send_email( "*****@*****.**", email, "%s Execution on Galaxy - Cloud USP" % self.opts.toolname, get_message_email(self.opts.toolname), [], "smtp.gmail.com", ) except Exception, e: show_error_message(str(e))
def run_Build_Conformation(self): """ Create the 2PG Build Conformation configuration file and begin the execution to create a initial population. @type self: koala.BuildConformation2PG.BuildConformation2PG """ try: self.path_runs.set_path_execute() self.path_runs.set_execution_directory() self.sequence = create_local_fasta_file( self.path_runs.get_path_execution(), self.opts.fromFasta, self.opts.inputFasta, self.opts.toolname, self.framework, ) copy_necessary_files( self.path_runs.get_path_execute(), self.path_runs.get_path_execution(), self.framework.get_framework() ) self.framework.set_parameter("gromacs_energy_min", self.opts.gromacsEnergyMin) self.framework.set_parameter("SizePopulation", self.opts.sizePopulation) self.framework.set_parameter("force_field", self.opts.forceField) self.framework.set_parameter("rotamer_library", self.opts.rotamerLibrary) if self.opts.forceField == "amber99sb-ildn": self.framework.set_parameter("c_terminal_charge", self.opts.cTerminal) self.framework.set_parameter("n_terminal_charge", self.opts.nTerminal) self.framework.set_parameter( "SequenceAminoAcidsPathFileName", self.path_runs.get_path_execution() + "fasta.txt" ) self.framework.set_parameter("Local_Execute", self.path_runs.get_path_execution()) self.framework.set_parameter("Path_Gromacs_Programs", get_path_gromacs()) self.framework.set_parameter("NativeProtein", "%s1VII.pdb" % self.path_runs.get_path_execution()) self.framework.set_parameter("Database", "%sDatabase/" % get_path_algorithms("2pg_build_conformation")) create_configuration_file(self.path_runs.get_path_execution(), self.framework) self.framework.set_command(self.path_runs.get_path_execution(), "protpred-Gromacs_pop_initial") config = "configuration.conf" cl = [self.framework.get_command(), config, "&"] retProcess = subprocess.Popen(cl, 0, stdout=None, stderr=subprocess.STDOUT, shell=False) retCode = retProcess.wait() if retCode != 0: show_error_message("The 2PG framework finished wrong.\nContact the system administrator.") path_output, file_output = os.path.split(self.opts.output) result, html = get_result_files(self.path_runs.get_path_execution(), self.opts.toolname) send_output_results(path_output, file_output, result) except Exception, e: show_error_message(str(e))
extract_gz_file(input_f, self.path_runs.get_path_execution()) except Exception, e: raise Exception("The input file could not be read.\n%s" % e) else: copy_pdbs_from_input( self.path_runs.get_path_execution(), self.opts.outputdir, self.opts.inputnames, self.opts.inputPDBs) pdbs = list_directory(self.path_runs.get_path_execution(), "*.pdb") for pdb in pdbs: self.check_structue_by_pdb2gmx( os.path.join(self.path_runs.get_path_execution(), pdb), get_path_gromacs(), self.opts.forceField) path_output, file_output = os.path.split(self.opts.output) pdbs_accepted = list_directory(self.path_runs.get_path_execution(), "*.pdb") if compress_files(pdbs_accepted, self.path_runs.get_path_execution(), "PDBsChecked"): send_output_results( path_output, file_output, os.path.join(self.path_runs.get_path_execution(), 'PDBsChecked.zip')) if(os.path.exists( os.path.join(self.path_runs.get_path_execution(), self.check_pdb_log))): send_multiple_outputs(