| @@ 15-63 (lines=49) @@ | ||
| 12 | AnalysisResultsImporter, InstrumentCSVResultsFileParser |
|
| 13 | ||
| 14 | ||
| 15 | class TaqMan96DNA212BSCSVParser(InstrumentCSVResultsFileParser): |
|
| 16 | def __init__(self, csv): |
|
| 17 | InstrumentCSVResultsFileParser.__init__(self, csv) |
|
| 18 | self._columns = [] # The different columns names |
|
| 19 | self._values = {} # The analysis services from the same resid |
|
| 20 | self._resid = '' # A stored resid |
|
| 21 | self._rownum = None |
|
| 22 | self._end_header = False |
|
| 23 | ||
| 24 | def _parseline(self, line): |
|
| 25 | sline = line.split(',') |
|
| 26 | if len(sline) > 0 and not self._end_header: |
|
| 27 | self._columns = sline |
|
| 28 | self._end_header = True |
|
| 29 | return 0 |
|
| 30 | elif sline > 0 and self._end_header: |
|
| 31 | self.parse_data_line(sline) |
|
| 32 | else: |
|
| 33 | self.err("Unexpected data format", numline=self._numline) |
|
| 34 | return -1 |
|
| 35 | ||
| 36 | def parse_data_line(self, sline): |
|
| 37 | """ |
|
| 38 | Parses the data line and builds the dictionary. |
|
| 39 | :param sline: a split data line to parse |
|
| 40 | :returns: the number of rows to jump and parse the next data line or return the code error -1 |
|
| 41 | """ |
|
| 42 | # if there are less values founded than headers, it's an error |
|
| 43 | if len(sline) != len(self._columns): |
|
| 44 | self.err("One data line has the wrong number of items") |
|
| 45 | return -1 |
|
| 46 | #print self._columns |
|
| 47 | rawdict = {} |
|
| 48 | for idx, result in enumerate(sline): |
|
| 49 | rawdict[self._columns[idx]] = result |
|
| 50 | # Getting key values |
|
| 51 | resid = rawdict['Sample ID'] |
|
| 52 | del rawdict['Sample ID'] |
|
| 53 | testname = rawdict['Test'] |
|
| 54 | del rawdict['Test'] |
|
| 55 | ||
| 56 | # Building the new dict |
|
| 57 | rawdict['DefaultResult'] = 'Result' |
|
| 58 | rawdict['Remarks'] = rawdict['Comment'] |
|
| 59 | del rawdict['Comment'] |
|
| 60 | print rawdict |
|
| 61 | ||
| 62 | self._addRawResult(resid, {testname: rawdict}, False) |
|
| 63 | return 0 |
|
| 64 | ||
| 65 | ||
| 66 | class TaqMan96DNA212BSImporter(AnalysisResultsImporter): |
|
| @@ 15-63 (lines=49) @@ | ||
| 12 | AnalysisResultsImporter, InstrumentCSVResultsFileParser |
|
| 13 | ||
| 14 | ||
| 15 | class FacsCaliburParser(InstrumentCSVResultsFileParser): |
|
| 16 | def __init__(self, csv): |
|
| 17 | InstrumentCSVResultsFileParser.__init__(self, csv) |
|
| 18 | self._columns = [] # The different columns names |
|
| 19 | self._values = {} # The analysis services from the same resid |
|
| 20 | self._resid = '' # A stored resid |
|
| 21 | self._rownum = None |
|
| 22 | self._end_header = False |
|
| 23 | ||
| 24 | def _parseline(self, line): |
|
| 25 | sline = line.split(',') |
|
| 26 | if len(sline) > 0 and not self._end_header: |
|
| 27 | self._columns = sline |
|
| 28 | self._end_header = True |
|
| 29 | return 0 |
|
| 30 | elif sline > 0 and self._end_header: |
|
| 31 | self.parse_data_line(sline) |
|
| 32 | else: |
|
| 33 | self.err("Unexpected data format", numline=self._numline) |
|
| 34 | return -1 |
|
| 35 | ||
| 36 | def parse_data_line(self, sline): |
|
| 37 | """ |
|
| 38 | Parses the data line and builds the dictionary. |
|
| 39 | :param sline: a split data line to parse |
|
| 40 | :returns: the number of rows to jump and parse the next data line or return the code error -1 |
|
| 41 | """ |
|
| 42 | # if there are less values founded than headers, it's an error |
|
| 43 | if len(sline) != len(self._columns): |
|
| 44 | self.err("One data line has the wrong number of items") |
|
| 45 | return -1 |
|
| 46 | #print self._columns |
|
| 47 | rawdict = {} |
|
| 48 | for idx, result in enumerate(sline): |
|
| 49 | rawdict[self._columns[idx]] = result |
|
| 50 | # Getting key values |
|
| 51 | resid = rawdict['Sample ID'] |
|
| 52 | del rawdict['Sample ID'] |
|
| 53 | testname = rawdict['Test'] |
|
| 54 | del rawdict['Test'] |
|
| 55 | ||
| 56 | # Building the new dict |
|
| 57 | rawdict['DefaultResult'] = 'Result' |
|
| 58 | rawdict['Remarks'] = rawdict['Comment'] |
|
| 59 | del rawdict['Comment'] |
|
| 60 | print rawdict |
|
| 61 | ||
| 62 | self._addRawResult(resid, {testname: rawdict}, False) |
|
| 63 | return 0 |
|
| 64 | ||
| 65 | ||
| 66 | class FacsCaliburImporter(AnalysisResultsImporter): |
|