Example #1
0
  def htmlSummaryXtriage(self):
    """
    Create HTML/php files for xtriage output results.
    """
    if self.verbose:
      self.logger.debug('AutoStats::htmlSummaryXtriage')
    try:
      if self.xtriage_summary:
        if self.gui:
          sl = 'jon_summary_xtriage.php'
        else:
          sl = 'jon_summary_xtriage.html'
        jon_summary = open(sl,'w')
        jon_summary.write(Utils.getHTMLHeader(self,'xtriage'))
        jon_summary.write('%6s$(document).ready(function() {\n'%'')
        jon_summary.write("%8s$('#accordion-xtriage').accordion({\n%11scollapsible: true,\n%11sactive: false });\n"%(3*('',)))
        jon_summary.write("%8s$('#xtriage-auto2').dataTable({\n"%'')
        jon_summary.write('%11s"bPaginate": false,\n%11s"bFilter": false,\n%11s"bInfo": false,\n%11s"bSort": false,\n%11s"bAutoWidth": false });\n'%(5*('',)))
        jon_summary.write("%8s$('#xtriage_pat').dataTable({\n"%'')
        jon_summary.write('%11s"bPaginate": false,\n%11s"bFilter": false,\n%11s"bInfo": false,\n%11s"bSort": false,\n%11s"bAutoWidth": false });\n'%(5*('',)))
        if self.pts:
          jon_summary.write("%8s$('#xtriage_pts').dataTable({\n"%'')
          jon_summary.write('%11s"bPaginate": false,\n%11s"bFilter": false,\n%11s"bInfo": false,\n%11s"bSort": false,\n%11s"bAutoWidth": false });\n'%(5*('',)))
        if self.twin:
          jon_summary.write("%8s$('#xtriage_twin').dataTable({\n"%'')
          jon_summary.write('%11s"bPaginate": false,\n%11s"bFilter": false,\n%11s"bInfo": false,\n%11s"bSort": false,\n%11s"bAutoWidth": false });\n'%(5*('',)))
        jon_summary.write('%6s});\n%4s</script>\n%2s</head>\n%2s<body id="dt_example">\n'%(4*('',)))
        jon_summary.writelines(self.xtriage_summary)
        jon_summary.write('%4s<div id="container">\n%5s<div class="full_width big">\n%6s<div id="demo">\n'%(3*('',)))
        jon_summary.write("%7s<h1 class='Results'>Xtriage Output</h1>\n%6s</div>\n%5s</div>\n"%(3*('',)))
        jon_summary.write('%5s<div id="accordion-xtriage">\n'%'')
        jon_summary.write('%6s<h3><a href="#">Click to view Xtriage log</a></h3>\n%6s<div>\n%7s<pre>\n'%(3*('',)))
        if self.xtriage_log:
          for line in self.xtriage_log:
            jon_summary.write(line)
        else:
          jon_summary.write('---------------Xtriage FAILED---------------\n')
        jon_summary.write('%7s</pre>\n%6s</div>\n%5s</div>\n%4s</div>\n%2s</body>\n</html>\n'%(5*('',)))
        jon_summary.close()
      else:
        Utils.failedHTML(self,('jon_summary_xtriage','Input data could not be analysed, probably because resolution was too low.'))

    except:
      self.logger.exception('**ERROR in AutoStats.htmlSummaryXtriage**')
