Пример #1
0
 def create_citation_tab(self, ample_dict):
     if self.citation_tab_id:
         return
     self.citation_tab_id = "citation_tab"
     pyrvapi.rvapi_insert_tab(self.citation_tab_id, "Citation",
                              self.log_tab_id, False)
     refMgr = reference_manager.ReferenceManager(ample_dict)
     bibtex_file = refMgr.save_citations_to_file(ample_dict)
     if self.ccp4i2:
         # The horror of ccp4i2 means that this all gets dumped into xml so we can't use any markup tags
         tdata = refMgr.citations_as_text
     else:
         tdata = refMgr.methods_as_html
         tdata += refMgr.citations_as_html
         tdata += '<hr><p>A bibtex file with the relevant citations has been saved to: {}</p>'.format(
             bibtex_file)
     pyrvapi.rvapi_add_text(tdata, self.citation_tab_id, 0, 0, 1, 1)
     if not self.ccp4i2:
         pyrvapi.rvapi_add_data(
             "bibtex_file",
             "Citations as BIBTEX",
             self.fix_path(bibtex_file),
             "text",
             self.citation_tab_id,
             2,
             0,
             1,
             1,
             True,
         )
     return self.citation_tab_id
Пример #2
0
    def create_ensembles_section(self, ample_dict):
        self.rm_pending_section()
        ensembles_data = ample_dict['ensembles_data']
        self.summary_tab_ensemble_sec_id = "ensembles"
        pyrvapi.rvapi_add_section(self.summary_tab_ensemble_sec_id,
                                  "Ensembles", self.summary_tab_id, 0, 0, 1, 1, True)
        if ample_dict['import_ensembles']:
            rstr = 'Imported {0} ensembles.'.format(len(ensembles_data))
            pyrvapi.rvapi_add_text(rstr, self.summary_tab_ensemble_sec_id, 0, 0, 1, 1)
        else:
            # Get the ensembling data
            d = ensembler.collate_cluster_data(ensembles_data)
            clusters = d['clusters']

            rstr = ""
            rstr += "Ensemble Results<br/>"
            rstr += "----------------<br/><br/>"
            rstr += "Cluster method: {0}<br/>".format(d['cluster_method'])
            rstr += "Cluster score type: {0}<br/>".format(d['cluster_score_type'])
            rstr += "Truncation method: {0}<br/>".format(d['truncation_method'])
            rstr += "Percent truncation: {0}<br/>".format(d['percent_truncation'])
            rstr += "Side-chain treatments: {0}<br/>".format(d['side_chain_treatments'])
            rstr += "Number of clusters: {0}<br/><br/>".format(len(clusters.keys()))
            rstr += "Generated {0} ensembles<br/><br/>".format(len(ensembles_data))
            pyrvapi.rvapi_add_text(rstr, self.summary_tab_ensemble_sec_id, 0, 0, 1, 1)
            ensemble_table = "ensemble_table"
            pyrvapi.rvapi_add_table1(self.summary_tab_ensemble_sec_id + "/" + ensemble_table, "Ensembling Results", 1, 0, 1, 1, True)
            tdata = []
            for i, cluster_num in enumerate(sorted(d['clusters'].keys())):
                header = True if i == 0 else False
                tdata += ensembler.cluster_table_data(clusters, cluster_num, d['side_chain_treatments'], header=header)
            self.fill_table(ensemble_table, tdata, tooltips=self._ensemble_tooltips)
        return
Пример #3
0
    def display_citation_tab(self):
        """Function to display citations for programs used within SIMBAD

        Returns
        -------
        object
            Section containing the relevant citations
        """

        self._create_citation_tab()

        args = self.get_arguments_from_log(self.logfile)

        refMgr = reference_manager.ReferenceManager(args)
        bibtex_file = refMgr.save_citations_to_file(self.work_dir)

        if self.ccp4i2:
            # The horror of ccp4i2 means that this all gets dumped into xml so we can't use any markup tags
            tdata = refMgr.citations_as_text
        else:
            tdata = refMgr.methods_as_html
            tdata += refMgr.citations_as_html
            tdata += '<hr><p>A bibtex file with the relevant citations has been saved to: {}</p>'.format(bibtex_file)
        pyrvapi.rvapi_add_text(tdata, self.citation_tab_id, 0, 0, 1, 1)
        if not self.ccp4i2:
            pyrvapi.rvapi_add_data("bibtex_file",
                                   "Citations as BIBTEX",
                                   self.fix_path(bibtex_file),
                                   "text",
                                   self.citation_tab_id,
                                   2, 0, 1, 1, True)
Пример #4
0
 def create_summary_tab(self, ample_dict):
     self._create_summary_tab()
     if self.do_create_ensembles_section(ample_dict):
         self.create_ensembles_section(ample_dict)
     if not self._got_mrbump_results(ample_dict):
         return self.summary_tab_id
     if not self.summary_tab_results_sec_id:
         self.rm_pending_section()
         # Only create the table once
         self.summary_tab_results_sec_id = "mrbump"
         pyrvapi.rvapi_add_section(self.summary_tab_results_sec_id,
                                   "MRBUMP", self.summary_tab_id, 0, 0, 1, 1, True)
         self.summary_tab_results_sec_table_id = "mrbump_table"
         pyrvapi.rvapi_add_table1(self.summary_tab_results_sec_id + "/" + self.summary_tab_results_sec_table_id,
                                  "MRBUMP Results", 1, 0, 1, 1, True)
     mrb_results = ample_dict.get('mrbump_results')
     if not mrb_results == self.old_mrbump_results:
         # We set old_mrbump_results when we create the results_tab
         self.fill_table(self.summary_tab_results_sec_table_id,
                         mrbump_util.ResultsSummary().results_table(mrb_results),
                         tooltips=self._mrbump_tooltips)
     if not self.summary_tab_survey_sec_id and not self.ccp4i2:
         # Only create the table once
         self.summary_tab_survey_sec_id = "survey"
         pyrvapi.rvapi_add_section(self.summary_tab_survey_sec_id, "Feedback", self.summary_tab_id, 0, 0, 1, 1, True)
         rstr = "<h2>How did we do?</h2><h3>Please follow this link and leave some feedback:</h3><a href='{0}' style='color: blue'>{0}</a>".format(reference_manager.survey_url)
         pyrvapi.rvapi_add_text(rstr, self.summary_tab_survey_sec_id, 0, 0, 1, 1)
     return self.summary_tab_id
Пример #5
0
    def import_all(self):

        # ============================================================================
        # start page construction: summary table

        pyrvapi.rvapi_add_table(self.import_summary_id(),
                                "<font size='+1'>Import Summary</font>",
                                self.report_page_id(), self.rvrow + 1, 0, 1, 1,
                                0)
        pyrvapi.rvapi_set_table_style(self.import_summary_id(), "table-blue",
                                      "text-align:left;")
        pyrvapi.rvapi_add_text("&nbsp;", self.report_page_id(), self.rvrow + 2,
                               0, 1, 1)
        self.rvrow += 3

        pyrvapi.rvapi_put_horz_theader(self.import_summary_id(),
                                       "Imported file",
                                       "Name of imported file", 0)
        pyrvapi.rvapi_put_horz_theader(self.import_summary_id(), "Type",
                                       "Dataset type", 1)
        pyrvapi.rvapi_put_horz_theader(self.import_summary_id(),
                                       "Generated dataset(s)",
                                       "List of generated datasets", 2)

        # ============================================================================
        # get list of uploaded files

        #self.files_all = [f for f in os.listdir(self.importDir()) if os.path.isfile(os.path.join(self.importDir(),f))]

        self.files_all = []
        for dirName, subdirList, fileList in os.walk(self.importDir(),
                                                     topdown=False):
            dName = dirName[len(self.importDir()) + 1:]
            for fname in fileList:
                self.files_all.append(os.path.join(dName, fname))

        # ============================================================================
        # do individual data type imports

        for importer in importers:
            importer.run(self)

        # ============================================================================
        # finish import

        if len(self.files_all) > 0:
            self.file_stdout.write ( "\n\n" + "="*80 + \
               "\n*** The following files are not recognised and will be ignored:\n" )
            for f in self.files_all:
                self.file_stdout.write("     " + f + "\n")
            self.file_stdout.write("\n")

            for f in self.files_all:
                self.putSummaryLine_red(f, "UNKNOWN",
                                        "Failed to recognise, ignored")
Пример #6
0
 def _create_summary_tab(self):
     if not self.summary_tab_id:
         self.summary_tab_id = "summary_tab"
         title = "Summary"
         pyrvapi.rvapi_insert_tab(self.summary_tab_id, title, self.citation_tab_id, False)
         # Create pending section until we have data to show
         self.summary_tab_pending_sec_id = 'summary_tab_pending'
         pyrvapi.rvapi_add_section(self.summary_tab_pending_sec_id, "Processing...",
                                   self.summary_tab_id, 0, 0, 1, 1, True)
         rstr = "<p>No results are currently available. Please check back later.</p>"
         pyrvapi.rvapi_add_text(rstr, self.summary_tab_pending_sec_id, 0, 0, 1, 1)
     return
Пример #7
0
 def create_citation_tab(self, ample_dict):
     if self.citation_tab_id:
         return
     self.citation_tab_id = "citation_tab"
     pyrvapi.rvapi_insert_tab(self.citation_tab_id, "Citation", self.log_tab_id, False)
     refMgr = reference_manager.ReferenceManager(ample_dict)
     bibtex_file = refMgr.save_citations_to_file(ample_dict)
     if self.ccp4i2:
         # The horror of ccp4i2 means that this all gets dumped into xml so we can't use any markup tags
         tdata = refMgr.citations_as_text
     else:
         tdata = refMgr.methods_as_html
         tdata += refMgr.citations_as_html
         tdata += '<hr><p>A bibtex file with the relevant citations has been saved to: {}</p>'.format(bibtex_file)
     pyrvapi.rvapi_add_text(tdata, self.citation_tab_id, 0, 0, 1, 1)
     if not self.ccp4i2:
         pyrvapi.rvapi_add_data("bibtex_file",
                                "Citations as BIBTEX",
                                self.fix_path(bibtex_file),
                                "text",
                                self.citation_tab_id,
                                2, 0, 1, 1, True)
     return self.citation_tab_id
Пример #8
0
    def _create_summary_tab(self):
        if not self.summary_tab_id:
            self.summary_tab_id = "summary_tab"
            title = "Summary"
            if self.ccp4i2:
                # Create summary tab
                pyrvapi.rvapi_add_tab(
                    self.summary_tab_id, title,
                    True)  # Last arg is "open" - i.e. show or hide
            else:
                # Insert summary tab before log tab
                pyrvapi.rvapi_insert_tab(
                    self.summary_tab_id, title, self.log_tab_id,
                    False)  # Last arg is "open" - i.e. show or hide

            # Create pending section until we have data to show
            self.summary_tab_pending_sec_id = 'summary_tab_pending'
            pyrvapi.rvapi_add_section(self.summary_tab_pending_sec_id,
                                      "Processing...", self.summary_tab_id, 0,
                                      0, 1, 1, True)
            rstr = "<p>No results are currently available. Please check back later. when your structure will have been solved. Honest.</p>"
            pyrvapi.rvapi_add_text(rstr, self.summary_tab_pending_sec_id, 0, 0,
                                   1, 1)
        return
