Exemple #1
0
    def parse_resultsline(self, line):
        """ Parses result lines
        """
        splitted = [token.strip() for token in line.split(self._delimiter)]
        if len(filter(lambda x: len(x), splitted)) == 0:
            return 0

        # AR id
        if splitted[0] == 'Laboratory number':
            self._ar_id = splitted[2]
            return 0

        if splitted[0] == 'Molecule':
            self._kw = format_keyword(splitted[2])
            return 0

        if splitted[0] == 'Retention time in the molecule':
            if self._retentiontime:
                self._retentiontimeref = splitted[1]
            else:
                self._retentiontime = splitted[1]
            return 0

        if splitted[0].startswith('ion'):
            ion_number = splitted[0].split(' ')[1]
            mz_values = splitted[1].split('---')
            self._ions.append({
                'Ion{}mzmax'.format(ion_number): mz_values[0],
                'Ion{}mzmin'.format(ion_number): mz_values[1],
                'Ion{}Area'.format(ion_number): splitted[2],
                'Ion{}AreaRef'.format(ion_number): splitted[3],
                'Ion{}SigNseRat'.format(ion_number): splitted[4],
            })

        if splitted[0] == 'PARAMETERS TO BE CONSIDERED FOR THE CALCULATION':
            # No result field
            record = {
                'DefaultResult': None,
                'Remarks': '',
                'DateTime': str(DateTime())[:16]
            }

            # Interim values
            column_name = 'RetentionTime'
            record[column_name] = self.get_result(column_name,
                                                  self._retentiontime, 0)

            column_name = 'RetentionTimeRef'
            record[column_name] = self.get_result(column_name,
                                                  self._retentiontimeref, 0)

            for ion in self._ions:
                for interim_key in ion.keys():
                    record[interim_key] = self.get_result(
                        interim_key, ion[interim_key], 0)

            # Append record
            self._addRawResult(self._ar_id, {self._kw: record})

        return 0
Exemple #2
0
    def parse(self):
        """ parse the data
        """
        tree = ET.parse(self.getInputFile())
        root = tree.getroot()
        # Building Assay dictionary to query names by id from test results line
        for as_ref in root.find("Assays").findall("AssayRef"):
            self._assays[as_ref.get("KEY_AssayRef")] = as_ref.get("ID")

        # Building Instruments dictionary to get Serial number by id
        for ins in root.find("Instruments").findall("Instrument"):
            self._instruments[ins.get("KEY_InstrumentData")] = \
                ins.get("SerialNumber")

        for t_req in root.iter("TestRequest"):
            t_res = t_req.find("TestResult")
            if len(t_res) == 0 or not t_res.get("Valid", "false") == "true":
                continue
            res_id = t_req.get("SampleID")
            test_name = self._assays.get(t_req.get("KEY_AssayRef"))
            test_name = format_keyword(test_name)
            result = t_res.get("Value")
            if not result:
                continue
            result = result.split(" cps/ml")[0]
            detected = t_res.get("Detected")

            # SOME ADDITIONAL DATA
            # Getting instrument serial number from 'Run' element which is
            # parent of 'TestRequest' elements
            ins_serial = t_req.getParent().get("KEY_InstrumentData")

            # Matrix is important for calculation.
            matrix = t_req.get("Matrix")
            # For now, using EasyQDirector as keyword, but this is not the
            # right way. test_name must be used.
            values = {
                'EasyQDirector': {
                    "DefaultResult": "Result",
                    "Result": result,
                    "Detected": detected,
                    "Matrix": matrix,
                    "Instrument": ins_serial
                }
            }
            self._addRawResult(res_id, values)
Exemple #3
0
    def parse_headerline(self, line):
        """ Parses header lines

            Keywords example:
            Keyword1, Keyword2, Keyword3, ..., end
        """
        if self._end_header:
            # Header already processed
            return 0

        splitted = [token.strip() for token in line.split(self._delimiter)]
        if splitted[0].startswith('Sample'):
            self._kw = splitted[7].split(' ')[0]
            self._kw = format_keyword(self._kw)
            self._end_header = True

        return 0
Exemple #4
0
    def parse_resultsline(self, line):
        """ Parses result lines
        """
        splitted = [token.strip() for token in line.split(self._delimiter)]
        if len(filter(lambda x: len(x), splitted)) == 0:
            return 0

        # Header
        if splitted[0] == 'Comp #':
            self._header = splitted
            return 0

        # No default
        record = {
            'DefaultResult': None,
            'Remarks': ''
        }
        # 4 Interim fields
        value_column = 'Amount'
        result = splitted[4]
        result = self.get_result(value_column, result, 0)
        record[value_column] = result

        value_column = 'ReturnTime'
        result = splitted[2]
        result = self.get_result(value_column, result, 0)
        record[value_column] = result

        value_column = 'Area'
        result = splitted[3]
        result = self.get_result(value_column, result, 0)
        record[value_column] = result

        value_column = 'QVal'
        result = splitted[6]
        result = self.get_result(value_column, result, 0)
        record[value_column] = result

        # assign record to kw dict
        kw = splitted[1]
        kw = format_keyword(kw)
        self._addRawResult(self._ar_id, {kw: record})

        return 0
Exemple #5
0
    def parse_resultsline(self, line):
        """ Parses result lines
        """
        splitted = [token.strip() for token in line.split(self._delimiter)]
        if len(filter(lambda x: len(x), splitted)) == 0:
            return 0

        # Header
        if splitted[0].startswith('Score'):
            self._header = splitted
            return 0

        ar_id = splitted[104]
        kw = format_keyword(splitted[18])
        analysis_date = str(DateTime())[:16]

        # Result field
        record = {
            'DefaultResult': None,
            'Remarks': '',
            'DateTime': analysis_date
        }

        # Interim values can get added to record here
        interims = [
            ('Label', 22),
            ('Area', 48),
            ('File', 54),
            ('End', 55),
            ('mz', 67),
            ('mzProd', 68),
            ('ReturnTime', 69),
            ('Start', 71),
            ('Width', 72),
            ('AcqMethod', 110),
        ]
        for column_name, column_number in interims:
            result = splitted[column_number]
            record[column_name] = self.get_result(column_name, result, 0)

        # Append record
        self._addRawResult(ar_id, {kw: record})

        return 0