Example #2
0
  def htmlSummaryMolrep(self):
    """
    Create HTML/php files for Molrep output results.
    """
    if self.verbose:
      self.logger.debug('AutoStats::htmlSummaryMolrep')
    try:
      if self.molrep_summary:
        molrep_log = self.molrep_results.get('Molrep results').get('Molrep log')
        if self.gui:
          sl = 'jon_summary_molrep.php'
        else:
          sl = 'jon_summary_molrep.html'
        jon_summary = open(sl,'w')
        jon_summary.write(Utils.getHTMLHeader(self))
        jon_summary.write('%6s$(document).ready(function() {\n'%'')
        jon_summary.write("%8s$('#accordion-molrep').accordion({\n"%'')
        jon_summary.write('%11scollapsible: true,\n%11sactive: false });\n'%('',''))
        if self.molrep_summary:
          jon_summary.write("%8s$('#molrep').dataTable({\n"%'')
          jon_summary.write('%11s"bPaginate": false,\n%11s"bFilter": false,\n%11s"bInfo": false,\n%11s"bSort": false,\n%11s"bAutoWidth": false});\n'%(5*('',)))
        jon_summary.write('%6s});\n%4s</script>\n%2s</head>\n%2s<body id="dt_example">\n'%(4*('',)))
        if self.molrep_summary:
          jon_summary.writelines(self.molrep_summary)
        else:
          jon_summary.write("%7s<h2 class='Results'>Error in molrep analysis</h1>\n"%'')
        jon_summary.write('%4s<div id="container">\n%5s<div class="full_width big">\n%6s<div id="demo">\n'%(3*('',)))
        jon_summary.write("%7s<h1 class='Results'>Molrep Output</h1>\n%6s</div>\n%5s</div>\n"%(3*('',)))
        jon_summary.write('%5s<div id="accordion-molrep">\n'%'')
        jon_summary.write('%6s<h3><a href="#">Click to view Molrep log</a></h3>\n%6s<div>\n%7s<pre>\n\n'%(3*('',)))
        if molrep_log:
          for line in open(molrep_log,'r').readlines():
            jon_summary.write(line)
        else:
          jon_summary.write('---------------Molrep FAILED---------------\n')
        jon_summary.write('%7s</pre>\n%6s</div>\n%5s</div>\n%4s</div>\n%2s</body>\n</html>\n'%(5*('',)))
        jon_summary.close()
      else:
        Utils.failedHTML(self,'jon_summary_molrep')

    except:
      self.logger.exception('**ERROR in AutoStats.htmlSummaryMolrep**')
Example #3
0
    def run(self):
        """
    Convoluted path of modules to run.
    """
        if self.verbose:
            self.logger.debug('LabelitPP::run')

        self.preprocess()
        if self.failed == False:
            #Run Labelit
            self.preprocessLabelit()
            self.processLabelit()
            #Sorts labelit results by highest symmetry.
            self.labelitSort()
            if self.labelit_failed == False:
                #Run labelit_precession_photo for the 3 planes
                self.processLabelitPP()
                self.Queue()
        else:
            Utils.failedHTML(self, 'jon_summary_pp')
        #Finish everything up
        self.postprocess()
Example #4
0
 def run(self):
   """
   Convoluted path of modules to run.
   """
   if self.verbose:
     self.logger.debug('LabelitPP::run')
   
   self.preprocess()
   if self.failed == False:
     #Run Labelit
     self.preprocessLabelit()
     self.processLabelit()
     #Sorts labelit results by highest symmetry.
     self.labelitSort()
     if self.labelit_failed == False:
       #Run labelit_precession_photo for the 3 planes
       self.processLabelitPP()
       self.Queue()
   else:
     Utils.failedHTML(self,'jon_summary_pp')
   #Finish everything up
   self.postprocess()
Example #5
0
  def plotXtriage(self):
    """
    generate plots html/php file
    """      
    if self.verbose:
      self.logger.debug('AutoStats::plotXtriage')
    try:
      cid0 = False
      cid1 = False
      anom       = self.xtriage_results.get('Xtriage results').get('Xtriage anom plot')
      intensity  = self.xtriage_results.get('Xtriage results').get('Xtriage int plot')
      #xtriage_i          = self.xtriage_results.get('Xtriage results').get('Xtriage i plot')
      nz         = self.xtriage_results.get('Xtriage results').get('Xtriage nz plot')
      l_test     = self.xtriage_results.get('Xtriage results').get('Xtriage l-test plot')
      #xtriage_z          = self.xtriage_results.get('Xtriage results').get('Xtriage z plot')
      if self.NCS_results:
        cid0 = self.NCS_results.get('PhaserNCS results').get('CID').get('before')
        cid1 = self.NCS_results.get('PhaserNCS results').get('CID').get('after')
      #List of params for parsing later.
      l = [['Intensity','Mean I vs. Resolution','Resolution(A)','M e a n &nbsp I',intensity,
            ("&lt I &gt smooth","&lt I &gt binning","&lt I &gt expected")],
           #['Z scores','Data Sanity and Completeness check','Resolution(A)','Z &nbsp S c o r e','z',
            #('Z_score','Completeness')],
           ['Anom_Signal','Anomalous Measurability','Resolution(A)','',anom,
            ('Obs_anom_meas','Smoothed')],
           #['I/sigI','Signal to Noise vs. Resolution','Resolution(A)','I / S i g I','i',
            #('Signal_to_Noise',)],
           ['NZ_Test','NZ Test','z','',nz,('Acen_obs','Acen_untwinned','Cen_obs','Cen_untwinned')],
           ['L_Test','L-Test','|I|','',l_test,('Obs','Acen_th_untwinned','Acen_th_perfect_twin')],
           ['CID0','CID before Anisotropic and tNCS correction','Z','',cid0,
            ('Acen_theo','Acen_twin','Acen_obs','Cen_theo','Cen_obs')],
           ['CID1','CID after Anisotropic and tNCS correction','Z','',cid1,
            ('Acen_theo','Acen_twin','Acen_obs','Cen_theo','Cen_obs')]
          ]
      if self.NCS_results:
        e = len(l)
      else:
        e = len(l) - 2
      if nz != 'None':
        xtriage_plot = ''
        xtriage_plot += Utils.getHTMLHeader(self,'plots')
        xtriage_plot +="%4s$(function() {\n%6s$('.tabs').tabs();\n%4s});\n"%(3*('',))
        xtriage_plot +="%4s</script>\n%2s</head>\n%2s<body>\n%4s<table>\n%6s<tr>\n"%(5*('',))
        xtriage_plot +='%8s<td width="100%%">\n%10s<div class="tabs">\n%12s<ul>\n'%(3*('',))
        for i in range(e):
          xtriage_plot += '%14s<li><a href="#tabs-44%s">%s</a></li>\n'%('',i,l[i][0])
        xtriage_plot += "%12s</ul>\n"%''
        for i in range(e):
          xtriage_plot += '%12s<div id="tabs-44%s">\n%14s<div class=title><b>%s</b></div>\n'%('',i,'',l[i][1])
          xtriage_plot += '%14s<div id="chart%s_div3" style="width:750px;height:550px;margin-left:20;"></div>\n'%('',i)
          xtriage_plot += '%14s<div class=x-label>%s</div>\n%14s<span class=y-label>%s</span>\n%12s</div>\n'%('',l[i][2],'',l[i][3],'')
        xtriage_plot +="%10s</div>\n%8s</td>\n%6s</tr>\n%4s</table>\n"%(4*('',))
        xtriage_plot += '%4s<script id="source" language="javascript" type="text/javascript">\n'%''
        xtriage_plot += "%6s$(function () {\n"%''
        s = '\n%8svar '%''
        for i in range(e):
          l1 = []
          l2 = []
          label = ['%10s[\n'%'']
          s1 = s
          for x in range(len(l[i][4][0])-1):
            var = '%s%s'%(l[i][0].upper(),x)
            s1 += '%s=[],'%var
            label.append('%12s{ data: %s, label:"%s" },\n'%('',var,l[i][5][x]))
            for y in range(len(l[i][4])):
              if l[i][0] == 'Anom_Signal':
                l2.append(float(l[i][4][y][0]))
              if l[i][0] in ('Intensity','Anom_Signal'):
                l1.append("%8s%s.push([-%s,%s]);\n"%('',var,l[i][4][y][0],l[i][4][y][x+1]))
              else:
                l1.append("%8s%s.push([%s,%s]);\n"%('',var,l[i][4][y][0],l[i][4][y][x+1]))
          if l[i][0] == 'Anom_Signal':
            xtriage_plot += '%s,mark=[];\n'%s1[:-1]
            label.append('%12s{ data: mark, label:"min level for anom signal" },\n'%'')
          else:
            xtriage_plot += '%s;\n'%s1[:-1]
          label.append('%10s],\n'%'')
          l[i].append(label)
          for line in l1:
            xtriage_plot += line
          if l[i][0] == 'Anom_Signal':
            xtriage_plot += "%8sfor (var i = -%s; i < -%s; i +=0.25)\n%8smark.push([i,0.05]);\n"%('',max(l2),min(l2),'')
        for i in range(e):
          xtriage_plot += '%8svar plot%s = $.plot($("#chart%s_div3"),\n'%('',i,i)
          for line in l[i][-1]:
            xtriage_plot += line
          xtriage_plot += "%10s{ lines: { show: true},\n%12spoints: { show: true },\n"%('','')
          xtriage_plot += "%12sselection: { mode: 'xy' },\n%12sgrid: { hoverable: false, clickable: false },\n"%('','')
          if l[i][0] in ('Intensity','Anom_Signal'):
            xtriage_plot += "%12sxaxis: { transform: function (v) { return Math.log(-v); },\n"%''
            xtriage_plot += "%21sinverseTransform: function (v) { return Math.exp(-v); },\n"%''
            xtriage_plot += "%21stickFormatter: ( function negformat(val,axis){return -val.toFixed(axis.tickDecimals);} ) },\n"%''
          else:
            xtriage_plot += "%12sxaxis: {min:0},\n"%''
          xtriage_plot += "%12syaxis: {min:0},\n%10s});\n\n"%('','')
        """
        xtriage_plot += "%8sfunction showTooltip(x, y, contents) {\n"%''
        xtriage_plot += "%10s$('<div id=\"tooltip\">' + contents + '</div>').css( {\n"%''
        xtriage_plot += "%12sposition: 'absolute',\n%12sdisplay: 'none',\n"%('','')
        xtriage_plot += "%12stop: y + 5,\n%12sleft: x + 5,\n%12sborder: '1px solid #fdd',\n"%(3*('',))
        xtriage_plot += "%12spadding: '2px',\n%12s'background-color': '#fee',\n"%('','')
        xtriage_plot += '%12sopacity: 0.80\n%10s}).appendTo("body").fadeIn(200);\n'%('','')
        xtriage_plot += "%8s}\n%6s});\n%4s</script>\n%2s</body>\n</html>\n"%(4*('',))
        """
        xtriage_plot += "%6s});\n%4s</script>\n%2s</body>\n</html>\n"%(3*('',))
        if xtriage_plot:
          if self.gui:
            sp = 'plots_xtriage.php'
          else:
            sp = 'plots_xtriage.html'
          xtriage_plot_file = open(sp,'w')
          xtriage_plot_file.writelines(xtriage_plot)
          xtriage_plot_file.close()
      else:
        Utils.failedHTML(self,'plots_xtriage')

    except:
      self.logger.exception('**ERROR in AutoStats.plotXtriage**')
      Utils.failedHTML(self,'plots_xtriage')
Example #6
0
  def postprocess(self):
    """
    Run summaries, make php/html files, send data back, and clean up.
    """
    if self.verbose:
      self.logger.debug('AutoStats::postprocess')
    
    output = {}
    status = {}
    results = {}
    failed = False
    cell_results = False
    cell_out = False
    pp_results = False
    pp_out = False
    
    #Make the output html files
    self.plotXtriage()
    if self.xtriage_results:
      Summary.summaryXtriage(self)
    self.htmlSummaryXtriage()
    if self.molrep_results:
      Summary.summaryMolrep(self)
    self.htmlSummaryMolrep()
    
    if self.gui:
      e = '.php'
    else:
      e = '.html'
    l = [('jon_summary_xtriage%s'%e,'Xtriage summary html'),
          ('plots_xtriage%s'%e,'Xtriage plots html'),
          ('jon_summary_molrep%s'%e,'Molrep summary html')]
    for i in range(len(l)):
      try:
        path = os.path.join(self.working_dir,l[i][0])
        if os.path.exists(path):
          output[l[i][1]] = path
        else:
          output[l[i][1]] = 'None'
      except:
        self.logger.exception('**Could not update paths of %s file.**'%l[i][0])
        output[l[i][1]] = 'FAILED'
        failed = True

    #Get rapd_agent_cell results back       
    try:
      cell_results = self.cell_output.get()
      if cell_results.has_key('status'):
        if cell_results['status'] == 'FAILED':
          failed = True
        del cell_results['status']
      if cell_results.has_key('Output files'):
        cell_out = cell_results['Output files']
        del cell_results['Output files']
    except:
      self.logger.exception('**Error importing rapd_agent_cell results**')

    #Get rapd_agent_pp results back
    try:
      if self.pp:
        pp_results = self.pp_output.get()
        if pp_results.has_key('status'):
          if pp_results['status'] == 'FAILED':
            failed = True
          del pp_results['status']
        if pp_results.has_key('Output files'):
          pp_out = pp_results['Output files']
          del pp_results['Output files']
      else:
        #Put together the dict from LabelitPP and create an html summary.
        pp_results = {'LabelitPP results': {'HK0 jpg':None,'H0L jpg':None,'0KL jpg':None}}
        Utils.failedHTML(self,('jon_summary_pp','Cannot create precession photos from merged datasets.'))
        if os.path.exists(os.path.join(self.working_dir,'jon_summary_pp%s'%e)):
          pp_out = {'LabelitPP summary html':os.path.join(self.working_dir,'jon_summary_pp%s'%e)}
        else:
          pp_out = {'LabelitPP summary html':'None'}
            
    except:
      self.logger.exception('**Error importing rapd_agent_cell results**')
    #Get proper status.
    if failed:
      status['status'] = 'FAILED'
    else:
      status['status'] = 'SUCCESS'
    #Put all the result dicts from all the programs run into one resultant dict and pass it along the pipe.
    try:
      results.update(status)
      if self.xtriage_results:
        results.update(self.xtriage_results)
      if self.molrep_results:
        results.update(self.molrep_results)
      if cell_results:
        results.update(cell_results)
      if pp_results:
        results.update(pp_results)
      if output:
        if cell_out:
          output.update(cell_out)
        if pp_out:
          output.update(pp_out)
        results.update(output)
      self.input.insert(0,'STATS')
      self.input.append(results)
      if self.gui:
        self.sendBack2(self.input)

    except:
      self.logger.exception('**Could not send results to pipe.**')

    try:
      #Cleanup my mess.
      if self.clean:
        if failed == False:
          if self.verbose:
            self.logger.debug('Cleaning up files')
          os.system('rm -rf *.ps *.btc *.tab *.xml *.com molrep.doc molrep.log logfile.log xtriage.log phaser2.log PHASER.mtz')
    except:
      self.logger.exception('**Could not cleanup**')

    #Say job is complete.
    t = round(time.time()-self.st)
    self.logger.debug('-------------------------------------')
    self.logger.debug('RAPD AutoStat complete.')
    self.logger.debug('Total elapsed time: %s seconds'%t)
    self.logger.debug('-------------------------------------')
    print '\n-------------------------------------'
    print 'RAPD AutoStat complete.'
    print 'Total elapsed time: %s seconds'%t
    print '-------------------------------------'
