Пример #1
0
 def test_xls_key(self):
     #
     # Import .xlsx workbook
     #
     test_file = os.path.join(test_dir, "sample_gc_ms_key.xlsx")
     headers, table = gc_ms.import_xlsx_metadata(open(test_file, "rb"))
     assert (headers == [
         'sample ID (could be vial #)',
         'label to display',
         'parent strain',
         'plasmid/change',
         'colony number',
         'time point',
         'media (induction, etc.)',
         'sample type',
         None,
         'user field 1',
         'user field 2',
         'user field 3',
     ])
Пример #2
0
def process_gc_ms_form_and_parse_file(form, file):
    try:
        data = re.sub("\r", "", file.read())
        result = gc_ms.Report(data.splitlines())
    except ValueError as e:
        try:
            headers, table = gc_ms.import_xlsx_metadata(file)
        except Exception:
            raise ValueError(
                "The uploaded file could not be processed as either an MSDChemStation report "
                "or an Excel workbook.")
        else:
            return {
                "data_type": "xls",
                "headers": headers,
                "table": table,
            }
    if form.get("auto_peaks") == "auto":
        return result.find_peaks_automatically_and_export(include_headers=True)
    else:
        n_mols = form_utils.extract_integers_from_form(form, "n_mols")
        rt_std_min = form_utils.extract_floats_from_form(
            form, "rt_standard_min")
        rt_std_max = form_utils.extract_floats_from_form(
            form, "rt_standard_max")
        rt_ranges_and_molecules = [(rt_std_min, rt_std_max, "standard")]
        for i_mol in range(n_mols):
            mol_name = form_utils.extract_non_blank_string_from_form(
                form, param_name="mol_name_%d" % i_mol)
            rt_min = form_utils.extract_floats_from_form(
                form, param_name='rt_min_mol_%d' % i_mol)
            rt_max = form_utils.extract_floats_from_form(
                form, param_name='rt_max_mol_%d' % i_mol)
            rt_ranges_and_molecules.append((rt_min, rt_max, mol_name))
        rt_ranges_and_molecules.sort(key=lambda x: x[0])
        for i_rt, (x1, y1, s1) in enumerate(rt_ranges_and_molecules[:-1]):
            x2, y2, s2 = rt_ranges_and_molecules[i_rt + 1]
            assert (y1 < x2)  # this should really be checked server-side too
        return result.find_peaks_by_range_and_export(
            rt_ranges=[(x, y) for (x, y, s) in rt_ranges_and_molecules],
            molecule_names=[s for (x, y, s) in rt_ranges_and_molecules])