Skip to content

Commit

Permalink
Merge pull request #51 from llegregam/Dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
llegregam committed Mar 28, 2024
2 parents 6538d4f + 9c68555 commit f69a2aa
Show file tree
Hide file tree
Showing 13 changed files with 4,418 additions and 236 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [ '3.8', '3.9', '3.10']
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion ms_reader/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.6.1"
__version__ = "1.6.2"
6 changes: 3 additions & 3 deletions ms_reader/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ def convert_df(df):
try:
reader.handle_calibration()
except Exception as e:
st.error("There was an error while handling the calibration data")
st.error(f"There was an error while handling the calibration data:\n{e}")
raise
if report_box:
try:
reader.generate_report(metabolites_to_drop)
except Exception as e:
st.error("There was an error while generating the report")
st.error(f"There was an error while generating the report:\n{e}")
raise
if preview:
with st.expander("Show report"):
Expand Down Expand Up @@ -288,4 +288,4 @@ def convert_df(df):
reader.export_stat_output(destination, pca=True)
if conc_box or lloq_box:
st.warning("**WARNING:** The PCA output only exports areas and ratios")
st.success("The input for GraphStatR has been generated (PCA mode)")
st.success("The input for GraphStatR has been generated (PCA mode)")
12 changes: 5 additions & 7 deletions ms_reader/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,8 @@ def _replace_nf(self):
Replace initial N/F with 0
:return: None
"""
self.data.loc[:, "Area"] = \
self.data.loc[:, "Area"].replace("N/F", 0).copy()
self.data.loc[:, "Calculated Amt"] = \
self.data.loc[:, "Calculated Amt"].replace("N/F", 0).copy()
self.data["Area"] = self.data["Area"].replace("N/F", 0)
self.data["Calculated Amt"] = self.data["Calculated Amt"].replace("N/F", 0).copy()

def _split_dataframes(self):
"""
Expand Down Expand Up @@ -320,7 +318,7 @@ def _get_excluded(self):
Replace excluded points concentration with 'excluded'
:return: None
"""
self.calib_data.loc[:, "Calculated Amt"] = pd.to_numeric(
self.calib_data["Calculated Amt"] = pd.to_numeric(
self.calib_data["Calculated Amt"]
)
self.calib_data.loc[
Expand Down Expand Up @@ -580,7 +578,7 @@ def _handle_conc_norm(self, cols, base_unit):
"""
# normalise
self._generate_normalised_concentrations(cols)
# map "ND" to negative and null values
# applymap "ND" to negative and null values
self.quantities = self.quantities.applymap(format)
self.normalised_quantities = \
self.normalised_quantities.applymap(format)
Expand Down Expand Up @@ -622,7 +620,7 @@ def _handle_conc_no_norm(self, cols, base_unit):

# generate loq_table
self.loq_table = self._define_loq(self.concentration_table.copy())
# map "ND" to negative and null values
# applymap "ND" to negative and null values
self.concentration_table = self.concentration_table.applymap(
format
)
Expand Down
42 changes: 22 additions & 20 deletions ms_reader/skyline_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,29 @@
"Blank": "Unknown"
}

def convert_column_names(df):

def convert_column_names(df):
return df.rename(MAPPING, axis=1)

def convert_sample_types(value):

def convert_sample_types(value):
if value in SAMPLE_TYPE_MAPPING.keys():
return SAMPLE_TYPE_MAPPING[value]
return value

def convert_accuracy_to_diff(value):

def convert_accuracy_to_diff(value):
if value != np.nan:
return round(float(str(value).replace("%", ""))-100, 1)

def convert_calculated_amt(value):

def convert_calculated_amt(value):
if type(value) == str:
if "Normalized Area" in value or "NaN" in value:
return np.nan
return float(str(value).replace(" uM", ""))


def handle_na(row):
if "(heavy)" in row["Precursor"]:
row["Compound"] = row["Compound"] + " C13"
Expand All @@ -62,15 +63,15 @@ def handle_na(row):
print(f"Area value = {row['Area']}\nCalculated Amt value = {row['Calculated Amt']}")
return row


def import_skyline_dataset(skyline_file):
"""
Import skyline dataset and transform into MS_Reader compatible format
:param skyline_file: Bytes file containing skyline data (tabular format)
"""

# Get copy of file binary to dodge any wierd effects when file is read twice by pandas
#file = copy(skyline_file)
# file = copy(skyline_file)
filename_extension = skyline_file.name[-3:]
if filename_extension not in ["tsv", "txt"]:
raise TypeError(
Expand All @@ -79,7 +80,7 @@ def import_skyline_dataset(skyline_file):
)

data = pd.read_csv(skyline_file, sep="\t")
#if len(data.columns) == 1:
# if len(data.columns) == 1:
# data = pd.read_csv(file, sep="\t")
data = convert_column_names(data)
data["Sample Type"] = data["Sample Type"].apply(convert_sample_types)
Expand All @@ -93,20 +94,21 @@ def import_skyline_dataset(skyline_file):

return data


if __name__ == "__main__":

#df = pd.read_csv(,sep=",")
#print(df.columns)
#converted_df = convert_column_names(df)
#print(converted_df.columns)
#print(converted_df["Sample Type"].unique())
#converted_df["Sample Type"] = converted_df["Sample Type"].apply(convert_sample_types)
#print(converted_df["Sample Type"].unique())
#print(converted_df["%Diff"])
#converted_df["%Diff"] = converted_df["%Diff"].apply(convert_accuracy_to_diff).fillna("NA")
#print(converted_df["%Diff"])
#converted_df["Calculated Amt"] = converted_df["Calculated Amt"].apply(convert_calculated_amt)
#converted_df = converted_df.apply(handle_na, axis=1)
#converted_df.to_excel(r"C:\Users\legregam\Desktop\test\test.xlsx", index=False)
# df = pd.read_csv(,sep=",")
# print(df.columns)
# converted_df = convert_column_names(df)
# print(converted_df.columns)
# print(converted_df["Sample Type"].unique())
# converted_df["Sample Type"] = converted_df["Sample Type"].apply(convert_sample_types)
# print(converted_df["Sample Type"].unique())
# print(converted_df["%Diff"])
# converted_df["%Diff"] = converted_df["%Diff"].apply(convert_accuracy_to_diff).fillna("NA")
# print(converted_df["%Diff"])
# converted_df["Calculated Amt"] = converted_df["Calculated Amt"].apply(convert_calculated_amt)
# converted_df = converted_df.apply(handle_na, axis=1)
# converted_df.to_excel(r"C:\Users\legregam\Desktop\test\test.xlsx", index=False)
data = import_skyline_dataset(r"C:\Users\legregam\PycharmProjects\MSReader\tests\data\skyline\Quantif-MC.csv")
data.to_excel(r"C:\Users\legregam\Desktop\test\test2.xlsx")
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name = ms_reader
version = attr: ms_reader.__version__
author = Loïc Le Grégam
author_email = [email protected]
description = Package for parsing a Tracefinder file containing processed Mass Spectrometry data
long_description = file: README.rst
description = Package for parsing a Tracefinder or Skyline file containing processed Mass Spectrometry data
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/llegregam/MSReader
project_urls =
Expand Down
Binary file removed tests/data/good_tables_no_norm.xlsx
Binary file not shown.
Binary file removed tests/data/good_tables_norm.xlsx
Binary file not shown.
Binary file removed tests/data/no_cal/Tables.xlsx
Binary file not shown.
Binary file removed tests/data/no_cal/test_data.xlsx
Binary file not shown.
Loading

0 comments on commit f69a2aa

Please sign in to comment.