Example #7
0
  def postprocess(self,final=True):
    """
    Things to do after the main process runs
    1. Return the data through the pipe
    """
    if self.verbose:
      self.logger.debug('AutoMolRep::postprocess')
    #Run summary files for each program to print to screen
    output = {}
    results = {}
    output_files = False
    status = False
    cell_results = False
    failed = False
    #Setup output file name
    if self.phaser_results:
      Summary.summaryCell(self,'phaser')
    if self.input_pdb:
      self.htmlSummaryPhaser()
    else:
      Utils.failedHTML(self,('jon_summary_cell','Input PDB file does not exist.'))
    try:
      if self.gui:
        sl = 'jon_summary_cell.php'
      else:
        sl = 'jon_summary_cell.html'
      if os.path.exists(os.path.join(self.working_dir,sl)):
        output['Cell summary html'] = os.path.join(self.working_dir,sl)
      else:
        output['Cell summary html'] = 'None'
    except:
      self.logger.exception('**Could not update path of cell summary html file in AutoMolRep.postprocess.**')
      output['Cell summary html'] = 'FAILED'

    try:
      #Only tar up files at end to see if they show up in the user dir.
      #if final:
      if self.input_pdb:
        #pdb = os.path.basename(self.input_pdb)
        for sg in self.phaser_results.keys():
          dir1 = self.phaser_results[sg].get('AutoMR results').get('AutoMR dir')
          l = ['pdb','mtz','adf','peak']
          if dir1 not in ('No solution','Timed out','NA','DL Failed','Still running'):
            #pack all the output files in a tar and save the path in results.
            os.chdir(dir1)
            #tar = '%s_%s.tar'%(pdb[:-4],sg)
            tar = '%s_%s.tar'%(sg.split('_')[0],sg.split('_')[1])
            if os.path.exists('%s.bz2'%tar) == False:
              for p in l:
                f = self.phaser_results[sg].get('AutoMR results').get('AutoMR %s'%p)
                if os.path.exists(f):
                  os.system('tar -rf %s %s'%(tar,f))
              if os.path.exists(tar):
                os.system('bzip2 -qf %s'%tar)
              #Remove old tar's in working dir, if they exist and copy new one over.
              if os.path.exists(os.path.join(self.working_dir,'%s.bz2'%tar)):
                os.system('rm -rf %s'%os.path.join(self.working_dir,'%s.bz2'%tar))
              shutil.copy('%s.bz2'%tar,self.working_dir)
            self.phaser_results[sg].get('AutoMR results').update({'AutoMR tar': os.path.join(self.working_dir,'%s.bz2'%tar)})
          else:
            self.phaser_results[sg].get('AutoMR results').update({'AutoMR tar': 'None'})
      cell_results = { 'Cell analysis results': self.phaser_results }

    except:
      self.logger.exception('**Could not AutoMR results in AutoMolRep.postprocess.**')
      cell_results = { 'Cell analysis results': 'FAILED'}
      self.clean = False
      failed = True

    try:
      output_files = {'Output files' : output}
    except:
      self.logger.exception('**Could not update the output dict in AutoMolRep.postprocess.**')

    #Get proper status.
    if final:
      if failed:
        status = {'status': 'FAILED'}
      else:
        status = {'status': 'SUCCESS'}
    else:
      status = {'status': 'WORKING'}

    #Put all the result dicts from all the programs run into one resultant dict and pass it back.       
    try:
      if self.gui == False:
        if self.input[0] == "SAD":
          self.input.remove("SAD")
          self.input.insert(0,'MR')
      if status:
        results.update(status)
      if cell_results:
        results.update(cell_results)
      #Utils.pp(self,cell_results)
      if output_files:
        results.update(output_files)
      #Utils.pp(results)
      if self.gui:
        if results:
          if len(self.input) == 6:
            #Delete the previous Phaser results sent back.
            del self.input[5]
          self.input.append(results)
        self.sendBack2(self.input)

    except:
      self.logger.exception('**Could not send results to pipe in AutoMolRep.postprocess.**')

    if final:
      try:
        #Cleanup my mess.
        if self.clean:
          os.chdir(self.working_dir)
          if self.verbose:
            self.logger.debug('Cleaning up Phaser files and folders')
          os.system('rm -rf Phaser_* *.com *.pdb *.mtz *.sum')

      except:
        self.logger.exception('**Could not cleanup in AutoMolRep.postprocess**')

      #Say job is complete.
      t = round(time.time()-self.st)
      self.logger.debug(50*'-')
      self.logger.debug('RAPD AutoMolRep complete.')
      self.logger.debug('Total elapsed time: %s seconds'%t)
      self.logger.debug(50*'-')
      print 50*'-'
      print 'RAPD AutoMolRep complete.'
      print 'Total elapsed time: %s seconds'%t
      print 50*'-'