示例#1
0
 def create_log_tab(self, ample_dict):
     if not self.own_log_tab or self.log_tab_id:
         return
     logfile = ample_dict['ample_log']
     if not os.path.isfile(logfile):
         return False
     self.log_tab_id = "log_tab"
     logurl = self.fix_path(logfile)
     pyrvapi.rvapi_add_tab(self.log_tab_id, "Log file", True)
     pyrvapi.rvapi_append_content(logurl, True, self.log_tab_id)
     return self.log_tab_id
示例#2
0
 def create_log_tab(self, ample_dict):
     if not self.own_log_tab or self.log_tab_id:
         return
     logfile = ample_dict['ample_log']
     if not os.path.isfile(logfile):
         return False
     self.log_tab_id = "log_tab"
     logurl = self.fix_path(logfile)
     pyrvapi.rvapi_add_tab(self.log_tab_id, "Log file", True)
     pyrvapi.rvapi_append_content(logurl, True, self.log_tab_id)
     return self.log_tab_id
示例#3
0
    def create_log_tab(self, ample_dict):
        if not self.do_log_tab or self.log_tab_id: return
        logfile = ample_dict['ample_log']
        if not os.path.isfile(logfile): return False

        self.log_tab_id = "log_tab"
        logurl = self.fix_path(logfile)
        pyrvapi.rvapi_add_tab(self.log_tab_id, "Log file",
                              True)  # Last arg is "open" - i.e. show or hide

        # Add watched (updatable) content to the log tab.
        pyrvapi.rvapi_append_content(logurl, True, self.log_tab_id)
        # pyrvapi.rvapi_flush()
        return self.log_tab_id
示例#4
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
示例#5
0
文件: tab.py 项目: fsimkovic/rvapi
 def __init__(self, parent, title, opened=False):
     self._identifier = self.unique_id("tab")
     super(Tab, self).__init__(parent)
     self._title = title
     self._opened = opened
     pyrvapi.rvapi_add_tab(self._identifier, self._title, self._opened)
示例#6
0
 def addTab(self, tabId, tabName, opened):
     pyrvapi.rvapi_add_tab(tabId, tabName, opened)
     return self.setOutputPage([tabId, 0])
示例#7
0
 def _add_tab_to_pyrvapi(self, id, title, opened):
     if self.jscofe_mode:
         self._insert_tab_to_pyrvapi(id, title, self.rhs_tab_id, opened)
     else:
         pyrvapi.rvapi_add_tab(id, title, opened)
示例#8
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
示例#9
0
 def _add_tab_to_pyrvapi(self, id, title, opened):
     if self.jscofe_mode:
         self._insert_tab_to_pyrvapi(id, title, self.rhs_tab_id, opened)
     else:
         pyrvapi.rvapi_add_tab(id, title, opened)
