Skip to content

Commit 03170dc

Browse files
committed
deal with cases when CDS annotation is incomplete in input gtf file
1 parent fae992e commit 03170dc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/perChrom.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ def getCodons(ttdf, AA_len=None):
234234
'''
235235
if AA_len is None:
236236
AA_len = ttdf.shape[0] // 3
237+
if AA_len * 3 >= ttdf.shape[0]:
238+
AA_len = ttdf.shape[0] // 3
237239
ttdf = ttdf.iloc[:AA_len * 3]
238240
tdf_result = ttdf.groupby(np.arange(AA_len * 3) // 3).agg({'chr':'first', 'strand':'first', 'locs':'first', 'bases':lambda x:''.join(x), 'variant_id':lambda x:','.join(list(dict.fromkeys([e for e in list(x) if pd.notnull(e)])))})
239241
tdf_result.columns = ['chr', 'strand', 'codon1', 'codon','variants']
@@ -591,8 +593,8 @@ def translateCDSplusWithMut(r, df_mutations):
591593

592594
codons_ref = getCodons(df_CDSref, AA_len=AA_len)
593595
codons_alt = getCodons(df_CDSalt, AA_len=None)
594-
codons_ref['AA_ref'] = list(AA_seq)
595-
codons_ref['AA_index'] = list(range(1, AA_len+1))
596+
codons_ref['AA_ref'] = list(AA_seq)[:codons_ref.shape[0]]
597+
codons_ref['AA_index'] = list(range(1, codons_ref.shape[0]+1))
596598
if frame !=0:
597599
codons_ref['AA_index'] = codons_ref['AA_index'] + 1
598600
# add ref AA to codon_alt

0 commit comments

Comments
 (0)