Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #4
0
    def create_log_tab(self, logfile):
        """Function to create log tab

        Parameters
        ----------
        logfile : str
            Path to the log file

        Returns
        -------
        str
            Updating page containing log

        """
        if self.jscofe_mode or self.log_tab_id:
            return
        if not os.path.isfile(logfile):
            return False

        self.log_tab_id = self.tab_prefix + "log_tab"
        logurl = self.fix_path(logfile)
        self._add_tab_to_pyrvapi(self.log_tab_id, "Log file", True)
        pyrvapi.rvapi_append_content(logurl, True, self.log_tab_id)
        return self.log_tab_id
Beispiel #5
0
    def create_log_tab(self, logfile):
        """Function to create log tab

        Parameters
        ----------
        logfile : str
            Path to the log file

        Returns
        -------
        str
            Updating page containing log

        """
        if self.jscofe_mode or self.log_tab_id:
            return
        if not os.path.isfile(logfile):
            return False

        self.log_tab_id = self.tab_prefix + "log_tab"
        logurl = self.fix_path(logfile)
        self._add_tab_to_pyrvapi(self.log_tab_id, "Log file", True)
        pyrvapi.rvapi_append_content(logurl, True, self.log_tab_id)
        return self.log_tab_id
Beispiel #6
0
 def add_content(self, content):
     pyrvapi.rvapi_append_content(content, True, self._identifier)
Beispiel #7
0
    def start_branch(self,
                     branch_title,
                     page_title,
                     subdir,
                     branch_id,
                     headTabId=None):

        tree_header_id = headTabId
        if not headTabId:
            tree_header_id = subdir + "_header_id"
        logtab_id = subdir + "_logtab_id"
        errtab_id = subdir + "_errtab_id"

        # make work directory
        sdir = os.path.join(self.workdir, subdir)
        if not os.path.isdir(sdir):
            os.mkdir(sdir)
        sodir = os.path.join(self.workdir, self.outputdir, subdir)
        if not os.path.isdir(sodir):
            os.mkdir(sodir)

        self.mk_std_streams(subdir)

        self.stage_no += 1
        if self.layout == 0:
            pyrvapi.rvapi_set_tab_proxy(self.navTreeId, branch_id)

        # cursor0 remembers point og output in parent page
        cursor0 = self.addTab(tree_header_id,
                              str(self.stage_no) + ". " + branch_title, False)
        if page_title:
            if self.jobId:
                title = "[" + self.jobId.zfill(4) + "] " + page_title
            else:
                title = str(self.stage_no) + ". " + page_title
            self.putMessage("<h2>" + title + "</h2>")
            #self.putMessage ( "<h3>" + title + ": <i>in progress</i></h3>" )

        if self.layout == 0:
            pyrvapi.rvapi_set_tab_proxy(self.navTreeId, tree_header_id)

        # cursor1 is set to the begining of new tab page
        cursor1 = self.addTab(logtab_id, "Log file", True)
        self.addTab(errtab_id, "Errors", True)
        pyrvapi.rvapi_append_content(
            os.path.join("..", subdir,
                         self.file_stdout_path() + '?capsize'), True,
            logtab_id)
        pyrvapi.rvapi_append_content(
            os.path.join("..", subdir, self.file_stderr_path()), True,
            errtab_id)

        # back to the beginning of head tab
        self.setOutputPage(cursor1)

        return {
            "title": title,
            "pageId": tree_header_id,
            "logTabId": logtab_id,
            "cursor0": cursor0,
            "cursor1": cursor1
        }
Beispiel #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
Beispiel #9
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