Skip to content

Commit

Permalink
update: ae&de
Browse files Browse the repository at this point in the history
  • Loading branch information
zprobot committed May 30, 2024
1 parent 06abcfc commit c25ef88
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
13 changes: 11 additions & 2 deletions quantmsio/commands/absolute_expression_command.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import click

from quantmsio.core.ae import AbsoluteExpressionHander

from quantmsio.utils.file_utils import extract_protein_list

@click.command(
"convert-ae",
Expand All @@ -17,6 +17,11 @@
help="the sdrf_file path",
required=True,
)
@click.option(
"--protein_file",
help="Protein file that meets specific requirements",
required=False,
)
@click.option(
"--project_file",
help="quantms.io project file",
Expand All @@ -29,6 +34,7 @@ def convert_ibaq_absolute(
ibaq_file: str,
sdrf_file: str,
project_file: str,
protein_file:str,
output_folder: str,
output_prefix_file: str,
delete_existing: bool = True,
Expand All @@ -40,14 +46,17 @@ def convert_ibaq_absolute(
:param sdrf_file: sdrf file
:param project_file: quantms.io project file
:param output_folder: Folder to generate the df expression file.
:protein_file: Filtered protein file.
:param output_prefix_file: Prefix of the df expression file
:param delete_existing: Delete existing files in the output folder
:return: none
"""
protein_list = extract_protein_list(protein_file) if protein_file else None
protein_str = "|".join(protein_list) if protein_list else None
ae_handler = AbsoluteExpressionHander()
if project_file:
ae_handler.load_project_file(project_file)
ae_handler.load_ibaq_file(ibaq_file)
ae_handler.load_ibaq_file(ibaq_file,protein_str)
ae_handler.load_sdrf_file(sdrf_file)
ae_handler.convert_ibaq_to_quantms(
output_folder=output_folder,
Expand Down
13 changes: 10 additions & 3 deletions quantmsio/commands/differential_expression_command.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import click

from quantmsio.core.de import DifferentialExpressionHandler

from quantmsio.utils.file_utils import extract_protein_list

@click.command(
"convert-de",
Expand All @@ -24,13 +24,19 @@
required=False,
default="0.05",
)
@click.option(
"--protein_file",
help="Protein file that meets specific requirements",
required=False,
)
@click.option("--output_folder", help="Folder to generate the df expression file.", required=True)
@click.option("--output_prefix_file", help="Prefix of the df expression file", required=False)
@click.option("--delete_existing", help="Delete existing files in the output folder", is_flag=True)
def convert_msstats_differential(
msstats_file: str,
sdrf_file: str,
project_file: str,
protein_file:str,
fdr_threshold: float,
output_folder: str,
output_prefix_file: str,
Expand All @@ -51,11 +57,12 @@ def convert_msstats_differential(

if msstats_file is None or sdrf_file is None or output_folder is None:
raise click.UsageError("Please provide all the required parameters")

protein_list = extract_protein_list(protein_file) if protein_file else None
protein_str = "|".join(protein_list) if protein_list else None
de_handler = DifferentialExpressionHandler()
if project_file:
de_handler.load_project_file(project_file)
de_handler.load_msstats_file(msstats_file)
de_handler.load_msstats_file(msstats_file,protein_str)
de_handler.load_sdrf_file(sdrf_file)
de_handler.set_fdr_threshold(fdr_threshold=fdr_threshold)
de_handler.convert_msstats_to_quantms(
Expand Down
2 changes: 1 addition & 1 deletion quantmsio/commands/feature_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
)
@click.option(
"--protein_file",
help="the mzTab file, this will be used to extract the protein information",
help="Protein file that meets specific requirements",
required=False,
)
@click.option(
Expand Down
2 changes: 1 addition & 1 deletion quantmsio/commands/psm_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
)
@click.option(
"--protein_file",
help="the mzTab file, this will be used to extract the protein information",
help="Protein file that meets specific requirements",
required=False,
)
@click.option(
Expand Down
4 changes: 3 additions & 1 deletion quantmsio/core/ae.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ def load_project_file(self, project_file: str):
self.project_manager = ProjectHandler()
self.project_manager.load_project_info(project_file)

def load_ibaq_file(self, path):
def load_ibaq_file(self, path,protein_str=None):
usecols = ["ProteinName", "SampleID", "Condition", "Ibaq", "IbaqLog"]
ibaq_columns = get_ibaq_columns(path)
for col in usecols:
if col not in ibaq_columns:
raise Exception(f"Not found {col} in ibaq file")
ibaqs = pd.read_csv(path, usecols=usecols)
ibaqs.rename(columns=AbsoluteExpressionHander.LABEL_MAP, inplace=True)
if protein_str:
ibaqs = ibaqs[ibaqs["protein"].str.contains(f"{protein_str}",na=False)]
self.ae_file_path = path
self.ibaq_df = ibaqs

Expand Down
4 changes: 3 additions & 1 deletion quantmsio/core/de.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(self):
self.msstats_df = None
self.de_file_path = None

def load_msstats_file(self, msstats_file_path: str):
def load_msstats_file(self, msstats_file_path: str,protein_str:str=None):
"""
Load a MSstats differential file
:param msstats_file_path: MSstats differential file path
Expand All @@ -90,6 +90,8 @@ def load_msstats_file(self, msstats_file_path: str):
self.msstats_df = pd.read_csv(msstats_file_path, sep="\t")
# Rename columns to a lower case
self.msstats_df.columns = self.msstats_df.columns.str.lower()
if protein_str:
self.msstats_df = self.msstats_df[self.msstats_df["protein"].str.contains(f"{protein_str}",na=False)]

def load_project_file(self, project_file: str):
"""
Expand Down

0 comments on commit c25ef88

Please sign in to comment.