Пример #9
0
def run(
    body,  # body is reference to the main Import class
    sectionTitle="Reflection datasets created",
    sectionOpen=False,  # to keep result section closed if several datasets
    freeRflag=True  # will be run if necessary
):

    files_mtz = []
    for f_orig in body.files_all:
        f_base, f_ext = os.path.splitext(f_orig)
        if f_ext.lower() in ('.hkl', '.mtz'):
            p_orig = os.path.join(body.importDir(), f_orig)
            f_fmt = mtz.hkl_format(p_orig, body.file_stdout)
            if f_fmt in ('xds_merged', 'mtz_merged'):
                files_mtz.append((f_orig, f_fmt))

    if not files_mtz:
        return

    mtzSecId = body.getWidgetId("mtz_sec") + "_"

    k = 0
    for f_orig, f_fmt in files_mtz:
        body.files_all.remove(f_orig)
        p_orig = os.path.join(body.importDir(), f_orig)
        p_mtzin = p_orig
        if not f_fmt.startswith('mtz_'):
            p_mtzin = os.path.splitext(f_orig)[0] + '.mtz'
            sp = subprocess.Popen('pointless',
                                  stdin=subprocess.PIPE,
                                  stdout=body.file_stdout,
                                  stderr=body.file_stderr)
            sp.stdin.write('XDSIN ' + p_orig + '\nHKLOUT ' + p_mtzin +
                           '\nCOPY\n')
            sp.stdin.close()
            if sp.wait():
                p_mtzin = None

        if p_mtzin:

            p_mtzout = p_mtzin
            rc = command.comrc()

            if freeRflag:

                p_mtzout = os.path.join(body.outputDir(),
                                        os.path.basename(f_orig))

                if k == 0:
                    scr_file = open(freerflag_script(), "w")
                    scr_file.write("UNIQUE\n")
                    scr_file.close()

                # run freerflag: generate FreeRFlag if it is absent, and expand
                # all reflections

                rc = command.call("freerflag",
                                  ["HKLIN", p_mtzin, "HKLOUT", p_mtzout],
                                  "./",
                                  freerflag_script(),
                                  body.file_stdout,
                                  body.file_stderr,
                                  log_parser=None)

            if rc.msg:
                msg = "\n\n Freerflag failed with message:\n\n" + \
                      rc.msg + \
                      "\n\n File " + f_orig + \
                      " cannot be processed.\n\n"
                body.file_stdout.write(msg)
                body.file_stderr.write(msg)
                body.putSummaryLine_red(f_orig, "MTZ",
                                        "Failed to process/import, ignored")

            else:

                mf = mtz.mtz_file(p_mtzout)
                body.summary_row_0 = -1  # to signal the beginning of summary row

                for ds in mf:

                    if k == 0:
                        body.file_stdout.write("\n" + "%" * 80 + "\n")
                        body.file_stdout.write(
                            "%%%%%  IMPORT REFLECTION DATA\n")
                        body.file_stdout.write("%" * 80 + "\n")

                    # make HKL dataset annotation
                    hkl = dtype_hkl.DType(body.job_id)
                    hkl.importMTZDataset(ds)
                    body.dataSerialNo += 1
                    hkl.makeDName(body.dataSerialNo)
                    datasetName = ""

                    if k == 0:
                        if sectionTitle:
                            pyrvapi.rvapi_add_section(mtzSecId, sectionTitle,
                                                      body.report_page_id(),
                                                      body.rvrow, 0, 1, 1,
                                                      sectionOpen)
                        else:
                            pyrvapi.rvapi_add_section(
                                mtzSecId,
                                "Reflection dataset created: " + hkl.dname,
                                body.report_page_id(), body.rvrow, 0, 1, 1,
                                sectionOpen)

                    subSecId = mtzSecId
                    if len(files_mtz) > 1 or len(mf) > 1:
                        subSecId = mtzSecId + str(k)
                        pyrvapi.rvapi_add_section(subSecId, hkl.dname,
                                                  mtzSecId, k, 0, 1, 1, False)
                        #pyrvapi.rvapi_add_section ( subSecId,
                        #            f_orig + " / " + hkl.getDataSetName(),
                        #            mtzSecId,k,0,1,1,False )

                    # run crtruncate
                    outFileName = os.path.join(body.outputDir(),
                                               hkl.dataId + ".mtz")
                    outXmlName = os.path.join("ctruncate" + hkl.dataId +
                                              ".xml")
                    cmd = ["-hklin", p_mtzout, "-hklout", outFileName]
                    amplitudes = ""

                    meanCols = hkl.getMeanColumns()
                    if meanCols[2] != "X":
                        cols = "/*/*/["
                        if meanCols[1] != None:
                            cols = cols + meanCols[0] + "," + meanCols[1]
                        else:
                            cols = cols + meanCols[0]
                        if meanCols[2] == "F":
                            amplitudes = "-amplitudes"
                        cmd += ["-colin", cols + "]"]

                    anomCols = hkl.getAnomalousColumns()
                    anomalous = False
                    if anomCols[4] != "X":
                        anomalous = True
                        cols = "/*/*/["
                        for i in range(0, 4):
                            if anomCols[i] != None:
                                if i > 0:
                                    cols = cols + ","
                                cols = cols + anomCols[i]
                        if anomCols[4] == "F":
                            amplitudes = "-amplitudes"
                        cmd += ["-colano", cols + "]"]

                    if amplitudes:
                        cmd += [amplitudes]

                    cmd += ["-xmlout", outXmlName]
                    cmd += ["-freein"]

                    pyrvapi.rvapi_add_text(
                        "&nbsp;<p><h2>Data analysis (CTruncate)</h2>",
                        subSecId, 1, 0, 1, 1)
                    pyrvapi.rvapi_add_panel(mtzSecId + str(k), subSecId, 2, 0,
                                            1, 1)
                    """
                    log_parser = pyrvapi_ext.parsers.generic_parser ( mtzSecId+str(k),
                            False,body.generic_parser_summary,False )
                    rc = command.call ( "ctruncate",cmd,"./",None,
                                        body.file_stdout,body.file_stderr,log_parser )
                    """
                    body.file_stdin = None  # not clear why this is not None at
                    # this point and needs to be forced,
                    # or else runApp looks for input script
                    body.setGenericLogParser(mtzSecId + str(k), False)
                    body.runApp("ctruncate", cmd)

                    body.file_stdout.flush()

                    mtzTableId = body.getWidgetId("mtz") + "_" + str(
                        k) + "_table"

                    if rc.msg:
                        msg = "\n\n CTruncate failed with message:\n\n" + \
                              rc.msg + \
                              "\n\n Dataset " + hkl.dname + \
                              " cannot be used.\n\n"
                        body.file_stdout.write(msg)
                        body.file_stderr.write(msg)
                        makeHKLTable(body, mtzTableId, subSecId, hkl, hkl, -1,
                                     msg, 0)
                        datasetName = hkl.dname

                    elif not os.path.exists(outFileName):
                        body.file_stdout.write ( "\n\n +++ Dataset " + hkl.dname + \
                            "\n was not truncated and will be used as is\n\n" )
                        hkl.makeUniqueFNames(body.outputDir())
                        body.outputDataBox.add_data(hkl)
                        makeHKLTable(body, mtzTableId, subSecId, hkl, hkl, 0,
                                     "", 0)
                        datasetName = hkl.dname

                        srf.putSRFDiagram(body, hkl, body.outputDir(),
                                          body.reportDir(), subSecId, 3, 0, 1,
                                          1, body.file_stdout,
                                          body.file_stderr, None)

                        pyrvapi.rvapi_set_text (
                                "&nbsp;<br><hr/><h3>Created Reflection Data Set (merged)</h3>" + \
                                "<b>Assigned name:</b>&nbsp;&nbsp;" + datasetName + "<br>&nbsp;",
                                subSecId,4,0,1,1 )
                        pyrvapi.rvapi_add_data(
                            "hkl_data_" + str(body.dataSerialNo),
                            "Merged reflections",
                            # always relative to job_dir from job_dir/html
                            os.path.join("..", body.outputDir(), hkl.files[0]),
                            "hkl:hkl",
                            subSecId,
                            5,
                            0,
                            1,
                            1,
                            -1)

                    else:
                        body.file_stdout.write ( "\n\n ... Dataset " + hkl.dname + \
                            "\n was truncated and will substitute the " + \
                            "original one\n\n" )
                        mtzf = mtz.mtz_file(outFileName)
                        # ctruncate should create a single dataset here
                        for dset in mtzf:
                            dset.MTZ = os.path.basename(outFileName)
                            hkl_data = dtype_hkl.DType(body.job_id)
                            hkl_data.importMTZDataset(dset)
                            hkl_data.dname = hkl.dname
                            hkl_data.dataId = hkl.dataId
                            hkl_data.makeUniqueFNames(body.outputDir())
                            body.outputDataBox.add_data(hkl_data)
                            makeHKLTable(body, mtzTableId, subSecId, hkl,
                                         hkl_data, 1, "", 0)
                            datasetName = hkl_data.dname

                            srf.putSRFDiagram(body, hkl_data, body.outputDir(),
                                              body.reportDir(), subSecId, 3, 0,
                                              1, 1, body.file_stdout,
                                              body.file_stderr, None)

                            pyrvapi.rvapi_set_text (
                                "&nbsp;<br><hr/><h3>Created Reflection Data Set (merged)</h3>" + \
                                "<b>Assigned name:</b>&nbsp;&nbsp;" + datasetName + "<br>&nbsp;",
                                subSecId,4,0,1,1 )
                            pyrvapi.rvapi_add_data(
                                "hkl_data_" + str(body.dataSerialNo),
                                "Merged reflections",
                                # always relative to job_dir from job_dir/html
                                os.path.join("..", body.outputDir(),
                                             hkl_data.files[0]),
                                "hkl:hkl",
                                subSecId,
                                5,
                                0,
                                1,
                                1,
                                -1)

                    if body.summary_row_0 < 0:
                        body.putSummaryLine(f_orig, "HKL", datasetName)
                    else:
                        body.addSummaryLine("HKL", datasetName)
                    k += 1
                    pyrvapi.rvapi_flush()

                if len(mf) <= 0:
                    body.putSummaryLine_red(f_orig, "UNKNOWN", "-- ignored")

            body.file_stdout.write("... processed: " + f_orig + "\n    ")

    body.rvrow += 1
    pyrvapi.rvapi_flush()

    return
