def getTMScoreValues(self): """ Calculate the TM-Score value to the input PDB files @type self: koala.CalculateTMScore.CalculateTMScore """ try: pdbs = list_directory(self.path_runs.get_path_execution(), "*.pdb") if not pdbs: raise "getTMScoreValues: No PDB file found.\n" dict_tmscore = {} for pdb in pdbs: if not (pdb == self.opts.inputPDBRefName): name_pdb, ext = os.path.splitext(pdb) name_reference, ext = os.path.splitext(self.opts.inputPDBRefName) aux_command = self.command.replace( "@PATH@", self.path_runs.get_path_execute()).replace( "@MODEL@", (os.path.join(self.path_runs.get_path_execution(), pdb))).replace( "@NATIVE@", (os.path.join( self.path_runs.get_path_execution(), self.opts.inputPDBRefName))) aux_command = aux_command.replace( "@PATHEXECUTE@", self.path_runs.get_path_execution()).replace( "@NAMEMODEL@", name_pdb).replace( "@NAMENATIVE@", name_reference) os.system(aux_command) # TODO: USAR SUBPROCESS os.chdir(self.path_runs.get_path_execution()) result_file = name_reference + '_' + name_pdb + '.txt' temp_tmscore = open(result_file, "r") for line in temp_tmscore.readlines(): if line.startswith("TM-score"): tmscore_value = line.split("=", 1)[1].strip() only_pdb_file_name = os.path.basename(pdb) dict_tmscore[only_pdb_file_name] = tmscore_value temp_tmscore.close() return OrderedDict(sorted(dict_tmscore.items(), key=lambda x: x[1], reverse=True)) except Exception, e: show_error_message("Erro on getTMScoreValues method:\n%s" % e)
def getRMSDValues(self): """ Calculate the RMSD value to the input PDB files @type self: koala.CalculateRMSD.CalculateRMSD """ try: pdbs = list_directory(self.path_runs.get_path_execution(), "*.pdb") if not pdbs: raise Exception("getRMSDValues: No PDB file found.\n") dict_rmsd = {} for pdb in pdbs: if not (pdb == self.opts.inputPDBRefName): # aux_command = self.command.replace( # "@PATH_GROMACS@", # self.ClassColection.getPathGromacs()).replace( # "@PROT@", # (os.path.join(self.path_runs.get_path_execution(), pdb))).replace( # "@NATIVE@", # (os.path.join(self.path_runs.get_path_execution(), self.opts.inputPDBRefName))) # os.system(aux_command) # temp_rmsd = open("temporary_rmsd.xvg", "r") # for line in temp_rmsd.readlines(): # if line.find("@") < 0 and line.find("#") < 0: # rmsd_value = float(str(line).split()[1]) # only_pdb_file_name = os.path.basename(pdb) # dict_rmsd[only_pdb_file_name] = rmsd_value # temp_rmsd.close() # os.remove("temporary_rmsd.xvg") # Load Structures a = os.path.join(self.path_runs.get_path_execution(), pdb) aname, ext = os.path.splitext(pdb) b = os.path.join(self.path_runs.get_path_execution(), self.opts.inputPDBRefName) bname, ext = os.path.splitext(self.opts.inputPDBRefName) pymol.cmd.load(a, aname) pymol.cmd.load(b, bname) ret = pymol.cmd.align(aname, bname) rms = list(ret) print 'rmds %s, atoms %s, residues %s' % (rms[0], rms[1], rms[-1]) only_pdb_file_name = os.path.basename(pdb) dict_rmsd[only_pdb_file_name] = round(rms[0], 3) sleep(0.25) # (in seconds) pymol.cmd.reinitialize() return OrderedDict(sorted(dict_rmsd.items(), key=lambda x: x[1])) except Exception, e: show_error_message("Erro on getRMSDValues method:\n%s" % e)
def getBetterPDBs(self, path): """ Get the methods that have been classified on the two first fronts @type self: koala.SortByFront.SortByFront """ try: front = list_directory(path, "*.front") if len(front) > 1: raise Exception("There is more than one .front file.\n") if len(front) == 0: raise Exception("There is no .front file.\n") for l in file(front[0], 'r'): ln = l.split("\n") if not ln[0].startswith('#', 0, 1): ll = ln[0].split("\t") if(int(ll[1]) < 2): # ll[1] = fronteira fronteiras 0 e 1 self.methods.append(ll[6].strip()) # ll[6] = metodo except Exception, e: show_error_message("Error on getBetterPDBs.\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 makeHtml(self): """ Create an HTML file content to list all the artifacts found in the html_dir @type self: koala.Random2PG.Random2PG """ try: galhtmlprefix = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="Galaxy %s tool output" /> <title></title> <link rel="stylesheet" href="/static/koala.css" type="text/css" /> <link rel="stylesheet" href="/static/style/base.css" type="text/css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script src="http://code.highcharts.com/highcharts.js"></script> <script src="http://code.highcharts.com/highcharts-more.js"></script> <script src="http://code.highcharts.com/modules/exporting.js"></script> </head> <body> <div class="toolFormBody">""" galhtmlpostfix = """</div></body></html>\n""" flist = os.listdir(self.opts.htmlfiledir) flist.sort() html = [] html.append(galhtmlprefix % self.progname) html.append('<div class="sucessmessage">') html.append('<br>') html.append('<h1 align="center">2PG Random Ab Initio Algorithm results</h1><br></div>') html.append('<br>') html.append('<div class="sectionmessage">') html.append('<br>Submitted Primary Sequence.<br><br></div>') html.append('<div class="code">') html.append('Length: %s<br>' % len(self.sequence)) html.append('%s<br></div>' % self.sequence) fhtml = [] fitFiles = [] outputfiles = [] compressedFile = [] imageFiles = [] if len(flist) > 0: for rownum, fname in enumerate(flist): dname, e = os.path.splitext(fname) sfsize = get_file_size(fname, self.opts.htmlfiledir) if e.lower() == ".fit": fitFiles.append(fname) elif e.lower() == ".png": imageFiles.append(fname) elif e.lower() in ".zip, .gz": compressedFile.append(fname) elif not e.lower() in self.ignoreoutfiles: outputfiles.append(fname) # Arquivos fit for fit in fitFiles: sfsize = get_file_size(fit, self.opts.htmlfiledir) fhtml.append('<tr>') fhtml.append('<td><a href="%s">%s</a></td>' % (fit, fit)) fhtml.append('<td>%s</td>' % (sfsize)) fhtml.append('</tr>') if len(fhtml) > 0: html.append('<br>') html.append('<div class="sectionmessage">') html.append('<br>Download Calculated values of selected Objectives.<br><br></div>') fhtml.insert( 0, '<div class="filetables"><table border="1"><tr><th>File</th>' '<th>Size</th></tr>\n') fhtml.append('</table></div><br>') html += fhtml fhtml = [] # images (e depois models) listaArquivosPdb = list_directory( self.path_runs.get_path_execution(), 'randomSolution-M*.pdb') if len(listaArquivosPdb) <= 20: size = int(len(listaArquivosPdb) / 5) rest = len(listaArquivosPdb) % 5 else: size = 4 # vai mostrar no máximo 20 imagens rest = 0 idx = 0 # controla indice das imagens e dos metodos start = 0 end = 5 # limite de colunas para uma linha if size < 1: n = len(listaArquivosPdb) fhtml.append('<tr>') idx_linha = idx for i in range(0, n): pdbName, ext = os.path.splitext(listaArquivosPdb[idx]) fhtml.append( '<td><a href="%s.png"><img src="%s.png" ' 'title="Click to see %s.png bigger" width="130"/></a></td>' % (pdbName, pdbName, pdbName)) idx += 1 idx = idx_linha fhtml.append('</tr><tr>') for i in range(0, n): fhtml.append( '<td><a href="%s">%s</a></td>' % ( listaArquivosPdb[idx], listaArquivosPdb[idx])) idx += 1 idx = idx_linha fhtml.append('</tr><tr>') for i in range(0, n): sfsize = get_file_size( listaArquivosPdb[idx], self.opts.htmlfiledir) fhtml.append('<td>%s</td>' % (sfsize)) idx += 1 idx = idx_linha fhtml.append('</tr>') else: for img in range(0, size): fhtml.append('<tr>') idx_linha = idx for i in range(start, end): pdbName, ext = os.path.splitext(listaArquivosPdb[idx]) fhtml.append( '<td><a href="%s.png"><img src="%s.png" ' 'title="Click to see %s.png bigger" width="130"/></a></td>' % (pdbName, pdbName, pdbName)) idx += 1 idx = idx_linha fhtml.append('</tr><tr>') for i in range(start, end): fhtml.append( '<td><a href="%s">%s</a></td>' % ( listaArquivosPdb[idx], listaArquivosPdb[idx])) idx += 1 idx = idx_linha fhtml.append('</tr><tr>') for i in range(start, end): sfsize = get_file_size( listaArquivosPdb[idx], self.opts.htmlfiledir) fhtml.append('<td>%s</td>' % (sfsize)) idx += 1 fhtml.append('</tr>') fhtml.append('<tr>') idx_linha = idx for i in range(0, rest): pdbName, ext = os.path.splitext(listaArquivosPdb[idx]) fhtml.append( '<td><a href="%s.png"><img src="%s.png" ' 'title="Click to see %s.png bigger" width="130"/></a></td>' % (pdbName, pdbName, pdbName)) idx += 1 idx = idx_linha fhtml.append('</tr><tr>') for i in range(0, rest): fhtml.append( '<td><a href="%s">%s</a></td>' % ( listaArquivosPdb[idx], listaArquivosPdb[idx])) idx += 1 idx = idx_linha fhtml.append('</tr><tr>') for i in range(0, rest): sfsize = get_file_size( listaArquivosPdb[idx], self.opts.htmlfiledir) fhtml.append('<td>%s</td>' % (sfsize)) idx += 1 idx = idx_linha fhtml.append('</tr>') if len(fhtml) > 0: html.append('<br>') html.append('<div class="sectionmessage">') html.append('<br>Best Tertiary Structures<br>') html.append('<br></div>') if(self.opts.useJmol == 'true'): html.append('<div class="active-jmol">') html.append('<br>') html.append( '<a href=/datasets/%s/display/%s.htm>Activate JMol</a>' % ( self.opts.datasetID, self.opts.datasetID)) html.append('<br></div>') model = '' if size < 1: for i in range(0, len(listaArquivosPdb)): model += '<th>Model</th>' else: model = '<th>Model</th>'\ '<th>Model</th>'\ '<th>Model</th>'\ '<th>Model</th>'\ '<th>Model</th>' fhtml.insert( 0, '<div class="filetables"><table border="1">' '<tr>' + model + '</tr>\n') fhtml.append('</table></div><br/>') html += fhtml fhtml = [] # Outros arquivos de output for output in outputfiles: sfsize = get_file_size(output, self.opts.htmlfiledir) fhtml.append('<tr>') fhtml.append('<td><a href="%s">%s</a></td>' % (output, output)) fhtml.append('<td>%s</td>' % (sfsize)) fhtml.append('</tr>') if len(fhtml) > 0: html.append('<br>') html.append('<div class="sectionmessage">') html.append('<br>Download the output files:<br><br></div>') fhtml.insert( 0, '<div class="filetables"><table border="1"><tr><th>Output File</th>' '<th>Size</th></tr>\n') fhtml.append('</table></div><br>') html += fhtml fhtml = [] # arquivo zipado for output in compressedFile: sfsize = get_file_size(output, self.opts.htmlfiledir) fhtml.append('<tr>') fhtml.append('<td><a href="%s">%s</a></td>' % (output, output)) fhtml.append('<td>%s</td>' % (sfsize)) fhtml.append('</tr>') if len(fhtml) > 0: html.append('<br>') html.append('<div class="sectionmessage">') html.append('<br>Compressed file with all the output files<br><br></div>') fhtml.insert( 0, '<div class="filetables"><table border="1"><tr><th>File</th>' '<th>Size</th></tr>\n') fhtml.append('</table></div><br>') html += fhtml self.time_execution.set_job_end(datetime.datetime.now()) self.endTime = datetime.datetime.now() dif = self.time_execution.calculate_time_execution() html.append('<div>Time execution:<br>') html.append('Start: %s<br>' % self.time_execution.get_job_start().strftime("%d/%m/%Y %H:%M:%S")) html.append('End: %s<br>' % self.time_execution.get_job_end().strftime("%d/%m/%Y %H:%M:%S")) html.append('Total time: ~%dh:%dm:%ds' % (dif[0], dif[1], dif[2])) html.append('</div>') html.append('<hr>') html.append('<div>Citation<br>') html.append('Please, cite the used algorithm in this tool:<br><br>') html.append('') html.append('<br></div>') html.append(galhtmlpostfix) htmlf = file(self.opts.filehtml, 'w') htmlf.write('\n'.join(html)) htmlf.write('\n') htmlf.close() except Exception, e: show_error_message("Error on makeHtml:\n%s" % str(e))
def makeHtmlWithJMol(self, pdbReference): """ Create an HTML file content to list all the artifacts found in the html_dir @type self: koala.SortByFront.SortByFront """ try: galhtmlprefix = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="Galaxy %s tool output" /> <title></title> <link rel="stylesheet" href="/static/koala.css" type="text/css" /> <link rel="stylesheet" href="/static/style/base.css" type="text/css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script src="http://code.highcharts.com/highcharts.js"></script> <script src="http://code.highcharts.com/highcharts-more.js"></script> <script src="http://code.highcharts.com/modules/exporting.js"></script> <script type="text/javascript" src="/static/js/JSmol.min.js"></script> <script type="text/javascript"> Jmol._isAsync = false; Jmol.getProfile() var jmolApplet0; jmol_isReady = function(applet) { document.title = (applet._id + " is ready") Jmol._getElement(applet, "appletdiv").style.border="1px solid blue" } Info = { width: 400, height: 300, debug: false, color: "#F0F0F0", zIndexBase: 20000, z:{monitorZIndex:100}, addSelectionOptions: false, serverURL: "/static/js/php/jsmol.php", use: "HTML5", jarPath: "/static/js/java", j2sPath: "/static/js/j2s", jarFile: "JmolApplet.jar", isSigned: false, disableJ2SLoadMonitor: false, disableInitialConsole: false, readyFunction: jmol_isReady, allowjavascript: true, script: "set antialiasDisplay;set showtiming;load async /datasets/%s/display/%s;cartoons only;color cartoons structure; spin on" //,defaultModel: ":dopamine" //,noscript: true //console: "none", // default will be jmolApplet0_infodiv //script: "set antialiasDisplay;background white;load data/caffeine.mol;" //delay 3;background yellow;delay 0.1;background white;for (var i = 0; i < 10; i+=1){rotate y 3;delay 0.01}" } </script> </head> <body> <div class="toolFormBody">""" galhtmlpostfix = """</div></body></html>\n""" flist = os.listdir(self.opts.htmlfiledir) flist.sort() html = [] html.append(galhtmlprefix % (self.progname, self.opts.datasetID, pdbReference)) html.append('<div class="sucessmessage">') html.append('<br>') html.append('<h1 align="center">2PG Random Ab Initio Algorithm results</h1><br></div>') html.append('<br>') html.append('<div class="sectionmessage">') html.append('<br>Submitted Primary Sequence.<br><br></div>') html.append('<div class="code">') html.append('Length: %s<br>' % len(self.sequence)) html.append('%s<br></div>' % self.sequence) fhtml = [] fitFiles = [] outputfiles = [] compressedFile = [] imageFiles = [] if len(flist) > 0: for rownum, fname in enumerate(flist): dname, e = os.path.splitext(fname) sfsize = get_file_size(fname, self.opts.htmlfiledir) if e.lower() == ".fit": fitFiles.append(fname) elif e.lower() == ".png": imageFiles.append(fname) elif e.lower() in ".zip, .gz": compressedFile.append(fname) elif not e.lower() in self.ignoreoutfiles: outputfiles.append(fname) # Arquivos fit for fit in fitFiles: sfsize = get_file_size(fit, self.opts.htmlfiledir) fhtml.append('<tr>') fhtml.append('<td><a href="%s">%s</a></td>' % (fit, fit)) fhtml.append('<td>%s</td>' % (sfsize)) fhtml.append('</tr>') if len(fhtml) > 0: html.append('<br>') html.append('<div class="sectionmessage">') html.append('<br>Download Calculated values of selected Objectives.<br><br></div>') fhtml.insert( 0, '<div class="filetables"><table border="1"><tr><th>File</th>' '<th>Size</th></tr>\n') fhtml.append('</table></div><br>') html += fhtml fhtml = [] # images (e depois models) listaArquivosPdb = list_directory( self.path_runs.get_path_execution(), 'randomSolution-M*.pdb') if len(listaArquivosPdb) <= 20: size = int(len(listaArquivosPdb) / 5) rest = len(listaArquivosPdb) % 5 else: size = 4 # vai mostrar no máximo 20 imagens rest = 0 idx = 0 # controla indice das imagens e dos metodos start = 0 end = 5 # limite de colunas para uma linha if size < 1: n = len(listaArquivosPdb) fhtml.append('<tr>') idx_linha = idx for i in range(0, n): pdbName, ext = os.path.splitext(listaArquivosPdb[idx]) fhtml.append( '<td><a href="/datasets/%s/display/%s.png">' '<img src="/datasets/%s/display/%s.png" ' 'title="Click to see %s.png bigger" width="130"/></a></td>' % (self.opts.datasetID, pdbName, self.opts.datasetID, pdbName, pdbName)) idx += 1 idx = idx_linha fhtml.append('</tr><tr>') for i in range(0, n): fhtml.append( '<td><a href="/datasets/%s/display/%s">%s</a></td>' % ( self.opts.datasetID, listaArquivosPdb[idx], listaArquivosPdb[idx])) idx += 1 idx = idx_linha fhtml.append('</tr><tr>') for i in range(0, n): sfsize = get_file_size( listaArquivosPdb[idx], self.opts.htmlfiledir) fhtml.append('<td>%s</td>' % (sfsize)) idx += 1 idx = idx_linha fhtml.append('</tr><tr>') for i in range(0, n): fhtml.append( '<td>' '<a href="javascript:Jmol.script(jmolApplet0,' "'load /datasets/%s/display/%s;cartoons only; \ color cartoons structure; spin on')" '">Load on Jmol</a></td>' % ( self.opts.datasetID, listaArquivosPdb[idx])) idx += 1 idx = idx_linha else: for img in range(0, size): fhtml.append('<tr>') idx_linha = idx for i in range(start, end): pdbName, ext = os.path.splitext(listaArquivosPdb[idx]) fhtml.append( '<td><a href="/datasets/%s/display/%s.png">' '<img src="/datasets/%s/display/%s.png" ' 'title="Click to see %s.png bigger" width="130"/></a></td>' % (self.opts.datasetID, pdbName, self.opts.datasetID, pdbName, pdbName)) idx += 1 idx = idx_linha fhtml.append('</tr><tr>') for i in range(start, end): fhtml.append( '<td><a href="/datasets/%s/display/%s">%s</a></td>' % ( self.opts.datasetID, listaArquivosPdb[idx], listaArquivosPdb[idx])) idx += 1 idx = idx_linha fhtml.append('</tr><tr>') for i in range(start, end): sfsize = get_file_size( listaArquivosPdb[idx], self.opts.htmlfiledir) fhtml.append('<td>%s</td>' % (sfsize)) idx += 1 idx = idx_linha fhtml.append('</tr><tr>') for i in range(start, end): fhtml.append( '<td>' '<a href="javascript:Jmol.script(jmolApplet0,' "'load /datasets/%s/display/%s;cartoons only; \ color cartoons structure; spin on')" '">Load on Jmol</a></td>' % ( self.opts.datasetID, listaArquivosPdb[idx])) idx += 1 fhtml.append('<tr>') idx_linha = idx for i in range(0, rest): pdbName, ext = os.path.splitext(listaArquivosPdb[idx]) fhtml.append( '<td><a href="/datasets/%s/display/%s.png">' '<img src="/datasets/%s/display/%s.png" ' 'title="Click to see %s.png bigger" width="130"/></a></td>' % (self.opts.datasetID, pdbName, self.opts.datasetID, pdbName, pdbName)) idx += 1 idx = idx_linha fhtml.append('</tr><tr>') for i in range(0, rest): fhtml.append( '<td><a href="/datasets/%s/display/%s">%s</a></td>' % ( self.opts.datasetID, listaArquivosPdb[idx], listaArquivosPdb[idx])) idx += 1 idx = idx_linha fhtml.append('</tr><tr>') for i in range(0, rest): sfsize = get_file_size( listaArquivosPdb[idx], self.opts.htmlfiledir) fhtml.append('<td>%s</td>' % (sfsize)) idx += 1 idx = idx_linha fhtml.append('</tr><tr>') for i in range(0, rest): fhtml.append( '<td>' '<a href="javascript:Jmol.script(jmolApplet0,' "'load /datasets/%s/display/%s;cartoons only; \ color cartoons structure; spin on')" '">Load on Jmol</a></td>' % ( self.opts.datasetID, listaArquivosPdb[idx])) idx += 1 idx = idx_linha if len(fhtml) > 0: html.append('<br>') html.append('<div class="sectionmessage">') html.append('<br>Best Tertiary Structures<br>') html.append('<br></div>') model = '' if size < 1: for i in range(0, len(listaArquivosPdb)): model += '<th>Model</th>' else: model = '<th>Model</th>'\ '<th>Model</th>'\ '<th>Model</th>'\ '<th>Model</th>'\ '<th>Model</th>' fhtml.insert( 0, '<div class="filetables"><table border="1">' '<tr>' + model + '</tr>\n') fhtml.append('</table></div><br/>') # html += fhtml fhtml.append('<div class="jmol-applet">') fhtml.append('<script>') fhtml.append('jmolApplet0 = Jmol.getApplet("jmolApplet0", Info)') fhtml.append("var lastPrompt=0;") fhtml.append('</script></div>') html += fhtml fhtml = [] # Outros arquivos de output for output in outputfiles: sfsize = get_file_size(output, self.opts.htmlfiledir) fhtml.append('<tr>') fhtml.append('<td><a href="%s">%s</a></td>' % (output, output)) fhtml.append('<td>%s</td>' % (sfsize)) fhtml.append('</tr>') if len(fhtml) > 0: html.append('<br>') html.append('<div class="sectionmessage">') html.append('<br>Download the output files:<br><br></div>') fhtml.insert( 0, '<div class="filetables"><table border="1"><tr><th>Output File</th>' '<th>Size</th></tr>\n') fhtml.append('</table></div><br>') html += fhtml fhtml = [] # arquivo zipado for output in compressedFile: sfsize = get_file_size(output, self.opts.htmlfiledir) fhtml.append('<tr>') fhtml.append('<td><a href="%s">%s</a></td>' % (output, output)) fhtml.append('<td>%s</td>' % (sfsize)) fhtml.append('</tr>') if len(fhtml) > 0: html.append('<br>') html.append('<div class="sectionmessage">') html.append('<br>Compressed file with all the output files<br><br></div>') fhtml.insert( 0, '<div class="filetables"><table border="1"><tr><th>File</th>' '<th>Size</th></tr>\n') fhtml.append('</table></div><br>') html += fhtml self.time_execution.set_job_end(datetime.datetime.now()) self.endTime = datetime.datetime.now() dif = self.time_execution.calculate_time_execution() html.append('<div>Time execution:<br>') html.append('Start: %s<br>' % self.time_execution.get_job_start().strftime("%d/%m/%Y %H:%M:%S")) html.append('End: %s<br>' % self.time_execution.get_job_end().strftime("%d/%m/%Y %H:%M:%S")) html.append('Total time: ~%dh:%dm:%ds' % (dif[0], dif[1], dif[2])) html.append('</div>') html.append('<hr>') html.append('<div>Citation<br>') html.append('Please, cite the used algorithm in this tool:<br><br>') html.append('') html.append('<br></div>') html.append(galhtmlpostfix) htmlf = file("%s.htm" % os.path.join(self.opts.htmlfiledir, self.opts.datasetID), 'w') htmlf.write('\n'.join(html)) htmlf.write('\n') htmlf.close() except Exception, e: show_error_message("Error on makeHtmlWithJMol:\n%s" % str(e))
def main(self): """ Create the ProtPred-EDA configuration file and begin the execution. @type self: koala.ProtPredEDA.ProtPredEDA """ 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.SequenceFile, self.opts.toolname, self.framework) copy_necessary_files( self.path_runs.get_path_execute(), self.path_runs.get_path_execution(), self.framework.get_framework()) # Config self.framework.set_parameter('OptimMethod', 'rboa') self.framework.set_parameter('MaxEval', self.opts.MaxEval) self.framework.set_parameter('Threshold', self.opts.Threshold) # FitnessPSP self.framework.set_parameter('VanderWaals', self.opts.VanderWaals) # ClassColection.setParameter('SASA', self.opts.SASA) self.framework.set_parameter('Coulomb', self.opts.Coulomb) self.framework.set_parameter('Solvatation', self.opts.Solvatation) self.framework.set_parameter('HydrogenBond', self.opts.HydrogenBond) self.framework.set_parameter('Torsion', self.opts.Torsion) self.framework.set_parameter('UseAngleDB', self.opts.UseAngleDB) self.framework.set_parameter('AminoAcidL', self.opts.AminoAcidL) # rboa self.framework.set_parameter('PopSize', self.opts.PopSize) self.framework.set_parameter('SelSize', self.opts.SelSize) self.framework.set_parameter('MaxParents', self.opts.MaxParents) self.framework.set_parameter('MixtureComponents', self.opts.MixtureComponents) create_configuration_file( self.path_runs.get_path_execution(), self.framework) self.framework.set_command( self.path_runs.get_path_execution(), 'protpred') config = 'input.ini' cl = [self.framework.get_command(), config, '&'] retProcess = subprocess.Popen( cl, 0, stdout=None, stderr=None, shell=False) retCode = retProcess.wait() if(retCode != 0): show_error_message( "The ProtPred-EDA framework finished wrong.\nContact the system administrator.") copy_files_to_execute_folder( self.path_runs.get_path_execution(), 'ProtPredEDA_rBOA') if(self.opts.runMinimization == 'true'): self.do_minimization("ProtPredEDA_rBOA") pdbs = sorted(list_directory(self.path_runs.get_path_execution(), '*.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) 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(), "ProtPredEDA-rBOA"): 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(), 'ProtPredEDA-rBOA.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 buildHighchart(self): """ Create a Highchart chart with the algorithm result @type self: koala.SortByFront.SortByFront """ try: # Load files files = list_directory(self.path_runs.get_path_execution(), '*.xvg') methods = self.methods # Objectivies obj1 = "" obj2 = "" x = [[]]*len(files) y = [[]]*len(files) for i, f in enumerate(files): f = os.path.join(self.path_runs.get_path_execution(), f) arq = open(f, "r") # Loading File x[i] = [] y[i] = [] for line in arq: if line.find("#") == -1: x[i].append(float(line.split("\t")[0].strip())) y[i].append(float(line.split("\t")[1])) else: col = line.split("\t") if len(col) > 1: obj1 = col[0].replace('#', ' ') obj2 = col[2] arq.close() chart = Highchart(renderTo="container2") chart.title("Pareto Fronts") chart.subtitle( "A graph with %s and %s objectivies showing at most four fronts, " "but the first as line and the others as scatter" % (obj1, obj2)) graph_options = { "xAxis": { "minPadding": 0.05, "maxPadding": 0.1, "title": { 'offset': 30, 'text': obj1, 'rotation': 0, }, }, "yAxis": { "minPadding": 0.05, "maxPadding": 0.1, "title": { 'offset': 50, 'text': obj2, 'rotation': -90, }, }, "tooltip": { "shared": True, "useHTML": False, # "valueDecimals": 3, }, } data = [] it = {} i_file = 0 context = Context(prec=3, rounding=ROUND_UP) if(len(x) > 5): fronts = 4 else: fronts = len(x) for i in range(fronts): # no máximo as duas primeiras fronteiras data = [] z = x[i] for ii, w in enumerate(z): if(i == 0): it["name"] = methods[i_file] i_file += 1 else: it["name"] = "front%d" % i if(not math.isinf(z[ii])): it["x"] = (context.create_decimal_from_float(z[ii])).quantize( Decimal('.2'), rounding=ROUND_UP) else: it["x"] = "0.0" if(not math.isinf(y[i][ii])): it["y"] = (context.create_decimal_from_float(y[i][ii])).quantize( Decimal('.2'), rounding=ROUND_UP) else: it["y"] = "0.0" data.append(it) it = {} if(i == 0): chart.add_data_set(data, name="front%d" % i, index=i, marker={"enabled": True}) else: chart.add_data_set(data, series_type="scatter", name="front%d" % i, index=i) chart.set_options(graph_options) return chart.generate() except Exception, e: show_error_message("Error on building highcharts.\n%s" % e)
def CreateDominanceMatrix(self): """ Create a text file with the dominance ranking matrix @type self: koala.DominanceRanking.DominanceRanking """ try: front = list_directory(self.path_runs.get_path_execution(), "*.front") if len(front) == 0: raise Exception("There is no .front file.\n") objectivies = [[]]*len(front) ranking = [[]]*len(front) methods = [[]]*len(front) values = {} # matriz to be used on dominance ranking temp = [] for i, f in enumerate(front): f = os.path.join(self.path_runs.get_path_execution(), f) arq = open(f, "r") # Loading File objectivies[i] = [] ln_objectives = '' ranking[i] = [] methods[i] = [] for line in arq: if line.find("#") == -1: ranking[i].append(line.split("\t")[0].strip()) methods[i].append(line.split("\t")[6].strip()) if line.split("\t")[6].strip() not in values: values[line.split("\t")[6].strip()] = [line.split("\t")[0].strip()] self.headers.append( [line.split("\t")[6].strip(), 0, 0, 0]) # DOMINANCE, WINS, LOSES else: ranks = values[line.split("\t")[6].strip()] ranks.append(line.split("\t")[0].strip()) values[line.split("\t")[6].strip()] = ranks else: col = line.split("\t") if len(col) > 1: objectivies[i].append(col[2]) objectivies[i].append(col[4]) ln_objectives += col[2] ln_objectives += ';' ln_objectives += col[4] arq.close() matrixFile = open(os.path.join( self.path_runs.get_path_execution(), 'dr_matrix.txt'), 'w+') # utilizando os metodos como header for i in range(len(values)): if i == 0: matrixFile.write('#%s' % methods[0][i]) else: matrixFile.write(methods[0][i]) matrixFile.write('\t\t') matrixFile.write('\n') # executa a quantidade de x correspondente a qtde de metodos for i in range(len(values)): pdb = methods[0][i] if pdb in values: ranks = values[pdb] temp.append(ranks) for i in range(len(temp[0])): self.data.append([]) for j in range(len(temp)): self.data[i].append(temp[j][i]) for i in range(len(temp[0])): for j in range(len(temp)): matrixFile.write(temp[j][i]) matrixFile.write('\t\t') matrixFile.write('\n') matrixFile.close() self.CalculateDominance() self.makeHtml() pdbsToCopy = [os.path.join( self.path_runs.get_path_execution(), method) for method in self.methods] if(self.opts.useJmol == 'true'): self.makeHtmlWithJMol(pdbsToCopy[0].split('/')[-1]) except Exception, e: raise Exception("Error on CreateDominanceMatrix.\n%s" % e)
def build_Highchart(self, objectivies, container="container"): """ Create a Highchart chart with the algorithm result @type self: koala.DominanceRanking.DominanceRanking @type objectivies: string @type container: string """ try: # Load files objs = objectivies.split(",") files = list_directory( self.path_runs.get_path_execution(), '*%s_%s*.xvg' % (objs[0], objs[1])) images = self.methods x = [[]]*len(files) y = [[]]*len(files) for i, f in enumerate(files): f = os.path.join(self.path_runs.get_path_execution(), f) arq = open(f, "r") # Loading File x[i] = [] y[i] = [] for line in arq: if line.find("#") == -1: x[i].append(float(line.split("\t")[0].strip())) y[i].append(float(line.split("\t")[1])) arq.close() chart = Highchart(renderTo=container) chart.title("Pareto Fronts") chart.subtitle("A graph with %s and %s objectivies" % (objs[0], objs[1])) graph_options = { "xAxis": { "minPadding": 0.05, "maxPadding": 0.1, "title": { 'offset': 30, 'text': objs[0], 'rotation': 0, }, }, "yAxis": { "minPadding": 0.05, "maxPadding": 0.1, "title": { 'offset': 50, 'text': objs[1], 'rotation': -90, }, }, "tooltip": { "shared": True, "useHTML": False, "valueDecimals": 3, }, } data = [] it = {} i_file = 0 context = Context(prec=3, rounding=ROUND_UP) if(len(x) >= 4): fronts = 4 else: # fronts = 2 fronts = len(x) for i in range(fronts): data = [] z = x[i] for ii, w in enumerate(z): if(i_file < len(images)): it["name"] = images[i_file] i_file += 1 else: it["name"] = "front%d" % i it["x"] = (context.create_decimal_from_float(z[ii])).quantize( Decimal('.1'), rounding=ROUND_UP) it["y"] = (context.create_decimal_from_float(y[i][ii])).quantize( Decimal('.1'), rounding=ROUND_UP) data.append(it) it = {} if(i == 0): chart.add_data_set(data, name="front%d" % i, index=i, marker={"enabled": True}) else: chart.add_data_set(data, series_type="scatter", name="front%d" % i, index=i) chart.set_options(graph_options) return chart.generate() except Exception, e: show_error_message("Error while building the Highchart:\n%s" % e)
def getGDTValues(self): """ Calculate the GDT-TS value to the input PDB files @type self: koala.CalculateGDTTS.CalculateGDTTS """ try: pdbs = list_directory(self.path_runs.get_path_execution(), "*.pdb") if not pdbs: raise "getGDTValues: No PDB file found.\n" dict_gdtts = None for pdb in pdbs: if not (pdb == self.opts.inputPDBRefName): name_pdb, ext = os.path.splitext(pdb) name_reference, ext = os.path.splitext(self.opts.inputPDBRefName) result_file = file(os.path.join( self.path_runs.get_path_execution(), name_reference + '_' + name_pdb + '.txt'), 'w') cl = [ self.path_runs.get_path_execute()+'TMscore', os.path.join( self.path_runs.get_path_execution(), self.opts.inputPDBRefName), os.path.join( self.path_runs.get_path_execution(), pdb), '-o', 'TM.sup', '>', self.path_runs.get_path_execution()+name_reference+'_'+name_pdb+'.txt', '&'] retProcess = subprocess.Popen( cl, 0, stdout=result_file, stderr=None, shell=False) retCode = retProcess.wait() if(retCode != 0): show_error_message( "The TMscore program finished wrong.\n" "Contact the system administrator.") os.chdir(self.path_runs.get_path_execution()) result_file = name_reference + '_' + name_pdb + '.txt' temp_gdtts = open(result_file, "r") for line in temp_gdtts.readlines(): if line.startswith("GDT-TS"): gdt_value = line.split("=", 1)[1].split("%", 1)[0].strip() only_pdb_file_name = os.path.basename(pdb) if(dict_gdtts is None): dict_gdtts = dict([(only_pdb_file_name, [gdt_value])]) else: dict_gdtts.update(dict([(only_pdb_file_name, [gdt_value])])) if line.startswith("GDT-HA"): gdt_value = line.split("=", 1)[1].split("%", 1)[0].strip() only_pdb_file_name = os.path.basename(pdb) if(only_pdb_file_name in dict_gdtts): ts = dict_gdtts.get(only_pdb_file_name) ts.append(gdt_value) dict_gdtts.update(dict([(only_pdb_file_name, ts)])) temp_gdtts.close() if(dict_gdtts is not None): return OrderedDict(sorted(dict_gdtts.items(), key=lambda x: x[1])) else: return None except Exception, e: show_error_message("Error on getGDTValues:\n%s" % e)
def main(self): """ Create the MEAMT configuration file and begin the execution to create a initial population. @type self: koala.MEAMT.MEAMT """ 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_command( self.path_runs.get_path_execution(), 'aemt-mo-up2') size = int(SizePopulation) / 15 cl = [ self.framework.get_command(), self.opts.numberGeneration, str(SizePopulation), str(size), str(size), str(size), str(size), str(size), str(size), str(size), str(size), str(size), str(size), str(size), str(size), str(size), str(size), str(size), str(size), str(0), str(0), self.opts.VanderWaalsWeight, self.opts.ChargeWeight, str(0), str(0), str(0), str(0), str(0), self.opts.SolvWeight, self.opts.HbondWeight, os.path.join(self.path_runs.get_path_execution(), "fasta.txt"), os.path.join(self.path_runs.get_path_execution(), "result.txt"), os.path.join(self.path_runs.get_path_execution(), "pop_meamt.txt"), os.path.join(self.path_runs.get_path_execution(), "MEAMT-M1.pdb"), os.path.join(self.path_runs.get_path_execution(), "saida1.txt"), os.path.join(self.path_runs.get_path_execution(), "angles.txt"), str(0), os.path.join(self.path_runs.get_path_execution(), "meat.txt"), '&'] retProcess = subprocess.Popen( cl, 0, stdout=None, stderr=subprocess.STDOUT, shell=False) retCode = retProcess.wait() if(retCode != 0): show_error_message( "The MEAMT framework finished wrong.\nContact the system administrator.") if(self.opts.runMinimization == 'true'): self.do_minimization() pdbs = list_directory(self.path_runs.get_path_execution(), '*.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) 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(), "MEAMT"): 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(), 'MEAMT.zip')) self.makeHtml() if(self.opts.useJmol == '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 get_result_files(path, tool, fileName=None): try: resultFile = '' filesToHtml = [] os.chdir(path) if tool == '2PG_SortByFront_Tool': resultFile = '%s%s.zip' % (path, tool) z = zipfile.ZipFile(resultFile, 'w', zipfile.ZIP_DEFLATED) listaArquivosFront = list_directory(path, '*.front') for arq in listaArquivosFront: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) listaArquivosXvg = list_directory(path, '*.xvg') for arq in listaArquivosXvg: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) listaArquivosPng = list_directory(path, '*.png') for arq in listaArquivosPng: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) listaArquivosLog = list_directory(path, '*.log') for arq in listaArquivosLog: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) elif tool in ( 'Dominance_Ranking', '2PG_SortMethodByFront_Tool', 'CalculateRMSD', 'CalculateTMScore', 'CalculateGDTTS'): resultFile = '%s%s.zip' % (path, tool) z = zipfile.ZipFile(resultFile, 'w', zipfile.ZIP_DEFLATED) listaArquivosFront = list_directory(path, '*.front') for arq in listaArquivosFront: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) listaArquivosXvg = list_directory(path, '*.xvg') for arq in listaArquivosXvg: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) listaArquivosPdf = list_directory(path, '*.pdf') for arq in listaArquivosPdf: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) listaArquivosPng = list_directory(path, '*.png') for arq in listaArquivosPng: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) listaArquivosTxt = list_directory(path, '*.txt') for arq in listaArquivosTxt: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) listaArquivosLog = list_directory(path, '*.log') for arq in listaArquivosLog: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) elif tool == '2PG_BuildConformation_Tool': resultFile = '%s%s' % (path, 'pop_0.pdb') elif tool in ( '2PG_NSGA2_Tool', '2PG_Mono_Tool', '2PG_MC_Metropolis', '2PG_Random_Tool'): resultFile = '%s%s.zip' % (path, tool) z = zipfile.ZipFile(resultFile, 'w', zipfile.ZIP_DEFLATED) if(fileName): listaArquivosPDB = list_directory(path, '%s*.pdb' % fileName) else: listaArquivosPDB = list_directory(path, '*.pdb') for arq in listaArquivosPDB: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) listaArquivosXvg = list_directory(path, '*.xvg') for arq in listaArquivosXvg: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) listaArquivosFit = list_directory(path, '*.fit') for arq in listaArquivosFit: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) listaArquivosPng = list_directory(path, '*.png') for arq in listaArquivosPng: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) elif(tool == 'ProtPred_EDA'): resultFile = '%s%s.zip' % (path, tool) z = zipfile.ZipFile(resultFile, 'w', zipfile.ZIP_DEFLATED) listaArquivosPDB = list_directory(path, '*.pdb') for arq in listaArquivosPDB: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) listaArquivosPng = list_directory(path, '*.png') for arq in listaArquivosPng: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) elif tool == 'Download_From_Quark': resultFile = '%s%s' % (path, '/ResultQuark.zip') z = zipfile.ZipFile(resultFile, 'w', zipfile.ZIP_DEFLATED) listaArquivosPDB = list_directory(path, '*.pdb') for arq in listaArquivosPDB: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() listaArquivosTxt = list_directory(path, '*.txt') for arq in listaArquivosTxt: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() elif(tool == 'MEAMT_BuildConformation_Tool'): resultFile = '%s%s' % (path, 'pop_meamt.txt') elif(tool == 'MEAMT_Tool'): resultFile = '%s%s.zip' % (path, tool) z = zipfile.ZipFile(resultFile, 'w', zipfile.ZIP_DEFLATED) listaArquivosPDB = list_directory(path, '*.pdb') for arq in listaArquivosPDB: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) listaArquivosPng = list_directory(path, '*.png') for arq in listaArquivosPng: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) listaArquivosTxt = list_directory(path, 'subpop*.txt') for arq in listaArquivosTxt: z = zipfile.ZipFile(resultFile, 'a', zipfile.ZIP_DEFLATED) z.write(arq) z.close() filesToHtml.append(os.path.join(path, arq)) return resultFile, filesToHtml except Exception, e: show_error_message("Error when getResultFiles:\n%s" % e)
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) 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,