@@ -82,14 +82,32 @@ def __init__(self, stream, sample, mode, loh_type, logr_type):
8282 super ().__init__ (stream , sample , mode , loh_type , logr_type )
8383
8484 def is_header (self , line ):
85- toks = line .rstrip ('\n ' ).split ('\t ' )
86- # expect header like: ID chromosome start end ...
87- return len (toks ) > 1 and (toks [0 ].lower () in ('id' , 'sample' )
88- or toks [1 ].lower ().startswith ('chrom' ))
85+ # expect header: ID chrom loc.start loc.end num.mark seg.mean C
86+ line_sample = line .split ('\t ' , 1 )[0 ]
87+ if line_sample .startswith ('"' ):
88+ line_sample = line_sample [1 :]
89+ if line_sample .endswith ('"' ):
90+ line_sample = line_sample [0 :- 1 ]
91+ if line_sample == "ID" :
92+ return True
93+ else :
94+ return False
8995
9096 def parse_segment (self , line , logr_type , mode ):
9197 t = line .rstrip ('\n ' ).split ('\t ' )
9298 line_sample , chrm , start , end = t [0 :4 ]
99+
100+ # PureCN enumerates chroms - change them back to X and Y
101+ chrm = str (chrm )
102+ if chrm == "chr23" :
103+ chrm = "chrX"
104+ elif chrm == "23" :
105+ chrm = "X"
106+ elif chrm == "chr24" :
107+ chrm = "chrY"
108+ elif chrm == "24" :
109+ chrm = "Y"
110+
93111 cn = t [6 ]
94112 logr = self .calculate_logratio (cn ) if logr_type == "corrected" else t [5 ]
95113 sample_id = self .resolve_sample (line_sample )
@@ -99,8 +117,14 @@ class CNVKitParser(Parser):
99117 def __init__ (self , stream , sample , mode , loh_type , logr_type ):
100118 super ().__init__ (stream , sample , mode , loh_type , logr_type )
101119
120+ # Expected columns can change based on whether allele-specific
121+ # copy numbers could be inferred from the VCF
122+ # if yes:
123+ # chromosome start end gene log2 baf cn cn1 cn2 depth probes weight
124+ # if no:
125+ # chromosome start end gene log2 cn depth probes weight
126+
102127 def is_header (self , line ):
103- # expect header like: chromosome, start, end, gene, log2, baf, cn, ...
104128 chrm = line .split ('\t ' , 1 )[0 ]
105129 if chrm .startswith ('"' ):
106130 chrm = chrm [1 :]
@@ -118,11 +142,18 @@ def parse_segment(self, line, logr_type, mode):
118142 chrm = chrm [1 :]
119143 if chrm .endswith ('"' ):
120144 chrm = chrm [0 :- 1 ]
121- cn = _line [6 ]
122- cn1 = None if _line [7 ] == '' else _line [7 ]
123- cn2 = None if _line [8 ] == '' else _line [8 ]
124- loh_flag = self .get_loh_flag (cn , cn1 , cn2 )
125- logr = self .calculate_logratio (cn ) if logr_type == "corrected" else _line [4 ]
145+ if len (_line ) == 12 :
146+ cn = _line [6 ]
147+ cn1 = None if _line [7 ] == '' else _line [7 ]
148+ cn2 = None if _line [8 ] == '' else _line [8 ]
149+ loh_flag = self .get_loh_flag (cn , cn1 , cn2 )
150+ logr = self .calculate_logratio (cn ) if logr_type == "corrected" else _line [4 ]
151+ else :
152+ cn = _line [5 ]
153+ cn1 = None
154+ cn2 = None
155+ loh_flag = self .get_loh_flag (cn , cn1 , cn2 )
156+ logr = self .calculate_logratio (cn ) if logr_type == "corrected" else _line [4 ]
126157 return (Segment (chrm , start , end , cn , logr , self .sample , mode , loh_flag ))
127158
128159 def get_loh_flag (self , cn , cn1 , cn2 ):
0 commit comments