Пример #10
0
    def results_section(self, results_tab_id, mrb_results, ensemble_results,
                        section_title):
        """Results Tab"""
        if not mrb_results:
            return
        # Create unique identifier for this section by using the id
        # All ids will have this appended to avoid clashes
        uid = str(uuid.uuid4())
        section_id = section_title.replace(" ", "_") + uid
        self.results_tab_sections.append(
            section_id)  # Add to list so we can remove if we update
        pyrvapi.rvapi_add_panel(section_id, results_tab_id, 0, 0, 1, 1)
        pyrvapi.rvapi_add_text("<h3>{0}</h3>".format(section_title),
                               section_id, 0, 0, 1, 1)
        results_tree = "results_tree" + section_id
        pyrvapi.rvapi_add_tree_widget(results_tree, section_title, section_id,
                                      0, 0, 1, 1)
        for r in mrb_results:
            ensemble_name = r['ensemble_name']
            container_id = "sec_{0}".format(ensemble_name) + uid
            pyrvapi.rvapi_add_panel(container_id, results_tree, 0, 0, 1, 1)

            header = "<h3>Results for ensemble: {0}</h3>".format(ensemble_name)
            pyrvapi.rvapi_add_text(header, container_id, 0, 0, 1, 1)

            sec_table = "sec_table_{0}".format(ensemble_name) + uid
            title = "Results table: {0}".format(ensemble_name)
            title = "Summary"
            pyrvapi.rvapi_add_section(sec_table, title, container_id, 0, 0, 1,
                                      1, True)
            table_id = "table_{0}".format(ensemble_name) + uid
            pyrvapi.rvapi_add_table(table_id, "", sec_table, 1, 0, 1, 1, False)
            tdata = mrbump_util.ResultsSummary().results_table([r])
            self.fill_table(table_id, tdata, tooltips=self._mrbump_tooltips)
            # Ensemble
            if ensemble_results:
                epdb = self.ensemble_pdb(r, ensemble_results)
                if epdb:
                    sec_ensemble = "sec_ensemble_{0}".format(
                        ensemble_name) + uid
                    pyrvapi.rvapi_add_section(sec_ensemble,
                                              "Ensemble Search Model",
                                              container_id, 0, 0, 1, 1, False)
                    data_ensemble = "data_ensemble_{0}".format(
                        ensemble_name) + uid
                    pyrvapi.rvapi_add_data(data_ensemble, "Ensemble PDB",
                                           self.fix_path(epdb), "XYZOUT",
                                           sec_ensemble, 2, 0, 1, 1, True)
            # PHASER
            self.add_results_section(
                result_dict=r,
                ensemble_name=ensemble_name,
                program_name='PHASER',
                logfile_key='PHASER_logfile',
                pdb_key='PHASER_pdbout',
                mtz_key='PHASER_mtzout',
                uid=uid,
                container_id=container_id,
            )
            # REFMAC
            self.add_results_section(
                result_dict=r,
                ensemble_name=ensemble_name,
                program_name='Refmac',
                logfile_key='REFMAC_logfile',
                pdb_key='REFMAC_pdbout',
                mtz_key='REFMAC_mtzout',
                uid=uid,
                container_id=container_id,
            )
            # Buccaner
            self.add_results_section(
                result_dict=r,
                ensemble_name=ensemble_name,
                program_name='BUCCANEER',
                logfile_key='BUCC_logfile',
                pdb_key='BUCC_pdbout',
                mtz_key='BUCC_mtzout',
                uid=uid,
                container_id=container_id,
            )
            # Arpwarp
            self.add_results_section(
                result_dict=r,
                ensemble_name=ensemble_name,
                program_name='ArpWarp',
                logfile_key='ARP_logfile',
                pdb_key='ARP_pdbout',
                mtz_key='ARP_mtzout',
                uid=uid,
                container_id=container_id,
            )
            # SHELXE
            self.add_results_section(
                result_dict=r,
                ensemble_name=ensemble_name,
                program_name='SHELXE',
                logfile_key='SHELXE_logfile',
                pdb_key='SHELXE_pdbout',
                mtz_key='SHELXE_mtzout',
                uid=uid,
                container_id=container_id,
            )
            # Buccaner Rebuild
            self.add_results_section(
                result_dict=r,
                ensemble_name=ensemble_name,
                program_name='BUCCANEER SHELXE Trace Rebuild',
                logfile_key='SXRBUCC_logfile',
                pdb_key='SXRBUCC_pdbout',
                mtz_key='SXRBUCC_mtzout',
                uid=uid,
                container_id=container_id,
            )
            # Arpwarp Rebuild
            self.add_results_section(
                result_dict=r,
                ensemble_name=ensemble_name,
                program_name='ARPWARP SHELXE Trace Rebuild',
                logfile_key='SXRARP_logfile',
                pdb_key='SXRARP_pdbout',
                mtz_key='SXRARP_mtzout',
                uid=uid,
                container_id=container_id,
            )
            pyrvapi.rvapi_set_tree_node(results_tree, container_id,
                                        "{0}".format(ensemble_name), "auto",
                                        "")
        return
Пример #11
0
    def run(self):

        # Prepare gesamt job

        # Just in case (of repeated run) remove the output xyz file. When gesamt
        # succeeds, this file is created.
        if os.path.isfile(self.gesamt_xyz()):
            os.remove(self.gesamt_xyz())

        if os.path.isfile(self.gesamt_json()):
            os.remove(self.gesamt_json())

        # Prepare gesamt input

        # fetch input data
        xyz = self.input_data.data.xyz
        nXYZ = len(xyz)

        # make command-line parameters
        cmd = []
        for i in range(nXYZ):
            cmd += [
                os.path.join(self.inputDir(), xyz[i].files[0]), "-s",
                xyz[i].chainSel
            ]

        if nXYZ < 2:
            if not "GESAMT_ARCHIVE" in os.environ:
                self.fail ( "<b> *** Error: jsCofe is not configured to work " + \
                            "with GESAMT Archive</b><br>" + \
                            "<i>     Please look for support</i><br>",
                            "No GESAMT Archive configured" )

            cmd += [
                "-archive", os.environ["GESAMT_ARCHIVE"], "-nthreads=auto",
                "-min1=" +
                self.getParameter(self.task.parameters.sec1.contains.MIN1),
                "-min2=" +
                self.getParameter(self.task.parameters.sec1.contains.MIN2),
                "-trim-size=1", "-trim-Q=" +
                self.getParameter(self.task.parameters.sec1.contains.QSCORE),
                "--json",
                self.gesamt_json()
            ]

            self.rvrow += 1
            pyrvapi.rvapi_add_grid(self.progress_grid_id(), False,
                                   self.report_page_id(), self.rvrow, 0, 1, 1)

            pyrvapi.rvapi_add_progress_bar(self.progress_bar_id(),
                                           self.progress_grid_id(), 0, 0, 1, 1)
            pyrvapi.rvapi_add_text("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ETR:&nbsp;",
                                   self.progress_grid_id(), 0, 1, 1, 1)
            pyrvapi.rvapi_add_label(self.etr_label_id(),
                                    self.progress_grid_id(), "--:--:--", 0, 2,
                                    1, 1)

            self.storeReportDocument(self.progress_bar_id() + ";" +
                                     self.etr_label_id())

        else:
            cmd += [
                "-o",
                self.gesamt_xyz(), "-o-cs",
                self.task.parameters.sec1.contains.MODE.value
            ]
            if nXYZ == 2:
                cmd += ["-domains"]

            self.putPanel(self.gesamt_report_id())
            self.storeReportDocument(
                self.gesamt_report_id())  # self.job_id.zfill(4) )

        r0 = self.getParameter(self.task.parameters.sec1.contains.R0)
        if r0:
            cmd += ["-r0=" + r0]
        sigma = self.getParameter(self.task.parameters.sec1.contains.SIGMA)
        if sigma:
            cmd += ["-sigma=" + sigma]

        cmd += ["--rvapi-rdoc", self.reportDocumentName()]

        # run gesamt
        self.runApp("gesamt", cmd)

        if nXYZ < 2:  # PDB scan

            pyrvapi.rvapi_remove_widget(self.progress_grid_id())
            pyrvapi.rvapi_reset_task()
            pyrvapi.rvapi_flush()

            if os.path.isfile(self.gesamt_json()):

                hitlist = jsonut.readjObject(self.gesamt_json())

                pyrvapi.rvapi_add_table(self.query_table_id(),
                                        "Query structure",
                                        self.report_page_id(), self.rvrow, 0,
                                        1, 1, 0)
                pyrvapi.rvapi_put_horz_theader(self.query_table_id(), "Name",
                                               "Structure name", 0)
                pyrvapi.rvapi_put_horz_theader(
                    self.query_table_id(), "Size",
                    "Structure size in number of residues", 1)
                pyrvapi.rvapi_put_table_string(
                    self.query_table_id(), hitlist.query.file + "&nbsp;(" +
                    hitlist.query.selection + ")", 0, 0)
                pyrvapi.rvapi_put_table_string(self.query_table_id(),
                                               hitlist.query.size, 0, 1)

                self.rvrow += 1
                self.putMessage("&nbsp;")

                querySize = float(hitlist.query.size)

                nColumns = len(hitlist.columns)
                if nColumns < 1 or not hasattr(hitlist.columns[0], "value"):
                    nHits = 0
                elif type(hitlist.columns[0].value) is list:
                    nHits = min(
                        len(hitlist.columns[0].value),
                        self.task.parameters.sec1.contains.MAXHITS.value)
                else:
                    nHits = 1

                if nHits < 1:
                    self.putTitle("No PDB matches found")
                    self.putMessage(
                        "<i>Hint:</i> try to reduce report thresholds " +
                        "(ultimately down to 0) in order to see any hits;<br>"
                        +
                        "doing so will increase computation time and report " +
                        "lower-quality (less relevant) matches.")
                else:

                    self.putSection(self.hits_table_sec_id(), "PDB Hits Table",
                                    False)

                    pyrvapi.rvapi_add_table(self.hits_table_id(),
                                            "PDB hits found",
                                            self.hits_table_sec_id(), 0, 0, 1,
                                            1, 100)
                    pyrvapi.rvapi_set_table_type(self.hits_table_id(), True,
                                                 True)
                    pyrvapi.rvapi_set_table_style(self.hits_table_id(), "",
                                                  "text-align:center;")

                    for j in range(nHits):
                        pyrvapi.rvapi_put_vert_theader(self.hits_table_id(),
                                                       str(j + 1),
                                                       "Hit number", j)
                        pyrvapi.rvapi_shape_vert_theader(
                            self.hits_table_id(), j, "text-align:right;", "",
                            1, 1)

                    for i in range(nColumns):
                        column = hitlist.columns[i]
                        pyrvapi.rvapi_put_horz_theader(self.hits_table_id(),
                                                       column.title,
                                                       column.tooltip, i)
                        if i == 0:
                            td_css = "font-family:courier;"
                        elif i == nColumns - 1:
                            td_css = "text-align:left;font-size:80%;"
                            pyrvapi.rvapi_shape_horz_theader(
                                self.hits_table_id(), i, td_css, "", 1, 1)
                        else:
                            td_css = ""
                        for j in range(nHits):
                            if nHits == 1:
                                pyrvapi.rvapi_put_table_string(
                                    self.hits_table_id(), column.value, j, i)
                            else:
                                pyrvapi.rvapi_put_table_string(
                                    self.hits_table_id(), column.value[j], j,
                                    i)
                            if td_css:
                                pyrvapi.rvapi_shape_table_cell(
                                    self.hits_table_id(), j, i, "", td_css, "",
                                    1, 1)

                    pyrvapi.rvapi_add_button(
                        "hits_dnl_btn", "Export hit list", "{function}",
                        "window.parent.downloadJobFile(" +
                        self.job_id + ",'hits.txt')", False,
                        self.hits_table_sec_id(), 1, 0, 1, 1)

                    if nHits > 1:

                        self.putSection(self.hits_graph_sec_id(),
                                        "Score Plots", False)

                        pyrvapi.rvapi_add_text("<h3>Alignment scores</h3>",
                                               self.hits_graph_sec_id(), 0, 0,
                                               1, 1)
                        pyrvapi.rvapi_add_graph(self.hits_graph_id(),
                                                self.hits_graph_sec_id(), 1, 0,
                                                1, 1)
                        pyrvapi.rvapi_set_graph_size(self.hits_graph_id(), 700,
                                                     400)

                        pyrvapi.rvapi_add_text("&nbsp;<p><hr/>",
                                               self.hits_graph_sec_id(), 2, 0,
                                               1, 1)
                        pyrvapi.rvapi_add_text("<h3>Correlation plots</h3>",
                                               self.hits_graph_sec_id(), 3, 0,
                                               1, 1)

                        pyrvapi.rvapi_add_loggraph(self.corr_graph_id(),
                                                   self.hits_graph_sec_id(), 4,
                                                   0, 1, 1)

                        pyrvapi.rvapi_add_graph_data("data",
                                                     self.hits_graph_id(),
                                                     "Scores")
                        pyrvapi.rvapi_add_graph_data("data",
                                                     self.corr_graph_id(),
                                                     "Score correlations")

                        def addDatasets(ref, name):
                            pyrvapi.rvapi_add_graph_dataset(
                                ref, "data", self.hits_graph_id(), name, name)
                            pyrvapi.rvapi_add_graph_dataset(
                                ref, "data", self.corr_graph_id(), name, name)
                            return

                        addDatasets("hno", "Hit number")
                        addDatasets("qscore", "Q-score")
                        addDatasets("rmsd", "R.m.s.d.")
                        addDatasets("nalign", "Nalign/n0")
                        addDatasets("seqid", "Seq. Id.")

                        def addData(ref, value):
                            pyrvapi.rvapi_add_graph_real(
                                ref, "data", self.hits_graph_id(), value, "%g")
                            pyrvapi.rvapi_add_graph_real(
                                ref, "data", self.corr_graph_id(), value, "%g")
                            return

                        for j in range(nHits):
                            pyrvapi.rvapi_add_graph_int(
                                "hno", "data", self.hits_graph_id(), j)
                            addData("qscore",
                                    float(hitlist.columns[2].value[j]))
                            addData("rmsd", float(hitlist.columns[3].value[j]))
                            addData(
                                "nalign",
                                float(hitlist.columns[4].value[j]) / querySize)
                            addData("seqid",
                                    float(hitlist.columns[5].value[j]))

                        pyrvapi.rvapi_add_graph_plot("plot",
                                                     self.hits_graph_id(),
                                                     "Score profiles",
                                                     "Hit number", "Scores")

                        def addLine(xset, yset, color):
                            pyrvapi.rvapi_add_plot_line(
                                "plot", "data", self.hits_graph_id(), xset,
                                yset)
                            pyrvapi.rvapi_set_line_options(
                                yset, "plot", "data", self.hits_graph_id(),
                                color, "solid", "off", 2.5, True)
                            return

                        addLine("hno", "qscore", "#00008B")
                        addLine("hno", "rmsd", "#8B0000")
                        addLine("hno", "nalign", "#8B8B00")
                        addLine("hno", "seqid", "#008B00")

                        pyrvapi.rvapi_set_plot_legend("plot",
                                                      self.hits_graph_id(),
                                                      "e", "")

                        def addPlot(plotId, name, xname, yname, xset, yset,
                                    color):
                            pyrvapi.rvapi_add_graph_plot(
                                plotId, self.corr_graph_id(), name, xname,
                                yname)
                            pyrvapi.rvapi_add_plot_line(
                                plotId, "data", self.corr_graph_id(), xset,
                                yset)
                            pyrvapi.rvapi_set_line_options(
                                yset, plotId, "data", self.corr_graph_id(),
                                color, "off", "filledCircle", 2.5, True)
                            return

                        addPlot("p1", "R.m.s.d. vs Seq. Id", "Seq. Id",
                                "R.m.s.d.", "seqid", "rmsd", "#8B0000")
                        addPlot("p2", "R.m.s.d. vs Q-score", "Q-score",
                                "R.m.s.d.", "qscore", "rmsd", "#8B0000")
                        addPlot("p3", "R.m.s.d. vs Nalign",
                                "Normalised alignment length", "R.m.s.d.",
                                "nalign", "rmsd", "#8B0000")
                        addPlot("p4", "Seq. Id. vs Q-score", "Q-score",
                                "Seq. Id.", "qscore", "seqid", "#008B00")
                        addPlot("p5", "Seq. Id. vs Nalign",
                                "Normalised alignment length", "Seq. Id.",
                                "nalign", "seqid", "#008B00")
                        addPlot("p6", "Nalign vs. Q-score", "Q-score",
                                "Normalised alignment length", "qscore",
                                "nalign", "#8B8B00")

            else:
                self.putTitle("No PDB matches found")

        else:  # pairwise or multiple alignment

            self.rvrow += 1
            if nXYZ == 2:
                outFiles = self.restoreReportDocument().split("\n")
            elif nXYZ > 2:
                outFiles = [self.gesamt_xyz()]

            if len(outFiles) > 0:

                self.putTitle("Gesamt Output")

                # register output data from temporary location (files will be moved
                # to output directory by the registration procedure)
                ensemble = self.registerEnsemble(
                    dtype_template.subtypeProtein(), outFiles[0])
                if ensemble:
                    self.putEnsembleWidget("ensemble_btn",
                                           "Superposed ensemble&nbsp;&nbsp;",
                                           ensemble, -1)

                for i in range(1, len(outFiles) - 1):
                    self.rvrow += 1
                    ensemble = self.registerEnsemble(
                        dtype_template.subtypeProtein(), outFiles[i])
                    if ensemble:
                        self.putEnsembleWidget("ensemble_" + str(i) + "_btn",
                                               "Superposed domain #" + str(i),
                                               ensemble, -1)

            else:
                self.putTitle("No Output Files Generated")

        # close execution logs and quit
        self.success()
        return
