2
2
[FusionCatcher](https://github.com/ndaniel/fusioncatcher) and save as a
3
3
GVF file. The GVF file can be later used to call variant peptides using
4
4
[callVariant](call-variant.md)."""
5
- from typing import List
5
+ from __future__ import annotations
6
+ from typing import TYPE_CHECKING
6
7
from pathlib import Path
7
8
import argparse
8
9
from moPepGen import get_logger , seqvar , parser , err
9
10
from moPepGen .cli import common
10
11
11
12
13
+ if TYPE_CHECKING :
14
+ from typing import List
15
+ from logging import Logger
16
+
12
17
INPUT_FILE_FORMATS = ['.tsv' , '.txt' ]
13
18
OUTPUT_FILE_FORMATS = ['.gvf' ]
14
19
@@ -42,16 +47,48 @@ def add_subparser_parse_fusion_catcher(subparsers:argparse._SubParsersAction):
42
47
default = 5 ,
43
48
metavar = '<number>'
44
49
)
50
+ common .add_args_skip_failed (p )
45
51
common .add_args_source (p )
46
52
common .add_args_reference (p , proteome = False )
47
53
common .add_args_debug_level (p )
48
54
p .set_defaults (func = parse_fusion_catcher )
49
55
common .print_help_if_missing_args (p )
50
56
return p
51
57
58
+ class TallyTable ():
59
+ """ Tally table """
60
+ def __init__ (self , logger :Logger ):
61
+ """ Constructor """
62
+ self .total :int = 0
63
+ self .succeed :int = 0
64
+ self .skipped :TallyTableSkipped = TallyTableSkipped ()
65
+ self .logger = logger
66
+
67
+ def log (self ):
68
+ """ Show tally results """
69
+ self .logger .info ("Summary:" )
70
+ self .logger .info ("Totally records read: %i" , self .total )
71
+ self .logger .info ("Records successfully processed: %i" , self .succeed )
72
+ self .logger .info ("Records skipped: %i" , self .skipped .total )
73
+ if self .skipped .total > 0 :
74
+ self .logger .info ("Out of those skipped," )
75
+ self .logger .info (" Invalid gene ID: %i" , self .skipped .invalid_gene_id )
76
+ self .logger .info (" Invalid position: %i" , self .skipped .invalid_position )
77
+ self .logger .info (" Insufficient evidence: %i" , self .skipped .insufficient_evidence )
78
+
79
+ class TallyTableSkipped ():
80
+ """ Tally table for failed ones """
81
+ def __init__ (self ):
82
+ """ constructor """
83
+ self .invalid_gene_id :int = 0
84
+ self .invalid_position :int = 0
85
+ self .insufficient_evidence :int = 0
86
+ self .total :int = 0
87
+
52
88
def parse_fusion_catcher (args :argparse .Namespace ) -> None :
53
89
""" Parse FusionCatcher output and save it in GVF format. """
54
90
logger = get_logger ()
91
+ tally = TallyTable (logger )
55
92
# unpack args
56
93
fusion = args .input_path
57
94
output_path :Path = args .output_path
@@ -69,15 +106,26 @@ def parse_fusion_catcher(args:argparse.Namespace) -> None:
69
106
variants :List [seqvar .VariantRecord ] = []
70
107
71
108
for record in parser .FusionCatcherParser .parse (fusion ):
72
- if record .counts_of_common_mapping_reads > args .max_common_mapping :
73
- continue
74
- if record .spanning_unique_reads < args .min_spanning_unique :
109
+ tally .total += 1
110
+ if record .counts_of_common_mapping_reads > args .max_common_mapping \
111
+ or record .spanning_unique_reads < args .min_spanning_unique :
112
+ tally .skipped .insufficient_evidence += 1
113
+ tally .skipped .total += 1
75
114
continue
76
115
try :
77
116
var_records = record .convert_to_variant_records (anno , genome )
117
+ variants .extend (var_records )
118
+ tally .succeed += 1
78
119
except err .GeneNotFoundError :
120
+ tally .skipped .invalid_gene_id += 1
121
+ tally .skipped .total += 1
79
122
continue
80
- variants .extend (var_records )
123
+ except :
124
+ if args .skip_failed :
125
+ tally .skipped .total += 1
126
+ tally .skipped .invalid_position += 1
127
+ continue
128
+ raise
81
129
82
130
logger .info ('FusionCatcher output %s loaded.' , fusion )
83
131
@@ -95,3 +143,5 @@ def parse_fusion_catcher(args:argparse.Namespace) -> None:
95
143
seqvar .io .write (variants , output_path , metadata )
96
144
97
145
logger .info ("Variants written to disk." )
146
+
147
+ tally .log ()
0 commit comments