예제 #1
0
def test_rts04(analysis_ids, sqlite_with_atlas, mocker, lcmsrun, df_container):
    mocker.patch(
        "metatlas.io.metatlas_get_data_helper_fun.df_container_from_metatlas_file",
        return_value=df_container)
    mocker.patch("metatlas.plots.dill2plots.get_metatlas_files",
                 return_value=[lcmsrun])
    first = mads.MetatlasDataset(ids=analysis_ids)
    first.set_rt(0, "rt_max", 1.11)
    second = mads.MetatlasDataset(ids=analysis_ids)
    assert second.rts[0].rt_max == 1.11
    second.set_rt(0, "rt_max", 2.22)
    third = mads.MetatlasDataset(ids=analysis_ids)
    assert third.rts[0].rt_max == 2.22
예제 #2
0
def test_get_atlas03(mocker, analysis_ids, caplog, username):
    mocker.patch("metatlas.datastructures.metatlas_objects.retrieve",
                 return_value=[0, 0])
    with pytest.raises(ValueError):
        mads.MetatlasDataset(ids=analysis_ids)
    atlas = f"505892_OakGall_final_FinalEMA-HILIC_POS_{username}_0_0"
    assert f"2 atlases with name {atlas} and owned by {username} already exist." in caplog.text
예제 #3
0
def test_get_atlas02(mocker, analysis_ids, caplog):
    mocker.patch("metatlas.datastructures.metatlas_objects.retrieve",
                 return_value=[])
    caplog.set_level(logging.INFO)
    with pytest.raises(ValueError):
        mads.MetatlasDataset(ids=analysis_ids)
    assert "Database does not contain an atlas" in caplog.text
예제 #4
0
def test_metatlas_dataset_build02(mocker, atlas, group_with_2_lcmsruns,
                                  df_container, analysis_ids):
    # need to mock multiprocessing for this to work
    mocker.patch(
        "metatlas.io.metatlas_get_data_helper_fun.df_container_from_metatlas_file",
        return_value=df_container)
    metatlas_dataset = mads.MetatlasDataset(ids=analysis_ids, max_cpus=2)
    assert len(metatlas_dataset) == 2
    assert len(metatlas_dataset[0]) == 1
예제 #5
0
def test_get_atlas01(mocker, analysis_ids, df_container, lcmsrun, atlas,
                     username):
    mocker.patch(
        "metatlas.io.metatlas_get_data_helper_fun.df_container_from_metatlas_file",
        return_value=df_container)
    mocker.patch("metatlas.plots.dill2plots.get_metatlas_files",
                 return_value=[lcmsrun])
    mocker.patch("glob.glob", return_value=range(10))
    metatlas_dataset = mads.MetatlasDataset(ids=analysis_ids)
    assert metatlas_dataset.atlas.name == f"505892_OakGall_final_FinalEMA-HILIC_POS_{username}_0_0"
예제 #6
0
def pre_process_data_for_all_notebooks(
    ids: AnalysisIdentifiers,
    atlases: Sequence[str],
    cpus: int,
    use_poly_model: bool,
    num_points: Optional[int],
    peak_height: Optional[float],
    msms_score: Optional[float],
) -> None:
    """
    inputs:
        ids: an AnalysisIds object matching the one used in the main notebook
        atlases: list of atlas names to consider generating hits for
        cpus: max number of cpus to use
        use_poly_model: If True, use the polynomial model, else use linear model
                        Both types of models are always generated, this only determines which ones
                        are pre-populated into the generated notebooks
        num_points: minimum number of data points in a peak
        peak_height: threshold intensity level for filtering
        msms_score: minimum spectra similarity score to pass filtering
    Calls MetatlasDataset().hits, which will create a hits cache file
    Filters compounds by signal strength to reduce atlas size
    """
    for atlas_name in atlases:
        if (use_poly_model and "linear" in atlas_name) or (not use_poly_model and "polynomial" in atlas_name):
            continue
        current_ids = AnalysisIdentifiers(
            source_atlas=atlas_name,
            experiment=ids.experiment,
            output_type=get_output_type(ids.chromatography, atlas_name),
            polarity="positive" if "_POS_" in atlas_name else "negative",
            analysis_number=ids.analysis_number,
            project_directory=ids.project_directory,
            google_folder=ids.google_folder,
            rt_predict_number=ids.rt_predict_number,
        )
        metatlas_dataset = mads.MetatlasDataset(ids=current_ids, max_cpus=cpus)
        if current_ids.output_type == "ISTDsEtc":
            generate_qc_plots(metatlas_dataset, current_ids)
        _ = metatlas_dataset.hits
        if "EMA" in current_ids.output_type:
            metatlas_dataset.filter_compounds_by_signal(num_points, peak_height, msms_score)
예제 #7
0
def test_rts03(metatlas_dataset, analysis_ids):
    assert metatlas_dataset.rts[0].rt_max != 9.99
    metatlas_dataset.set_rt(0, "rt_max", 9.99)
    second_metatlas_dataset = mads.MetatlasDataset(ids=analysis_ids)
    assert second_metatlas_dataset.rts[0].rt_max == 9.99
    assert len(second_metatlas_dataset.rts) == 1