Пример #12
0
    def create_summary_tab(self, ample_dict):
        #
        # Summary Tab
        #
        self._create_summary_tab()

        if not (ample_dict['single_model_mode'] or ample_dict['homologs'] or ample_dict['ideal_helices']) and \
            bool(ample_dict['ensembles_data']) and not self.summary_tab_ensemble_sec_id:

            self.rm_pending_section()

            ensembles_data = ample_dict['ensembles_data']
            self.summary_tab_ensemble_sec_id = "ensembles"
            pyrvapi.rvapi_add_section(self.summary_tab_ensemble_sec_id,
                                      "Ensembles", self.summary_tab_id, 0, 0,
                                      1, 1, True)

            # Get the ensembling data
            d = ensembler.collate_cluster_data(ensembles_data)
            clusters = d['clusters']

            rstr = ""
            rstr += "Ensemble Results<br/>"
            rstr += "----------------<br/><br/>"
            rstr += "Cluster method: {0}<br/>".format(d['cluster_method'])
            rstr += "Cluster score type: {0}<br/>".format(
                d['cluster_score_type'])
            rstr += "Truncation method: {0}<br/>".format(
                d['truncation_method'])
            rstr += "Percent truncation: {0}<br/>".format(
                d['percent_truncation'])
            rstr += "Side-chain treatments: {0}<br/>".format(
                d['side_chain_treatments'])
            rstr += "Number of clusters: {0}<br/><br/>".format(
                len(clusters.keys()))
            rstr += "Generated {0} ensembles<br/><br/>".format(
                len(ensembles_data))
            pyrvapi.rvapi_add_text(rstr, self.summary_tab_ensemble_sec_id, 0,
                                   0, 1, 1)

            ensemble_table = "ensemble_table"
            pyrvapi.rvapi_add_table1(
                self.summary_tab_ensemble_sec_id + "/" + ensemble_table,
                "Ensembling Results", 1, 0, 1, 1, True)
            # for cluster_num in sorted(clusters.keys()):
            #     rstr += "\n"
            #     rstr += "Cluster {0}\n".format(cluster_num)
            #     rstr += "Number of models: {0}\n".format(clusters[cluster_num]['cluster_num_models'])
            #     rstr += "Cluster centroid: {0}\n".format(clusters[cluster_num]['cluster_centroid'])
            #     rstr += "\n"
            #     tdata = cluster_table_data(clusters, cluster_num)
            #     rstr += tableFormat.pprint_table(tdata)
            #
            cluster_num = 1
            tdata = ensembler.cluster_table_data(clusters, cluster_num,
                                                 d['side_chain_treatments'])
            self.fill_table(ensemble_table,
                            tdata,
                            tooltips=self._ensemble_tooltips)

        #
        # MRBUMP Results
        #
        if not self._got_mrbump_results(ample_dict): return self.summary_tab_id
        if not self.summary_tab_results_sec_id:
            self.rm_pending_section()
            # Only create the table once
            self.summary_tab_results_sec_id = "mrbump"
            pyrvapi.rvapi_add_section(self.summary_tab_results_sec_id,
                                      "MRBUMP", self.summary_tab_id, 0, 0, 1,
                                      1, True)
            self.summary_tab_results_sec_table_id = "mrbump_table"
            pyrvapi.rvapi_add_table1(
                self.summary_tab_results_sec_id + "/" +
                self.summary_tab_results_sec_table_id, "MRBUMP Results", 1, 0,
                1, 1, True)

        mrb_results = ample_dict['mrbump_results']
        if not mrb_results == self.old_mrbump_results:
            # We set old_mrbump_results when we create the results_tab
            self.fill_table(
                self.summary_tab_results_sec_table_id,
                mrbump_util.ResultsSummary().results_table(mrb_results),
                tooltips=self._mrbump_tooltips)

        #
        # Survey section
        #
        if not self.summary_tab_survey_sec_id and not self.ccp4i2:
            # Only create the table once
            self.summary_tab_survey_sec_id = "survey"
            pyrvapi.rvapi_add_section(self.summary_tab_survey_sec_id,
                                      "Feedback", self.summary_tab_id, 0, 0, 1,
                                      1, True)
            rstr = "<h2>How did we do?</h2><h3>Please follow this link and leave some feedback:</h3><a href='{0}' style='color: blue'>{0}</a>".format(
                ample_util.survey_url)
            pyrvapi.rvapi_add_text(rstr, self.summary_tab_survey_sec_id, 0, 0,
                                   1, 1)
        return self.summary_tab_id
Пример #13
0
    def run(self):

        # Check the existence of PDB archive
        self.checkPDB()

        # Prepare mrbump input
        # fetch input data
        seq = self.input_data.data.seq[0]
        hkl = None
        if hasattr(self.input_data.data, 'hkl'):  # optional data parameter
            hkl = self.input_data.data.hkl[0]

        # make a file with input script
        self.open_stdin()

        if hkl:
            self.write_stdin (
                "JOBID " + self.outdir_name() + "\n" + \
                "MDLS False\n" + \
                "MDLC True\n" + \
                "MDLD False\n" + \
                "MDLP False\n" + \
                "MDLM False\n" + \
                "MDLU False\n" + \
                "MRPROG molrep phaser\n" + \
                "SHELX False\n" + \
                "BUCC True\n" + \
                "BCYC 5\n" + \
                "ARPW False\n" + \
                "CHECK False\n" + \
                "UPDATE False\n" + \
                "PICKLE False\n" + \
                "MRNUM 10\n" + \
                "USEE True\n" + \
                "SCOP False\n" + \
                "DEBUG False\n" + \
                "RLEVEL 95\n" + \
                "GESE False\n" + \
                "GEST False\n" + \
                "AMPT False\n" + \
                "PDBLOCAL " + os.environ["PDB_DIR"] + "\n" + \
                "LABIN F=" + hkl.dataset.Fmean.value + \
                  " SIGF=" + hkl.dataset.Fmean.sigma + \
                  " FreeR_flag=" + hkl.dataset.FREE + "\n" + \
                "LITE False\n" + \
                "END\n"
            )

        else:
            self.write_stdin (
                "JOBID " + self.outdir_name() + "\n" + \
                "MDLS False\n" + \
                "MDLC True\n" + \
                "MDLD False\n" + \
                "MDLP False\n" + \
                "MDLM False\n" + \
                "MDLU False\n" + \
                "CHECK False\n" + \
                "UPDATE False\n" + \
                "PICKLE False\n" + \
                "MRNUM 5\n" + \
                "USEE True\n" + \
                "SCOP False\n" + \
                "DEBUG False\n" + \
                "RLEVEL 95\n" + \
                "GESE True\n" + \
                "GEST True\n" + \
                "AMPT False\n" + \
                "IGNORE 5tha\n" + \
                "DOPHMMER True\n" + \
                "PDBLOCAL " + os.environ["PDB_DIR"] + "\n" + \
                "DOHHPRED False\n" + \
                "END\n"
            )

        self.close_stdin()

        # make command-line parameters for mrbump run on a SHELL-type node
        cmd = ["seqin", os.path.join(self.inputDir(), seq.files[0])]

        if hkl:
            cmd += ["hklin", os.path.join(self.inputDir(), hkl.files[0])]
            # prepare report parser
            self.setGenericLogParser(self.mrbump_report(), True)

        # Start mrbump
        self.runApp("mrbump", cmd)
        self.unsetLogParser()

        # check solution and register data

        search_dir = "search_" + self.outdir_name()

        if os.path.isdir(search_dir):

            if hkl:
                molrep_dir = os.path.join(search_dir, "results", "solution",
                                          "mr", "molrep", "refine")

                if os.path.isdir(molrep_dir):
                    dirlist = os.listdir(molrep_dir)
                    xyzfile = None
                    #mtzfile = None
                    for filename in dirlist:
                        if filename.startswith("refmac"):
                            if filename.endswith(".pdb"):
                                xyzfile = os.path.join(molrep_dir, filename)
                            #if filename.endswith(".mtz"):
                            #mtzfile = os.path.join(molrep_dir,filename)

                    structure = self.finaliseStructure(xyzfile, "mrbump", hkl,
                                                       None, [seq], 1, False)
                    if structure:
                        # update structure revision
                        revision = self.makeClass(
                            self.input_data.data.revision[0])
                        revision.setStructureData(structure)
                        self.registerRevision(revision)

                else:
                    self.putTitle("No solution found")

            else:
                models_found = False
                ensembles_found = False
                models_dir = os.path.join(search_dir, "models")

                if os.path.isdir(models_dir):

                    mdirlist = os.listdir(models_dir)
                    domainNo = 1
                    dirName = "domain_" + str(domainNo)

                    while dirName in mdirlist:

                        secrow = 0
                        domains_dir = os.path.join(models_dir, dirName)
                        dirlist = os.listdir(domains_dir)

                        for filename in dirlist:
                            if filename.endswith(".pdb"):

                                if not models_found:
                                    models_found = True
                                    self.putTitle("Results")

                                if secrow == 0:
                                    secId = "domain_sec_" + str(domainNo)
                                    self.putSection(secId,
                                                    "Domain " + str(domainNo))
                                    pyrvapi.rvapi_add_text(
                                        "<h2>Models found:</h2>", secId,
                                        secrow, 0, 1, 1)
                                    secrow += 1

                                xyz = self.registerXYZ(
                                    os.path.join(domains_dir, filename))
                                if xyz:
                                    xyz.addDataAssociation(seq.dataId)
                                    pyrvapi.rvapi_add_data(
                                        "model_" + str(self.dataSerialNo) +
                                        "_btn",
                                        "Model #" +
                                        str(self.dataSerialNo).zfill(2),
                                        # always relative to job_dir from job_dir/html
                                        os.path.join("..", self.outputDir(),
                                                     xyz.files[0]),
                                        "xyz",
                                        secId,
                                        secrow,
                                        0,
                                        1,
                                        1,
                                        -1)
                                    secrow += 1

                        ensembles_dir = os.path.join(domains_dir, "ensembles")
                        ensembleSerNo = 0
                        if os.path.isdir(ensembles_dir):
                            for filename in os.listdir(ensembles_dir):
                                if filename.endswith(".pdb"):
                                    if not ensembles_found:
                                        pyrvapi.rvapi_add_text(
                                            "<h2>Ensembles made:</h2>", secId,
                                            secrow, 0, 1, 1)
                                        ensembles_found = True
                                        secrow += 1
                                    ensembleSerNo += 1
                                    ensemble = self.registerEnsemble(
                                        seq,
                                        os.path.join(ensembles_dir, filename))
                                    if ensemble:
                                        ensemble.addDataAssociation(seq.dataId)
                                        self.putEnsembleWidget1(
                                            secId, "ensemble_" +
                                            str(ensembleSerNo) + "_btn",
                                            "Ensemble #" +
                                            str(ensembleSerNo).zfill(2),
                                            ensemble, -1, secrow, 1)
                                        secrow += 1

                        domainNo += 1
                        dirName = "domain_" + str(domainNo)

                # ----------------------------------------------------------------
                if not models_found:
                    self.putTitle("No models found")

        else:
            self.putTitle("No resuts produced")

        # close execution logs and quit
        self.success()
        return