示例#10
0
    def importData(self):

        self.putWaitMessageLF("<b>1. Input Data Import</b>")
        #self.rvrow -= 1

        # -------------------------------------------------------------------
        # import uploaded data
        # make import tab and redirect output to it
        pyrvapi.rvapi_add_tab(self.import_page_id(), "1. Input Data Import",
                              False)
        self.setReportWidget(self.import_page_id())

        fstdout = self.file_stdout
        fstderr = self.file_stderr
        self.file_stdout = open(self.import_stdout_path(), 'w')
        self.file_stderr = open(self.import_stderr_path(), 'w')

        # create tabs for import standard outputs

        if self.navTreeId:
            pyrvapi.rvapi_set_tab_proxy(self.navTreeId, self.import_page_id())
        pyrvapi.rvapi_add_tab(self.import_log_page_id(), "Log file", False)
        pyrvapi.rvapi_append_content(
            os.path.join("..",
                         self.import_stdout_path() + '?capsize'), True,
            self.import_log_page_id())
        pyrvapi.rvapi_add_tab(self.import_err_page_id(), "Errors", False)
        pyrvapi.rvapi_append_content(
            os.path.join("..",
                         self.import_stderr_path() + '?capsize'), True,
            self.import_err_page_id())

        self.putTitle("CCP4go Automated Structure Solver: Data Import")
        super(CCP4go, self).import_all()

        # redirect everything back to report page and original standard streams
        self.file_stdout.close()
        self.file_stderr.close()
        self.file_stdout = fstdout
        self.file_stderr = fstderr
        self.resetReportPage()
        if self.navTreeId:
            pyrvapi.rvapi_set_tab_proxy(self.navTreeId, "")

        # -------------------------------------------------------------------
        # fetch data for CCP4go pipeline

        self.unm = None  # unmerged dataset
        self.hkl = None  # selected merged dataset
        self.seq = None  # list of sequence objects
        self.xyz = None  # coordinates (model/apo)
        self.hkl_alt = {}  # alternative-space group merged datasets

        if "DataUnmerged" in self.outputDataBox.data:
            self.unm = self.outputDataBox.data["DataUnmerged"][0]

        if "DataHKL" in self.outputDataBox.data:
            maxres = 10000.0
            for i in range(len(self.outputDataBox.data["DataHKL"])):
                res = self.outputDataBox.data["DataHKL"][i].getHighResolution(
                    True)
                if res < maxres:
                    maxres = res
                    self.hkl = self.outputDataBox.data["DataHKL"][i]

        if "DataSequence" in self.outputDataBox.data:
            self.seq = self.outputDataBox.data["DataSequence"]

        if "DataXYZ" in self.outputDataBox.data:
            self.xyz = self.outputDataBox.data["DataXYZ"][0]

        # -------------------------------------------------------------------
        # make data summary table

        panelId = "summary_section"
        pyrvapi.rvapi_set_text("", self.report_page_id(), self.rvrow, 0, 1, 1)
        self.putSection(panelId, "<b>1. Input summary</b>")

        tableId = "ccp4go_summary_table"
        #self.putTable ( tableId,"<font style='font-style:normal;font-size:125%;'>" +
        #                        "1. Input Data</font>",self.report_page_id(),
        #                        self.rvrow,0 )
        #self.rvrow += 1
        self.putTable(tableId, "Input data", panelId, 0, 0)
        self.setTableHorzHeaders(
            tableId, ["Assigned Name", "View"],
            ["Name of the assocuated data object", "Data view and export"])

        def addDataLine(name, tooltip, object, nrow):
            if object:
                self.putTableLine(tableId, name, tooltip, object.dname,
                                  nrow[0])
                self.putInspectButton(object, "View", tableId, nrow[0] + 1, 2)
                nrow[0] += 1
            return

        nrow = [0]
        addDataLine("Unmerged Reflections", "Reflection data", self.unm, nrow)
        addDataLine("Merged Reflections", "Reflection data", self.hkl, nrow)
        if self.seq:
            if len(self.seq) < 2:
                addDataLine("Sequence", "Sequence data", self.seq[0], nrow)
            else:
                for i in range(len(self.seq)):
                    addDataLine("Sequence #" + str(i + 1), "Sequence data",
                                self.seq[i], nrow)
        addDataLine("Structure", "Homologue structure", self.xyz, nrow)

        if self.task.ha_type:
            self.putTableLine(tableId, "Anomalous scatterers",
                              "Chemical type of anomalous scatterers",
                              self.task.ha_type, nrow[0])
            nrow[0] += 1

        for i in range(len(self.task.ligands)):
            ligand = self.task.ligands[i]
            if ligand.source != "none":
                dline = "[" + ligand.code + "] "
                if ligand.source == "smiles":
                    m = 0
                    for j in range(len(ligand.smiles)):
                        if m > 40:
                            dline += "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
                            m = 0
                        dline += ligand.smiles[j]
                        m += 1
                self.putTableLine(tableId, "Ligand #" + str(i + 1),
                                  "Ligand description", dline, nrow[0])
                nrow[0] += 1

        return