Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to write fragment level quant #443

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

ammarcsj
Copy link
Member

@ammarcsj ammarcsj commented Jan 17, 2025

This PR adds the option to write to disk a matrix with fragment-level quantities which can be used for detailed inspection of the data or downstream quantification algorithms.

Changes:

  • Extended SearchPlanOutput.build_lfq_tables() to support fragment-level table export. When enabled, the feature exports the precursor-level group_intensity_df containing all fragments that pass the precursor level correlation filters
  • Added boolean config option in config_dict["search_output"]["fragment_quant_matrix"] (default: false)
  • Updated default config.yaml to include the new option

@ammarcsj ammarcsj marked this pull request as draft January 17, 2025 16:16
@ammarcsj ammarcsj requested review from GeorgWa and mschwoer January 21, 2025 15:14
@ammarcsj ammarcsj marked this pull request as ready for review January 21, 2025 15:14
@@ -237,6 +237,7 @@ fdr:
search_output:
peptide_level_lfq: false
precursor_level_lfq: false
fragment_quant_matrix: false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment what this is doing and that this is an advanced feature

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 added

write_df(
group_intensity_df,
os.path.join(
self.output_folder, f"fragment_{level_name}filt.matrix"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the filt intended?

Copy link
Member Author

@ammarcsj ammarcsj Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is meant to indicate that the fragments are filtered using the precursor-level fragment filter

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please be more explicit, _filtered or smth

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -85,6 +85,7 @@ test_cases:
search_output:
peptide_level_lfq: true
precursor_level_lfq: true
fragment_quant_matrix: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's only test this in one of the testcases

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"peptide",
self.config["search_output"]["peptide_level_lfq"],
),
quantlevel_configs = [ # the configs specified here are: quantlevel, level_name, should_process, save_fragments
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be a namedtuple for instance, then the comment will be obsolete as the code will tell

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dataclass should be nicer:

       @dataclass
        class LFQOutputConfig:
            should_process: bool
            quant_level: str
            level_name: str
            save_fragments: bool = False

        quantlevel_configs = [
            LFQOutputConfig(
                self.config["search_output"]["precursor_level_lfq"],
                "mod_seq_charge_hash",
                "precursor",
                self.config["search_output"]["fragment_quant_matrix"],
            ),
            LFQOutputConfig(
                self.config["search_output"]["peptide_level_lfq"],
                "mod_seq_hash",
                "peptide",
            ),
            LFQOutputConfig(
                True,
                "pg",
                "pg",
                ),
            ]

        lfq_results = {}

        for quantlevel_config in quantlevel_configs:
            if not quantlevel_config.should_process:
                continue
....

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

write_df(
group_intensity_df,
os.path.join(
self.output_folder, f"fragment_{level_name}filt.matrix"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please be more explicit, _filtered or smth

@@ -237,6 +237,7 @@ fdr:
search_output:
peptide_level_lfq: false
precursor_level_lfq: false
fragment_quant_matrix: false #advanced feature to write out quantitative matrix with fragment ion intensities e.g. for AlphaQuant
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

save_fragment_quant_matrix?

should this also be part of the GUI @GeorgWa ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed it. Indeed I think it should be part of the GUI, would be good for AlphaQuant compatibility.

Copy link
Collaborator

@mschwoer mschwoer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -120,6 +121,7 @@ test_cases:
search_output:
peptide_level_lfq: true
precursor_level_lfq: true
save_fragment_quant_matrix: false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that false is the default, no need to specify it here in the yamls

group_intensity_df,
os.path.join(
self.output_folder,
f"fragment_{quantlevel_config.level_name}filtered.matrix",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is .matrix a special file format? or could this be something like .matrix.tsv?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the file format is set by write_df. To me it would also be fine if the advanced output is always saved as .parquet

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, did not look into write_df to see path_no_format 👍

Copy link
Collaborator

@GeorgWa GeorgWa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks Constantin

group_intensity_df,
os.path.join(
self.output_folder,
f"fragment_{quantlevel_config.level_name}filtered.matrix",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the file format is set by write_df. To me it would also be fine if the advanced output is always saved as .parquet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants