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

Repair canonical_transcripts #156

Open
wants to merge 5 commits into
base: v0.11
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions gffutils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def to_unicode(obj, encoding='utf-8'):

def canonical_transcripts(db, fasta_filename):
import pyfaidx
fasta = pyfaidx.Fasta(fasta_filename, as_raw=True)
fasta = pyfaidx.Fasta(fasta_filename, as_raw=False)
for gene in db.features_of_type('gene'):

# exons_list will contain (CDS_length, total_length, transcript, [exons]) tuples.
Expand All @@ -449,20 +449,20 @@ def canonical_transcripts(db, fasta_filename):
cds_len += exon_length
total_len += exon_length

exon_list.append((cds_len, total_len, transcript, exons))
exon_list.append((cds_len, total_len, transcript, exons if cds_len == 0 else [e for e in exons if e.featuretype in ['CDS', 'five_prime_UTR', 'three_prime_UTR']] ))

# If we have CDS, then use the longest coding transcript
if max(i[0] for i in exon_list) > 0:
best = sorted(exon_list)[0]
best = sorted(exon_list, key=lambda x: x[0], reverse=True)[0]
# Otherwise, just choose the longest
else:
best = sorted(exon_list, lambda x: x[1])[0]
best = sorted(exon_list, key=lambda x: x[1])[0]

print(best)

canonical_exons = best[-1]
transcript = best[-2]
seqs = [i.sequence(fasta) for i in canonical_exons]
seqs = [i.sequence(fasta) for i in sorted(canonical_exons, key=lambda x: x.start, reverse=transcript.strand != '+')]
yield transcript, ''.join(seqs)


Expand Down