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

Fix summarizeFasta that summarize table keys not determined correctly with source comb in --order-source #828

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion moPepGen/aa/PeptidePoolSummarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ def write_summary_table(self, handle:IO):
summary_keys = self.summary_table.get_keys()
header = '\t'.join(['sources', *summary_keys])
handle.write(header + '\n')
sources = [it[0] for it in sorted(self.order.items(), key=lambda x:x[1])]
sources = [it[0] for it in sorted(self.order.items(), key=lambda x:x[1])
if not isinstance(it[0], frozenset)]
for i in range(len(sources)):
for comb in itertools.combinations(sources, i + 1):
if self.ignore_missing_source:
Expand Down
81 changes: 81 additions & 0 deletions test/unit/test_peptide_pool_summarizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
""" Module for testing PeptidePoolSummarizer """
import copy
import io
from contextlib import redirect_stdout
import unittest
from test.unit import create_aa_record, create_genomic_annotation, get_tx2gene_and_coding_tx
from test.unit.test_peptide_pool_splitter import (
LABEL_MAP1, SOURCE_ORDER, ANNOTATION_DATA,
)
from moPepGen.aa.PeptidePoolSummarizer import PeptidePoolSummarizer
from moPepGen.aa.PeptidePoolSplitter import LabelSourceMapping
from moPepGen.aa import VariantPeptidePool


SOURCE_PARSER_MAP = {
'gSNP': 'parseVEP',
'gINDEL': 'parseVEP',
'sSNV': 'parseVEP',
'sINDEL': 'parseVEP',
'altSplice': 'parseRMATS',
'Fusion': 'parseSTARFusion',
'circRNA': 'parseCIRCExplorer'
}

class TestPeptidePoolSummarizer(unittest.TestCase):
""" Test cases for PeptidePoolSummarizer """
def test_summarize_fasta_case1(self):
""" basic test """
anno = create_genomic_annotation(ANNOTATION_DATA)
tx2gene, coding_tx = get_tx2gene_and_coding_tx(anno)
peptides_data = [[ 'SSSSSSSR', 'ENST0001|SNV-1001-T-A|1' ]]
peptides = VariantPeptidePool({create_aa_record(*x) for x in peptides_data})
label_map = LabelSourceMapping(copy.copy(LABEL_MAP1))
summarizer = PeptidePoolSummarizer(
peptides, order=copy.copy(SOURCE_ORDER), label_map=label_map,
)
summarizer.count_peptide_source(
tx2gene=tx2gene,
coding_tx=coding_tx,
enzyme='trypsin'
)
self.assertEqual(set(summarizer.summary_table.data.keys()), {frozenset(['gSNP'])})

def test_summarize_fasta_source_comb_order(self):
""" When source combination is present in --order-source """
anno = create_genomic_annotation(ANNOTATION_DATA)
anno.transcripts['ENST0005'] = copy.deepcopy(anno.transcripts['ENST0002'])
anno.transcripts['ENST0005'].is_protein_coding = False
tx2gene, coding_tx = get_tx2gene_and_coding_tx(anno)
peptides_data = [
[
'SSSSSSSR',
'CIRC-ENST0002-E1-E2|1 ENST0005|SE-2100|1'
]
]
peptides = VariantPeptidePool({create_aa_record(*x) for x in peptides_data})
label_map = LabelSourceMapping(copy.copy(LABEL_MAP1))
# order = copy.copy(SOURCE_ORDER)
order = {
'altSplice': 1,
frozenset(['altSplice', 'Noncoding']): 2,
'Noncoding': 3,
'circRNA': 4
}
source_parser_map = copy.deepcopy(SOURCE_PARSER_MAP)
summarizer = PeptidePoolSummarizer(
peptides, order=order, label_map=label_map, source_parser_map=source_parser_map
)
summarizer.count_peptide_source(
tx2gene=tx2gene,
coding_tx=coding_tx,
enzyme='trypsin'
)
self.assertEqual(
set(summarizer.summary_table.data.keys()),
{frozenset(['altSplice', 'Noncoding'])}
)

handle = io.StringIO()
with redirect_stdout(handle):
summarizer.write_summary_table(handle)