Пример #14
0
def write_output(items,
                 json_file=None,
                 xml_file=None,
                 xmlroot=None,
                 docid=None,
                 output=None):
    # in non-i2 mode items are added to the output dictionary which is dumped to json
    if json_file is not None:
        if 'result' in items:
            result = items['result']
            for solution in output['solutions']:
                if solution['id'] == result['id']:
                    solution.update({'acornCC': result['acornCC']})
        else:
            output.update(items)
        temp_filename = json_file + '.tmp'
        with open(temp_filename, 'w') as jsonfile:
            print(json.dumps(output,
                             sort_keys=True,
                             indent=2,
                             separators=(',', ': ')),
                  file=jsonfile)
        if os.path.exists(json_file):
            import uuid
            tmpfile = str(uuid.uuid4())
            os.rename(json_file, tmpfile)
            os.remove(tmpfile)
        os.rename(temp_filename, json_file)
        return output
    elif xmlroot is None and xml_file is not None:
        xmlroot = etree.Element('Fragon')
        return xmlroot
    elif docid is None:
        jsrview_dir = os.path.join(os.environ['CCP4'], 'share', 'jsrview')
        pyrvapi.rvapi_init_document('fragon_results', os.getcwd(),
                                    'Fragon %s results' % items['Fragon'], 1,
                                    7, jsrview_dir, None, None, None, None)
        pyrvapi.rvapi_add_tab('tab1', 'Fragon results', True)
        pyrvapi.rvapi_add_section('status', 'Current status', 'tab1', 0, 0, 1,
                                  1, True)
        pyrvapi.rvapi_add_text(
            'The job is currently running. Updates will be shown here after fragment placement and density modification.',
            'status', 0, 0, 1, 1)
        pyrvapi.rvapi_flush()
        output.update(items)
        return 'tab1', output
    elif xml_file is not None:
        # in i2 mode new items are added to the etree as this preserves the order in the xml
        for key in items:
            if key == 'Fragon':
                version_node = etree.SubElement(xmlroot, 'Version')
                version_node.text = output['Fragon']
            elif key == 'callback':
                callback = items['callback']
                if callback[0] == 'progress':
                    try:
                        progress_node = xmlroot.xpath(
                            '//Fragon/phaser_progress')[0]
                    except IndexError:
                        progress_node = etree.SubElement(
                            xmlroot, 'phaser_progress')
                    progress_node.text = callback[1]
                elif callback[0] == 'Best LLG/TFZ':
                    best_llg_node = etree.SubElement(xmlroot, 'best_llg')
                    best_llg_node.text = callback[1]['llg']
                    best_tfz_node = etree.SubElement(xmlroot, 'best_tfz')
                    best_tfz_node.text = callback[1]['tfz']
            elif key == 'solutions':
                solutions = items['solutions']
                try:
                    solutions_node = xmlroot.xpath('//Fragon/solutions')[0]
                except IndexError:
                    solutions_node = etree.SubElement(xmlroot, 'solutions')
                if len(solutions) > 0:
                    solutions_node.text = json.dumps(solutions)
            else:
                node = etree.SubElement(xmlroot, key)
                node.text = items[key].__str__()
        temp_filename = 'program.xml.tmp'
        with open(temp_filename, 'w') as xmlfile:
            xmlfile.write(etree.tostring(xmlroot, pretty_print=True))
        if os.path.exists(xml_file):
            import uuid
            tmpfile = str(uuid.uuid4())
            os.rename(xml_file, tmpfile)
            os.remove(tmpfile)
        os.rename(temp_filename, xml_file)
    elif docid is not None:
        for key in items:
            if key == 'copies':
                if items['copies'] > 1:
                    pyrvapi.rvapi_set_text(
                        'Running Phaser to place %d fragments' %
                        items['copies'], 'status', 0, 0, 1, 1)
                else:
                    pyrvapi.rvapi_set_text(
                        'Running Phaser to place the fragment', 'status', 0, 0,
                        1, 1)
                pyrvapi.rvapi_add_tab('tab2', 'Phaser log file', False)
                pyrvapi.rvapi_append_content(output['root'] + '_Phaser.log',
                                             True, 'tab2')
                pyrvapi.rvapi_flush()
                output.update(items)
            elif key == 'callback':
                callback = items['callback']
                if callback[0] == 'progress':
                    pyrvapi.rvapi_set_text(
                        'Current Phaser stage: %s' % callback[1], 'status', 1,
                        0, 1, 1)
                    pyrvapi.rvapi_flush()
                elif callback[0] == 'Best LLG':
                    pyrvapi.rvapi_set_text(
                        'Current best solution Log Likelihood Gain (LLG): %s Translation Function Z-score (TFZ): %s'
                        % (callback[1], output['best_tfz']), 'status', 2, 0, 1,
                        1)
                    pyrvapi.rvapi_flush()
                elif callback[0] == 'Best TFZ':
                    output.update({'best_tfz': callback[1]})
            elif key == 'solutions':
                solutions = items['solutions']
                top_llg = sorted(solutions,
                                 key=lambda r: r['llg'],
                                 reverse=True)[0]['llg']
                top_tfz = sorted(solutions,
                                 key=lambda r: r['llg'],
                                 reverse=True)[0]['tfz']
                top_acornCC = sorted([
                    solution['acornCC'] if solution['acornCC']
                    not in ['Running', '-', None] else None
                    for solution in solutions
                ],
                                     reverse=True)[0]
                if len(solutions) == 1:
                    pyrvapi.rvapi_set_text(
                        'Phaser has found a single solution with Log Likelihood Gain (LLG) of %0.2f and Translation Function Z-score (TFZ) of %0.2f'
                        % (top_llg, top_tfz), 'status', 0, 0, 1, 1)
                else:
                    pyrvapi.rvapi_set_text(
                        'Phaser has found %d solutions. The top solution has Log Likelihood Gain (LLG) of %0.2f and Translation Function Z-score (TF Z-score) of %0.2f'
                        % (output['num_phaser_solutions'], top_llg, top_tfz),
                        'status', 0, 0, 1, 1)
                if output['num_phaser_solutions'] > len(solutions):
                    pyrvapi.rvapi_set_text(
                        'Attempting to improve phases for the top %d solutions by density modification with ACORN'
                        % len(solns), 'status', 1, 0, 1, 1)
                else:
                    pyrvapi.rvapi_set_text(
                        'Attempting to improve phases by density modification with ACORN',
                        'status', 1, 0, 1, 1)
                if top_acornCC is not None:
                    pyrvapi.rvapi_set_text(
                        'The best solution so far has a correlation coefficient from density modification of %0.3f'
                        % top_acornCC, 'status', 2, 0, 1, 1)
                else:
                    pyrvapi.rvapi_set_text('', 'status', 2, 0, 1, 1)
                pyrvapi.rvapi_add_table('results_table', 'Phaser solutions',
                                        'tab1', 1, 0, 1, 1, 1)
                pyrvapi.rvapi_put_horz_theader('results_table',
                                               'Solution number', '', 0)
                pyrvapi.rvapi_put_horz_theader('results_table', 'Space group',
                                               '', 1)
                pyrvapi.rvapi_put_horz_theader('results_table', 'LLG',
                                               'Phaser Log Likelihood Gain', 2)
                pyrvapi.rvapi_put_horz_theader(
                    'results_table', 'TF Z-score',
                    'Phaser Translation Function Z-score', 3)
                pyrvapi.rvapi_put_horz_theader(
                    'results_table', 'CC',
                    'CC from ACORN density modification', 4)
                for solution in solutions:
                    pyrvapi.rvapi_put_table_string('results_table',
                                                   '%d' % solution['number'],
                                                   solution['number'] - 1, 0)
                    pyrvapi.rvapi_put_table_string('results_table',
                                                   solution['sg'],
                                                   solution['number'] - 1, 1)
                    pyrvapi.rvapi_put_table_string('results_table',
                                                   '%0.2f' % solution['llg'],
                                                   solution['number'] - 1, 2)
                    pyrvapi.rvapi_put_table_string('results_table',
                                                   '%0.2f' % solution['tfz'],
                                                   solution['number'] - 1, 3)
                    if solution['acornCC'] in ['Running', '-']:
                        pyrvapi.rvapi_put_table_string(
                            'results_table',
                            solution['acornCC'].replace('-', ''),
                            solution['number'] - 1, 4)
                    elif solution['acornCC'] is None:
                        pyrvapi.rvapi_put_table_string('results_table',
                                                       'Not tested',
                                                       solution['number'] - 1,
                                                       4)
                    else:
                        pyrvapi.rvapi_put_table_string(
                            'results_table', '%0.3f' % solution['acornCC'],
                            solution['number'] - 1, 4)
                output.update(items)
                pyrvapi.rvapi_flush()
            elif key == 'cc_best':
                solutions = output['solutions']
                top_llg = sorted(solutions,
                                 key=lambda r: r['llg'],
                                 reverse=True)[0]['llg']
                top_tfz = sorted(solutions,
                                 key=lambda r: r['llg'],
                                 reverse=True)[0]['tfz']
                top_acornCC = sorted([
                    solution['acornCC'] if solution['acornCC']
                    not in ['Running', '-', None] else None
                    for solution in solutions
                ],
                                     reverse=True)[0]
                pyrvapi.rvapi_set_section_state('status', False)
                pyrvapi.rvapi_add_section('results', 'Results', 'tab1', 2, 0,
                                          1, 1, True)
                pyrvapi.rvapi_add_text(
                    'Phaser found %d solutions. The top solution had Log Likelihood Gain (LLG) of %0.2f and Translation Function Z-score (TFZ) of %0.2f'
                    % (output['num_phaser_solutions'], top_llg, top_tfz),
                    'results', 0, 0, 1, 1)
                pyrvapi.rvapi_add_text(
                    'The best solution has a correlation coefficient from density modification of %0.3f'
                    % top_acornCC, 'results', 1, 0, 1, 1)
                if top_acornCC > 0.15:
                    pyrvapi.rvapi_add_text(
                        'This suggests the structure has been solved and the phases from ACORN will enable automated model building',
                        'results', 2, 0, 1, 1)
                else:
                    pyrvapi.rvapi_add_text(
                        'Sorry this does not suggest a solution', 'results', 3,
                        0, 1, 1)
                pyrvapi.rvapi_flush()
            elif key == 'best_solution_id':
                pdbout = output['name'] + '_phaser_solution.pdb'
                mtzout = output['name'] + '_acorn_phases.mtz'
                pyrvapi.rvapi_add_data(
                    'best', 'Best fragment placement and electron density',
                    pdbout, 'xyz', 'tab1', 3, 0, 1, 1, True)
                pyrvapi.rvapi_append_to_data('best', mtzout, 'hkl:map')
            else:
                output.update(items)
        return output
Пример #15
0
 def add_text(self, content):
     pyrvapi.rvapi_add_text(content, self._identifier, 0, 0, 1, 1)
Пример #16
0
    def results_section(self, results_tab_id, mrb_results, ensemble_results, section_title):
        #
        # Results Tab
        #
        if not mrb_results:
            return
        # Create unique identifier for this section by using the id
        # All ids will have this appended to avoid clashes
        uid = str(uuid.uuid4())
        section_id = section_title.replace(" ", "_") + uid
        self.results_tab_sections.append(section_id) # Add to list so we can remove if we update
        pyrvapi.rvapi_add_panel(section_id, results_tab_id, 0, 0, 1, 1)
        pyrvapi.rvapi_add_text("<h3>{0}</h3>".format(section_title), section_id, 0, 0, 1, 1)
        results_tree = "results_tree" + section_id
        pyrvapi.rvapi_add_tree_widget(results_tree, section_title, section_id, 0, 0, 1, 1)
        for r in mrb_results:
            name = r['ensemble_name']
            container_id = "sec_{0}".format(name) + uid
            pyrvapi.rvapi_add_panel(container_id, results_tree, 0, 0, 1, 1)

            header = "<h3>Results for ensemble: {0}</h3>".format(name)
            pyrvapi.rvapi_add_text(header, container_id, 0, 0, 1, 1)

            sec_table = "sec_table_{0}".format(name) + uid
            title = "Results table: {0}".format(name)
            title = "Summary"
            pyrvapi.rvapi_add_section(sec_table, title, container_id, 0, 0, 1, 1, True)
            table_id = "table_{0}".format(name) + uid
            pyrvapi.rvapi_add_table(table_id, "", sec_table, 1, 0, 1, 1, False)
            tdata = mrbump_util.ResultsSummary().results_table([r])
            self.fill_table(table_id, tdata, tooltips=self._mrbump_tooltips)

            # Ensemble
            if ensemble_results:
                epdb = self.ensemble_pdb(r, ensemble_results)
                if epdb:
                    sec_ensemble = "sec_ensemble_{0}".format(name) + uid
                    pyrvapi.rvapi_add_section(sec_ensemble, "Ensemble Search Model", container_id, 0, 0, 1, 1, False)
                    data_ensemble = "data_ensemble_{0}".format(name) + uid
                    pyrvapi.rvapi_add_data(data_ensemble,
                                           "Ensemble PDB",
                                           self.fix_path(epdb),
                                           "XYZOUT",
                                           sec_ensemble,
                                           2, 0, 1, 1, True)
            # PHASER
            if os.path.isfile(str(r['PHASER_logfile'])) or (os.path.isfile(str(r['PHASER_pdbout'])) and os.path.isfile(str(r['PHASER_mtzout']))):
                sec_phaser = "sec_phaser_{0}".format(name) + uid
                pyrvapi.rvapi_add_section(sec_phaser, "PHASER Outputs", container_id, 0, 0, 1, 1, False)
                if os.path.isfile(str(r['PHASER_pdbout'])) and os.path.isfile(str(r['PHASER_mtzout'])):
                    data_phaser = "data_phaser_out_{0}".format(name) + uid
                    pyrvapi.rvapi_add_data(data_phaser,
                                            "PHASER PDB",
                                            os.path.splitext(self.fix_path(r['PHASER_pdbout']))[0],
                                            "xyz:map",
                                            sec_phaser,
                                            2, 0, 1, 1, True)
                    pyrvapi.rvapi_append_to_data(data_phaser, self.fix_path(r['PHASER_mtzout']), "xyz:map")
                if os.path.isfile(str(r['PHASER_logfile'])):
                    pyrvapi.rvapi_add_data("data_phaser_logfile_{0}".format(name),
                                            "PHASER Logfile",
                                            self.fix_path(r['PHASER_logfile']),
                                            "text",
                                            sec_phaser,
                                            2, 0, 1, 1, True)

            # REFMAC
            if os.path.isfile(str(r['REFMAC_logfile'])) or (os.path.isfile(str(r['REFMAC_pdbout'])) and os.path.isfile(str(r['REFMAC_mtzout']))):
                sec_refmac = "sec_refmac_{0}".format(name) + uid
                pyrvapi.rvapi_add_section(sec_refmac, "REFMAC Outputs", container_id, 0, 0, 1, 1, False)
                if os.path.isfile(str(r['REFMAC_pdbout'])) and os.path.isfile(str(r['REFMAC_mtzout'])):
                    data_refmac = "data_refmac_out_{0}".format(name) + uid
                    pyrvapi.rvapi_add_data(data_refmac,
                                            "REFMAC PDB",
                                            os.path.splitext(self.fix_path(r['REFMAC_pdbout']))[0],
                                            "xyz:map",
                                            sec_refmac,
                                            2, 0, 1, 1, True)
                    pyrvapi.rvapi_append_to_data(data_refmac, self.fix_path(r['REFMAC_mtzout']), "xyz:map")
                if os.path.isfile(str(r['REFMAC_logfile'])):
                    pyrvapi.rvapi_add_data("data_refmac_logfile_{0}".format(name),
                                            "REFMAC Logfile",
                                            self.fix_path(r['REFMAC_logfile']),
                                            "text",
                                            sec_refmac,
                                            2, 0, 1, 1, True)

            # Buccaner
            if os.path.isfile(str(r['BUCC_logfile'])) or (os.path.isfile(str(r['BUCC_pdbout'])) and os.path.isfile(str(r['BUCC_mtzout']))):
                sec_bucc = "sec_bucc_{0}".format(name) + uid
                pyrvapi.rvapi_add_section(sec_bucc, "BUCCANEER Outputs", container_id, 0, 0, 1, 1, False)
                if os.path.isfile(str(r['BUCC_pdbout'])) and os.path.isfile(str(r['BUCC_mtzout'])):
                    data_bucc = "data_bucc_out_{0}".format(name) + uid
                    pyrvapi.rvapi_add_data(data_bucc,
                                            "BUCC PDB",
                                            os.path.splitext(self.fix_path(r['BUCC_pdbout']))[0],
                                            "xyz:map",
                                            sec_bucc,
                                            2, 0, 1, 1, True)
                    pyrvapi.rvapi_append_to_data(data_bucc, self.fix_path(r['BUCC_mtzout']), "xyz:map")
                if os.path.isfile(str(r['BUCC_logfile'])):
                    pyrvapi.rvapi_add_data("data_bucc_logfile_{0}".format(name),
                                            "BUCC Logfile",
                                            self.fix_path(r['BUCC_logfile']),
                                            "text",
                                            sec_bucc,
                                            2, 0, 1, 1, True)

            # Arpwarp
            if os.path.isfile(str(r['ARP_logfile'])) or (os.path.isfile(str(r['ARP_pdbout'])) and os.path.isfile(str(r['ARP_mtzout']))):
                sec_arp = "sec_arp_{0}".format(name) + uid
                pyrvapi.rvapi_add_section(sec_arp, "ARPWARP Outputs", container_id, 0, 0, 1, 1, False)
                if os.path.isfile(str(r['ARP_pdbout'])) and os.path.isfile(str(r['ARP_mtzout'])):
                    data_arp = "data_arp_out_{0}".format(name) + uid
                    pyrvapi.rvapi_add_data(data_arp,
                                            "ARP PDB",
                                            os.path.splitext(self.fix_path(r['ARP_pdbout']))[0],
                                            "xyz:map",
                                            sec_arp,
                                            2, 0, 1, 1, True)
                    pyrvapi.rvapi_append_to_data(data_arp, self.fix_path(r['ARP_mtzout']), "xyz:map")
                if os.path.isfile(str(r['ARP_logfile'])):
                    pyrvapi.rvapi_add_data("data_arp_logfile_{0}".format(name),
                                            "ARP Logfile",
                                            self.fix_path(r['ARP_logfile']),
                                            "text",
                                            sec_arp,
                                            2, 0, 1, 1, True)


            # SHELXE
            if os.path.isfile(str(r['SHELXE_logfile'])) or (os.path.isfile(str(r['SHELXE_pdbout'])) and os.path.isfile(str(r['SHELXE_mtzout']))):
                sec_shelxe = "sec_shelxe_{0}".format(name) + uid
                pyrvapi.rvapi_add_section(sec_shelxe, "SHELXE Outputs", container_id, 0, 0, 1, 1, False)
                if os.path.isfile(str(r['SHELXE_pdbout'])) and os.path.isfile(str(r['SHELXE_mtzout'])):
                    data_shelxe = "data_shelxe_out_{0}".format(name) + uid
                    pyrvapi.rvapi_add_data(data_shelxe,
                                            "SHELXE PDB",
                                            os.path.splitext(self.fix_path(r['SHELXE_pdbout']))[0],
                                            "xyz:map",
                                            sec_shelxe,
                                            2, 0, 1, 1, True)
                    pyrvapi.rvapi_append_to_data(data_shelxe, self.fix_path(r['SHELXE_mtzout']), "xyz:map")
                if os.path.isfile(str(r['SHELXE_logfile'])):
                    pyrvapi.rvapi_add_data("data_shelxe_logfile_{0}".format(name),
                                            "SHELXE Logfile",
                                            self.fix_path(r['SHELXE_logfile']),
                                            "text",
                                            sec_shelxe,
                                            2, 0, 1, 1, True)

            # Buccaner Rebuild
            if os.path.isfile(str(r['SXRBUCC_logfile'])) or (os.path.isfile(str(r['SXRBUCC_pdbout'])) and os.path.isfile(str(r['SXRBUCC_mtzout']))):
                sec_sxrbucc = "sec_sxrbucc_{0}".format(name) + uid
                pyrvapi.rvapi_add_section(sec_sxrbucc, "BUCCANEER SHELXE Trace Rebuild Outputs", container_id, 0, 0, 1, 1, False)
                if os.path.isfile(str(r['SXRBUCC_pdbout'])) and os.path.isfile(str(r['SXRBUCC_mtzout'])):
                    data_sxrbucc = "data_sxrbucc_out_{0}".format(name) + uid
                    pyrvapi.rvapi_add_data(data_sxrbucc,
                                            "SXRBUCC PDB",
                                            os.path.splitext(self.fix_path(r['SXRBUCC_pdbout']))[0],
                                            "xyz:map",
                                            sec_sxrbucc,
                                            2, 0, 1, 1, True)
                    pyrvapi.rvapi_append_to_data(data_sxrbucc, self.fix_path(r['SXRBUCC_mtzout']), "xyz:map")
                if os.path.isfile(str(r['SXRBUCC_logfile'])):
                    pyrvapi.rvapi_add_data("data_sxrbucc_logfile_{0}".format(name),
                                            "SXRBUCC Logfile",
                                            self.fix_path(r['SXRBUCC_logfile']),
                                            "text",
                                            sec_sxrbucc,
                                            2, 0, 1, 1, True)

            # Arpwarp Rebuild
            if os.path.isfile(str(r['SXRARP_logfile'])) or (os.path.isfile(str(r['SXRARP_pdbout'])) and os.path.isfile(str(r['SXRARP_mtzout']))):
                sec_sxrarp = "sec_sxrarp_{0}".format(name) + uid
                pyrvapi.rvapi_add_section(sec_sxrarp, "ARPWARP SHELXE Trace Redbuild Outputs", container_id, 0, 0, 1, 1, False)
                if os.path.isfile(str(r['SXRARP_pdbout'])) and os.path.isfile(str(r['SXRARP_mtzout'])):
                    data_sxrarp = "data_sxrarp_out_{0}".format(name) + uid
                    pyrvapi.rvapi_add_data(data_sxrarp,
                                           "SXRARP PDB",
                                           os.path.splitext(self.fix_path(r['SXRARP_pdbout']))[0],
                                           "xyz:map",
                                           sec_sxrarp,
                                           2, 0, 1, 1, True)
                    pyrvapi.rvapi_append_to_data(data_sxrarp, self.fix_path(r['SXRARP_mtzout']), "xyz:map")
                if os.path.isfile(str(r['SXRARP_logfile'])):
                    pyrvapi.rvapi_add_data("data_sxrarp_logfile_{0}".format(name),
                                           "SXRARP Logfile",
                                           self.fix_path(r['SXRARP_logfile']),
                                           "text",
                                           sec_sxrarp,
                                           2, 0, 1, 1, True)

            pyrvapi.rvapi_set_tree_node(results_tree, container_id, "{0}".format(name), "auto", "")
        return
