コード例 #1
0
ファイル: predict_rt.py プロジェクト: biorack/metatlas
def adjust_atlas(atlas: metob.Atlas, model: Model, ids: AnalysisIdentifiers) -> pd.DataFrame:
    """use model to adjust RTs within atlas"""
    atlas_df = ma_data.make_atlas_df(atlas)
    atlas_df["label"] = [cid.name for cid in atlas.compound_identifications]
    atlas_df["rt_peak"] = model.predict(atlas_df["rt_peak"].to_numpy())
    rt_offset = 0.2 if ids.chromatography == "C18" else 0.5
    atlas_df["rt_min"] = atlas_df["rt_peak"].apply(lambda rt: rt - rt_offset)
    atlas_df["rt_max"] = atlas_df["rt_peak"].apply(lambda rt: rt + rt_offset)
    return atlas_df
コード例 #2
0
ファイル: metatlas_dataset.py プロジェクト: biorack/metatlas
 def atlas_df(self) -> pd.DataFrame:
     """atlas_df getter, update ._atlas_df if necessary"""
     if self._atlas_df is None:
         start_time = datetime.datetime.now()
         logger.info("Generating atlas_df")
         self._atlas_df = ma_data.make_atlas_df(self.atlas)
         logger.info(
             "Generated atlas_df with %d rows in %s.",
             len(self.atlas_df),
             _duration_since(start_time),
         )
     return self._atlas_df
コード例 #3
0
ファイル: predict_rt.py プロジェクト: biorack/metatlas
def get_qc_atlas(
    ids: AnalysisIdentifiers, rt_min_delta: Optional[float], rt_max_delta: Optional[float]
) -> Tuple[metob.Atlas, pd.DataFrame]:
    """Retreives template QC atlas and return tuple (atlas, atlas_df)"""
    qc_atlas_dict = QC_ATLASES[ids.polarity][ids.chromatography]
    qc_atlas_name = qc_atlas_dict["name"]
    username = qc_atlas_dict["username"]
    logger.info("Loading QC Atlas %s", qc_atlas_name)
    original_atlas = metob.retrieve("Atlas", name=qc_atlas_name, username=username)[0]
    atlas = adjust_atlas_rt_range(original_atlas, rt_min_delta, rt_max_delta)
    atlas_df = ma_data.make_atlas_df(atlas)
    atlas_df["label"] = [cid.name for cid in atlas.compound_identifications]
    return atlas, atlas_df
コード例 #4
0
ファイル: metatlas_dataset.py プロジェクト: biorack/metatlas
 def _clone_source_atlas(self) -> metob.Atlas:
     logger.info("Retriving source atlas: %s", self.ids.source_atlas)
     source_atlas = get_atlas(cast(AtlasName, self.ids.source_atlas),
                              cast(Username, "*"))
     source_atlas_df = ma_data.make_atlas_df(source_atlas)
     logger.info("Cloning atlas %s", self.ids.source_atlas)
     return dp.make_atlas_from_spreadsheet(
         source_atlas_df,
         self.ids.atlas,
         filetype="dataframe",
         sheetname="",
         polarity=self.ids.polarity,
         store=True,
         mz_tolerance=source_atlas.compound_identifications[0].
         mz_references[0].mz_tolerance,
     )
コード例 #5
0
def test_make_atlas_df(atlas_with_2_cids):
    # pylint: disable=line-too-long
    expected = """{"inchi_key":{"0":"OLXZPDWKRNYJJZ-RRKCRQDMSA-N","1":"OIRDTQYFTABQOQ-KQYNXXCUSA-N"},"compound_name":{"0":"2\'-deoxyadenosine","1":"adenosine"},"rt_max":{"0":2.6964640054,"1":3.523318408},"rt_min":{"0":1.6964640054,"1":2.523318408},"rt_peak":{"0":2.1964640054,"1":3.023318408},"rt_units":{"0":"min","1":"min"},"detected_polarity":{"0":"positive","1":"positive"},"mz":{"0":252.1091393,"1":268.1040539},"mz_tolerance":{"0":20.0,"1":20.0},"mz_tolerance_units":{"0":"ppm","1":"ppm"},"mono_isotopic_molecular_weight":{"0":251.101839276,"1":267.096753896},"pubchem_compound_id":{"0":"13730","1":"60961"},"synonyms":{"0":"2\'-deoxyadenosine","1":"adenosine\\/\\/\\/58-61-7\\/\\/\\/Adenocard\\/\\/\\/Adenoscan"},"inchi":{"0":"InChI=1S\\/C10H13N5O3\\/c11-9-8-10(13-3-12-9)15(4-14-8)7-1-5(17)6(2-16)18-7\\/h3-7,16-17H,1-2H2,(H2,11,12,13)\\/t5-,6+,7+\\/m0\\/s1","1":"InChI=1S\\/C10H13N5O4\\/c11-8-5-9(13-2-12-8)15(3-14-5)10-7(18)6(17)4(1-16)19-10\\/h2-4,6-7,10,16-18H,1H2,(H2,11,12,13)\\/t4-,6-,7-,10-\\/m1\\/s1"},"adduct":{"0":"[M+H]+","1":"[M+H]+"},"label":{"0":"2\'-deoxyadenosine","1":"adenosine"},"ms1_notes":{"0":"keep","1":""},"ms2_notes":{"0":"-1,bad match to ref","1":""},"identification_notes":{"0":"my id note","1":""}}"""  # noqa: E501
    assert expected == gdhf.make_atlas_df(atlas_with_2_cids).to_json()