-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test unit for extract ri from comment
- Loading branch information
1 parent
9d4089f
commit 2a1006b
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import pytest | ||
import pandas as pd | ||
from RIAssigner.data import PandasData, MatchMSData | ||
|
||
import os | ||
|
||
here = os.path.abspath(os.path.dirname(__file__)) | ||
testdata_dir = os.path.join(here, 'data', 'ri_from_comment') | ||
|
||
@pytest.fixture | ||
def reference_data_csv(request): | ||
filename = f'peaks_with_rt_ref_{request.param}.csv' | ||
df_reference = pd.read_csv(os.path.join(testdata_dir, filename)) | ||
return df_reference['retention_index'].tolist() | ||
|
||
@pytest.mark.parametrize("reference_data_csv, comment_string", [("SemiStdNP", "SemiStdNP"), ("StdNP", "StdNP"), ("StdPolar", "StdPolar")], indirect=["reference_data_csv"]) | ||
def test_extract_ri_from_csv_comment(reference_data_csv, comment_string): | ||
query = PandasData(os.path.join(testdata_dir, 'nist_to_ri_2mols.csv'), "csv", rt_unit="seconds") | ||
query.extract_ri_from_comment(comment_string) | ||
assert query.retention_indices.tolist() == reference_data_csv | ||
|
||
@pytest.fixture | ||
def reference_data_msp(request): | ||
filename = f'peaks_with_rt_ref_{request.param}_msp.csv' | ||
df_reference = pd.read_csv(os.path.join(testdata_dir, filename), header=None, usecols=[0]) | ||
comment_parts = df_reference.loc[df_reference[0].str.startswith('COMMENT')][0].str.split() | ||
comment = [part for sublist in comment_parts for part in sublist] | ||
ri = [float(part.split('=')[1].split('/')[0]) for part in comment if part.startswith(request.param)] | ||
return ri | ||
|
||
@pytest.mark.parametrize("reference_data_msp, comment_string", [("SemiStdNP", "SemiStdNP"), ("StdNP", "StdNP"), ("StdPolar", "StdPolar")], indirect=["reference_data_msp"]) | ||
def test_extract_ri_from_msp_comment(reference_data_msp, comment_string): | ||
query = MatchMSData(os.path.join(testdata_dir, 'NIST_EI_MS_2mols.msp'), "msp", rt_unit="min") | ||
query.extract_ri_from_comment(comment_string) | ||
assert query.retention_indices == reference_data_msp |