Skip to content

Commit

Permalink
fix (splitFasta): made --variant-peptide optional
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuchcn committed Jan 1, 2024
1 parent dfec5c9 commit 5642271
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
22 changes: 15 additions & 7 deletions moPepGen/cli/split_fasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def add_subparser_split_fasta(subparser:argparse._SubParsersAction):
type=Path,
help='File path to the variant peptide FASTA database file. Must be'
f" generated by moPepGen callVariant. Valid formats: {FASTA_FILE_FORMAT}",
metavar='<file>'
metavar='<file>',
default=None
)
p.add_argument(
'--noncoding-peptides',
Expand All @@ -54,7 +55,8 @@ def add_subparser_split_fasta(subparser:argparse._SubParsersAction):
type=Path,
help='File path to the alt translation peptide FASTA file. Must be'
f"generated by moPepGen callAltTranslation. Valid formats: {FASTA_FILE_FORMAT}",
metavar='<file>'
metavar='<file>',
default=None
)
p.add_argument(
'-o', '--output-prefix',
Expand Down Expand Up @@ -109,7 +111,13 @@ def split_fasta(args:argparse.Namespace) -> None:
common.validate_file_format(
file, GVF_FILE_FORMAT, check_readable=True
)
for file in [args.variant_peptides, args.noncoding_peptides]:
peptide_fastas = [args.variant_peptides, args.noncoding_peptides, args.alt_translation_peptides]
if all(x is None for x in peptide_fastas):
raise ValueError(
"At least one of '--variant-peptide', '--noncoding-peptide' or"
"' --alt-translation-peptide' must be given. Please verify your command."
)
for file in peptide_fastas:
if file is not None:
common.validate_file_format(
file, FASTA_FILE_FORMAT, check_readable=True
Expand Down Expand Up @@ -155,10 +163,10 @@ def split_fasta(args:argparse.Namespace) -> None:

splitter = PeptidePoolSplitter(order=source_order, group_map=group_map)

with open(args.variant_peptides, 'rt') as handle:
splitter.load_database(handle)

logger(f"Variant FASTA loaded: {args.variant_peptides}.")
if args.variant_peptides:
with open(args.variant_peptides, 'rt') as handle:
splitter.load_database(handle)
logger(f"Variant FASTA loaded: {args.variant_peptides}.")

if args.noncoding_peptides:
with open(args.noncoding_peptides, 'rt') as handle:
Expand Down
18 changes: 18 additions & 0 deletions test/integration/test_split_fasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,21 @@ def test_split_fasta_source_order_comb(self):
])
args.max_source_groups = 2
cli.split_fasta(args)

def test_split_fasta_noncoding_and_alttrans(self):
""" test splitFasta with only noncoding and alt trans peptides """
args = self.create_base_args()
args.gvf = [
]
args.variant_peptides = None
args.noncoding_peptides = self.data_dir/'peptides/noncoding.fasta'
args.alt_translation_peptides = self.data_dir/'peptides/alt_translation.fasta'
args.annotation_gtf = self.data_dir/'annotation.gtf'
args.proteome_fasta = self.data_dir/'translate.fasta'
cli.split_fasta(args)
files = {str(file.name) for file in self.work_dir.glob('*')}
expected = {
'test_Noncoding.fasta', 'test_SECT.fasta',
'test_Remaining.fasta', 'test_CodonReassign.fasta'
}
self.assertEqual(files, expected)

0 comments on commit 5642271

Please sign in to comment.