Пример #17
0
    def display_summary_tab(self):
        """Function to create the MoRDa Database results tab

        Returns
        -------
        object
            Page containing a summary of the best results from SIMBAD
        """
        self._create_summary_tab()

        if self.lattice_df is None:
            lattice_score = 1
        else:
            try:
                lattice_score = self.lattice_df['final_r_free'][0]
            except IndexError:
                lattice_score = 1

        if self.contaminant_df is None:
            contaminant_score = 1
        else:
            try:
                contaminant_score = self.contaminant_df['final_r_free'][0]
            except IndexError:
                contaminant_score = 1

        if self.morda_db_df is None:
            morda_db_score = 1
        else:
            try:
                morda_db_score = self.morda_db_df['final_r_free'][0]
            except IndexError:
                morda_db_score = 1

        section_title = 'SIMBAD Summary'
        uid = str(uuid.uuid4())
        sec = section_title.replace(" ", "_") + uid
        tab = self.summary_tab_id

        if lattice_score == 1 and contaminant_score == 1 and morda_db_score == 1:
            msg = "No solution was found by SIMBAD"
            pyrvapi.rvapi_add_section(sec, section_title, tab, 0, 0, 1, 1, True)
            pyrvapi.rvapi_add_text(msg, sec, 2, 0, 1, 1)

        else:

            if lattice_score <= contaminant_score and lattice_score <= morda_db_score:
                pdb_code = self.lattice_df.loc[0][0]
                r_fact = self.lattice_df['final_r_fact'][0]
                r_free = self.lattice_df['final_r_free'][0]
                source = "latt"
            elif contaminant_score <= lattice_score and contaminant_score <= morda_db_score:
                pdb_code = self.contaminant_df.loc[0][0]
                r_fact = self.contaminant_df['final_r_fact'][0]
                r_free = self.contaminant_df['final_r_free'][0]
                source = "cont"
            elif morda_db_score <= lattice_score and morda_db_score <= contaminant_score:
                pdb_code = self.morda_db_df.loc[0][0]
                r_fact = self.morda_db_df['final_r_fact'][0]
                r_free = self.morda_db_df['final_r_free'][0]
                source = "morda"
            else:
                logger.debug('Unexpected result')
                return

            mr_workdir = os.path.join(self.work_dir, 'output_files', pdb_code)
            mr_log = os.path.join(mr_workdir, '{0}_mr.log'.format(pdb_code))
            ref_log = os.path.join(mr_workdir, '{0}_ref.log'.format(pdb_code))
            ref_pdb = os.path.join(mr_workdir, '{0}_refinement_output.pdb'.format(pdb_code))
            ref_map = os.path.join(mr_workdir, '{0}_refmac_2fofcwt.map'.format(pdb_code))
            ref_mtz = os.path.join(mr_workdir, '{0}_refinement_output.mtz'.format(pdb_code))
            diff_map = os.path.join(mr_workdir, '{0}_refmac_fofcwt.map'.format(pdb_code))

            msg = 'The best search model found by SIMBAD was {0}. \
                   This gave an R/Rfact of {1:.3f} and an R/Rfree of {2:.3f}. \
                   An R/Rfree lower than 0.450 is indicative of a \
                   solution. Values above this may also be indicative of a correct solution \
                   but you should examine the maps through the graphical map viewer for \
                   verification.'.format(pdb_code, r_fact, r_free)

            pyrvapi.rvapi_add_section(sec, section_title, tab, 0, 0, 1, 1, True)
            pyrvapi.rvapi_add_text(msg, sec, 2, 0, 1, 1)

            section_title = 'Best SIMBAD result Downloads'
            uid = str(uuid.uuid4())
            download_sec = section_title.replace(" ", "_") + uid
            pyrvapi.rvapi_add_section(download_sec, section_title, tab, 0, 0, 1, 1, True)

            section_title = 'Best SIMBAD result Log Files'
            uid = str(uuid.uuid4())
            logfile_sec = section_title.replace(" ", "_") + uid
            pyrvapi.rvapi_add_section(logfile_sec, section_title, tab, 0, 0, 1, 1, False)

            pdb, mtz, map_, dmap, mr_log, ref_log = list(
                self.adjust_paths_of_files([ref_pdb, ref_mtz, ref_map, diff_map, mr_log, ref_log]))
            for e in self.rvapi_meta.results:
                if e["name"] == pdb_code and e["source"] == source:
                    e["best"] = True
            self.output_result_files(download_sec, dmap, map_, mtz, pdb)
            self.output_log_files(logfile_sec, mr_log, ref_log)
Пример #18
0
    def results_section(self, results_tab_id, mrb_results, ensemble_results,
                        section_title):
        #
        # Results Tab
        #
        if not mrb_results: return

        # Create unique identifier for this section by using the id
        # All ids will have this appended to avoid clashes
        uid = str(uuid.uuid4())

        section_id = section_title.replace(" ", "_") + uid
        self.results_tab_sections.append(
            section_id)  # Add to list so we can remove if we update

        pyrvapi.rvapi_add_panel(section_id, results_tab_id, 0, 0, 1, 1)
        pyrvapi.rvapi_add_text("<h3>{0}</h3>".format(section_title),
                               section_id, 0, 0, 1, 1)

        results_tree = "results_tree" + section_id
        pyrvapi.rvapi_add_tree_widget(results_tree, section_title, section_id,
                                      0, 0, 1, 1)

        for r in mrb_results:
            name = r['ensemble_name']
            # container_id="sec_{0}".format(name)
            # pyrvapi.rvapi_add_section(container_id,"Results for: {0}".format(name),results_tree,0,0,1,1,True)
            container_id = "sec_{0}".format(name) + uid
            pyrvapi.rvapi_add_panel(container_id, results_tree, 0, 0, 1, 1)

            header = "<h3>Results for ensemble: {0}</h3>".format(name)
            pyrvapi.rvapi_add_text(header, container_id, 0, 0, 1, 1)

            sec_table = "sec_table_{0}".format(name) + uid
            title = "Results table: {0}".format(name)
            title = "Summary"
            pyrvapi.rvapi_add_section(sec_table, title, container_id, 0, 0, 1,
                                      1, True)
            table_id = "table_{0}".format(name) + uid
            pyrvapi.rvapi_add_table(table_id, "", sec_table, 1, 0, 1, 1, False)
            tdata = mrbump_util.ResultsSummary().results_table([r])
            self.fill_table(table_id, tdata, tooltips=self._mrbump_tooltips)

            # Ensemble
            if ensemble_results:
                epdb = self.ensemble_pdb(r, ensemble_results)
                if epdb:
                    sec_ensemble = "sec_ensemble_{0}".format(name) + uid
                    pyrvapi.rvapi_add_section(sec_ensemble,
                                              "Ensemble Search Model",
                                              container_id, 0, 0, 1, 1, False)
                    data_ensemble = "data_ensemble_{0}".format(name) + uid
                    pyrvapi.rvapi_add_data(data_ensemble, "Ensemble PDB",
                                           self.fix_path(epdb), "XYZOUT",
                                           sec_ensemble, 2, 0, 1, 1, True)
            # PHASER
            if os.path.isfile(str(r['PHASER_logfile'])) or (
                    os.path.isfile(str(r['PHASER_pdbout']))
                    and os.path.isfile(str(r['PHASER_mtzout']))):
                sec_phaser = "sec_phaser_{0}".format(name) + uid
                pyrvapi.rvapi_add_section(sec_phaser, "PHASER Outputs",
                                          container_id, 0, 0, 1, 1, False)
                if os.path.isfile(str(r['PHASER_pdbout'])) and os.path.isfile(
                        str(r['PHASER_mtzout'])):
                    data_phaser = "data_phaser_out_{0}".format(name) + uid
                    pyrvapi.rvapi_add_data(
                        data_phaser, "PHASER PDB",
                        os.path.splitext(self.fix_path(r['PHASER_pdbout']))[0],
                        "xyz:map", sec_phaser, 2, 0, 1, 1, True)
                    pyrvapi.rvapi_append_to_data(
                        data_phaser, self.fix_path(r['PHASER_mtzout']),
                        "xyz:map")
                if os.path.isfile(str(r['PHASER_logfile'])):
                    pyrvapi.rvapi_add_data(
                        "data_phaser_logfile_{0}".format(name),
                        "PHASER Logfile", self.fix_path(r['PHASER_logfile']),
                        "text", sec_phaser, 2, 0, 1, 1, True)

            # REFMAC
            if os.path.isfile(str(r['REFMAC_logfile'])) or (
                    os.path.isfile(str(r['REFMAC_pdbout']))
                    and os.path.isfile(str(r['REFMAC_mtzout']))):
                sec_refmac = "sec_refmac_{0}".format(name) + uid
                pyrvapi.rvapi_add_section(sec_refmac, "REFMAC Outputs",
                                          container_id, 0, 0, 1, 1, False)
                if os.path.isfile(str(r['REFMAC_pdbout'])) and os.path.isfile(
                        str(r['REFMAC_mtzout'])):
                    data_refmac = "data_refmac_out_{0}".format(name) + uid
                    pyrvapi.rvapi_add_data(
                        data_refmac, "REFMAC PDB",
                        os.path.splitext(self.fix_path(r['REFMAC_pdbout']))[0],
                        "xyz:map", sec_refmac, 2, 0, 1, 1, True)
                    pyrvapi.rvapi_append_to_data(
                        data_refmac, self.fix_path(r['REFMAC_mtzout']),
                        "xyz:map")
                if os.path.isfile(str(r['REFMAC_logfile'])):
                    pyrvapi.rvapi_add_data(
                        "data_refmac_logfile_{0}".format(name),
                        "REFMAC Logfile", self.fix_path(r['REFMAC_logfile']),
                        "text", sec_refmac, 2, 0, 1, 1, True)

            # Buccaner
            if os.path.isfile(str(r['BUCC_logfile'])) or (
                    os.path.isfile(str(r['BUCC_pdbout']))
                    and os.path.isfile(str(r['BUCC_mtzout']))):
                sec_bucc = "sec_bucc_{0}".format(name) + uid
                pyrvapi.rvapi_add_section(sec_bucc, "BUCCANEER Outputs",
                                          container_id, 0, 0, 1, 1, False)
                if os.path.isfile(str(r['BUCC_pdbout'])) and os.path.isfile(
                        str(r['BUCC_mtzout'])):
                    data_bucc = "data_bucc_out_{0}".format(name) + uid
                    pyrvapi.rvapi_add_data(
                        data_bucc, "BUCC PDB",
                        os.path.splitext(self.fix_path(r['BUCC_pdbout']))[0],
                        "xyz:map", sec_bucc, 2, 0, 1, 1, True)
                    pyrvapi.rvapi_append_to_data(
                        data_bucc, self.fix_path(r['BUCC_mtzout']), "xyz:map")
                if os.path.isfile(str(r['BUCC_logfile'])):
                    pyrvapi.rvapi_add_data(
                        "data_bucc_logfile_{0}".format(name), "BUCC Logfile",
                        self.fix_path(r['BUCC_logfile']), "text", sec_bucc, 2,
                        0, 1, 1, True)

            # Arpwarp
            if os.path.isfile(str(r['ARP_logfile'])) or (
                    os.path.isfile(str(r['ARP_pdbout']))
                    and os.path.isfile(str(r['ARP_mtzout']))):
                sec_arp = "sec_arp_{0}".format(name) + uid
                pyrvapi.rvapi_add_section(sec_arp, "ARPWARP Outputs",
                                          container_id, 0, 0, 1, 1, False)
                if os.path.isfile(str(r['ARP_pdbout'])) and os.path.isfile(
                        str(r['ARP_mtzout'])):
                    data_arp = "data_arp_out_{0}".format(name) + uid
                    pyrvapi.rvapi_add_data(
                        data_arp, "ARP PDB",
                        os.path.splitext(self.fix_path(r['ARP_pdbout']))[0],
                        "xyz:map", sec_arp, 2, 0, 1, 1, True)
                    pyrvapi.rvapi_append_to_data(
                        data_arp, self.fix_path(r['ARP_mtzout']), "xyz:map")
                if os.path.isfile(str(r['ARP_logfile'])):
                    pyrvapi.rvapi_add_data("data_arp_logfile_{0}".format(name),
                                           "ARP Logfile",
                                           self.fix_path(r['ARP_logfile']),
                                           "text", sec_arp, 2, 0, 1, 1, True)

            # SHELXE
            if os.path.isfile(str(r['SHELXE_logfile'])) or (
                    os.path.isfile(str(r['SHELXE_pdbout']))
                    and os.path.isfile(str(r['SHELXE_mtzout']))):
                sec_shelxe = "sec_shelxe_{0}".format(name) + uid
                pyrvapi.rvapi_add_section(sec_shelxe, "SHELXE Outputs",
                                          container_id, 0, 0, 1, 1, False)
                if os.path.isfile(str(r['SHELXE_pdbout'])) and os.path.isfile(
                        str(r['SHELXE_mtzout'])):
                    data_shelxe = "data_shelxe_out_{0}".format(name) + uid
                    pyrvapi.rvapi_add_data(
                        data_shelxe, "SHELXE PDB",
                        os.path.splitext(self.fix_path(r['SHELXE_pdbout']))[0],
                        "xyz:map", sec_shelxe, 2, 0, 1, 1, True)
                    pyrvapi.rvapi_append_to_data(
                        data_shelxe, self.fix_path(r['SHELXE_mtzout']),
                        "xyz:map")
                if os.path.isfile(str(r['SHELXE_logfile'])):
                    pyrvapi.rvapi_add_data(
                        "data_shelxe_logfile_{0}".format(name),
                        "SHELXE Logfile", self.fix_path(r['SHELXE_logfile']),
                        "text", sec_shelxe, 2, 0, 1, 1, True)

            # Buccaner Rebuild
            if os.path.isfile(str(r['SXRBUCC_logfile'])) or (
                    os.path.isfile(str(r['SXRBUCC_pdbout']))
                    and os.path.isfile(str(r['SXRBUCC_mtzout']))):
                sec_sxrbucc = "sec_sxrbucc_{0}".format(name) + uid
                pyrvapi.rvapi_add_section(
                    sec_sxrbucc, "BUCCANEER SHELXE Trace Rebuild Outputs",
                    container_id, 0, 0, 1, 1, False)
                if os.path.isfile(str(r['SXRBUCC_pdbout'])) and os.path.isfile(
                        str(r['SXRBUCC_mtzout'])):
                    data_sxrbucc = "data_sxrbucc_out_{0}".format(name) + uid
                    pyrvapi.rvapi_add_data(
                        data_sxrbucc, "SXRBUCC PDB",
                        os.path.splitext(self.fix_path(
                            r['SXRBUCC_pdbout']))[0], "xyz:map", sec_sxrbucc,
                        2, 0, 1, 1, True)
                    pyrvapi.rvapi_append_to_data(
                        data_sxrbucc, self.fix_path(r['SXRBUCC_mtzout']),
                        "xyz:map")
                if os.path.isfile(str(r['SXRBUCC_logfile'])):
                    pyrvapi.rvapi_add_data(
                        "data_sxrbucc_logfile_{0}".format(name),
                        "SXRBUCC Logfile", self.fix_path(r['SXRBUCC_logfile']),
                        "text", sec_sxrbucc, 2, 0, 1, 1, True)

            # Arpwarp Rebuild
            if os.path.isfile(str(r['SXRARP_logfile'])) or (
                    os.path.isfile(str(r['SXRARP_pdbout']))
                    and os.path.isfile(str(r['SXRARP_mtzout']))):
                sec_sxrarp = "sec_sxrarp_{0}".format(name) + uid
                pyrvapi.rvapi_add_section(
                    sec_sxrarp, "ARPWARP SHELXE Trace Redbuild Outputs",
                    container_id, 0, 0, 1, 1, False)
                if os.path.isfile(str(r['SXRARP_pdbout'])) and os.path.isfile(
                        str(r['SXRARP_mtzout'])):
                    data_sxrarp = "data_sxrarp_out_{0}".format(name) + uid
                    pyrvapi.rvapi_add_data(
                        data_sxrarp, "SXRARP PDB",
                        os.path.splitext(self.fix_path(r['SXRARP_pdbout']))[0],
                        "xyz:map", sec_sxrarp, 2, 0, 1, 1, True)
                    pyrvapi.rvapi_append_to_data(
                        data_sxrarp, self.fix_path(r['SXRARP_mtzout']),
                        "xyz:map")
                if os.path.isfile(str(r['SXRARP_logfile'])):
                    pyrvapi.rvapi_add_data(
                        "data_sxrarp_logfile_{0}".format(name),
                        "SXRARP Logfile", self.fix_path(r['SXRARP_logfile']),
                        "text", sec_sxrarp, 2, 0, 1, 1, True)

            pyrvapi.rvapi_set_tree_node(results_tree, container_id,
                                        "{0}".format(name), "auto", "")
        return
Пример #19
0
    def display_summary_tab(self):
        """Function to create the MoRDa Database results tab

        Returns
        -------
        object
            Page containing a summary of the best results from SIMBAD
        """
        self._create_summary_tab()

        if self.lattice_df is None:
            lattice_score = 1
        else:
            try:
                lattice_score = self.lattice_df['final_r_free'][0]
            except IndexError:
                lattice_score = 1

        if self.contaminant_df is None:
            contaminant_score = 1
        else:
            try:
                contaminant_score = self.contaminant_df['final_r_free'][0]
            except IndexError:
                contaminant_score = 1

        if self.morda_db_df is None:
            morda_db_score = 1
        else:
            try:
                morda_db_score = self.morda_db_df['final_r_free'][0]
            except IndexError:
                morda_db_score = 1

        section_title = 'SIMBAD Summary'
        uid = str(uuid.uuid4())
        sec = section_title.replace(" ", "_") + uid
        tab = self.summary_tab_id

        if lattice_score == 1 and contaminant_score == 1 and morda_db_score == 1:
            msg = "No solution was found by SIMBAD"
            pyrvapi.rvapi_add_section(sec, section_title, tab, 0, 0, 1, 1, True)
            pyrvapi.rvapi_add_text(msg, sec, 2, 0, 1, 1)

        else:

            if lattice_score <= contaminant_score and lattice_score <= morda_db_score:
                pdb_code = self.lattice_df.loc[0][0]
                r_fact = self.lattice_df['final_r_fact'][0]
                r_free = self.lattice_df['final_r_free'][0]
                source = "latt"
            elif contaminant_score <= lattice_score and contaminant_score <= morda_db_score:
                pdb_code = self.contaminant_df.loc[0][0]
                r_fact = self.contaminant_df['final_r_fact'][0]
                r_free = self.contaminant_df['final_r_free'][0]
                source = "cont"
            elif morda_db_score <= lattice_score and morda_db_score <= contaminant_score:
                pdb_code = self.morda_db_df.loc[0][0]
                r_fact = self.morda_db_df['final_r_fact'][0]
                r_free = self.morda_db_df['final_r_free'][0]
                source = "morda"
            else:
                logger.debug('Unexpected result')
                return

            mr_workdir = os.path.join(self.work_dir, 'output_files', pdb_code)
            mr_log = os.path.join(mr_workdir, '{0}_mr.log'.format(pdb_code))
            ref_log = os.path.join(mr_workdir, '{0}_ref.log'.format(pdb_code))
            ref_pdb = os.path.join(mr_workdir, '{0}_refinement_output.pdb'.format(pdb_code))
            ref_map = os.path.join(mr_workdir, '{0}_refmac_2fofcwt.map'.format(pdb_code))
            ref_mtz = os.path.join(mr_workdir, '{0}_refinement_output.mtz'.format(pdb_code))
            diff_map = os.path.join(mr_workdir, '{0}_refmac_fofcwt.map'.format(pdb_code))

            msg = 'The best search model found by SIMBAD was {0}. \
                   This gave an R/Rfact of {1:.3f} and an R/Rfree of {2:.3f}. \
                   An R/Rfree lower than 0.450 is indicative of a \
                   solution. Values above this may also be indicative of a correct solution \
                   but you should examine the maps through the graphical map viewer for \
                   verification'.format(pdb_code, r_fact, r_free)

            pyrvapi.rvapi_add_section(sec, section_title, tab, 0, 0, 1, 1, True)
            pyrvapi.rvapi_add_text(msg, sec, 2, 0, 1, 1)

            section_title = 'Best SIMBAD result Downloads'
            uid = str(uuid.uuid4())
            download_sec = section_title.replace(" ", "_") + uid
            pyrvapi.rvapi_add_section(download_sec, section_title, tab, 0, 0, 1, 1, True)

            section_title = 'Best SIMBAD result Log Files'
            uid = str(uuid.uuid4())
            logfile_sec = section_title.replace(" ", "_") + uid
            pyrvapi.rvapi_add_section(logfile_sec, section_title, tab, 0, 0, 1, 1, False)

            pdb, mtz, map_, dmap, mr_log, ref_log = list(
                self.adjust_paths_of_files([ref_pdb, ref_mtz, ref_map, diff_map, mr_log, ref_log]))
            for e in self.rvapi_meta.results:
                if e["name"] == pdb_code and e["source"] == source:
                    e["best"] = True
            self.output_result_files(download_sec, dmap, map_, mtz, pdb)
            self.output_log_files(logfile_sec, mr_log, ref_log)