Mercurial > repos > vipints > fml_gff3togtf
annotate gff_to_gtf.py @ 11:5c6f33e20fcc default tip
requirement tag added
author | vipints <vipin@cbio.mskcc.org> |
---|---|
date | Fri, 24 Apr 2015 18:04:27 -0400 |
parents | c42c69aa81f8 |
children |
rev | line source |
---|---|
10
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
2 """ |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
3 Program to convert data from GFF to GTF |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
4 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
5 Usage: python gff_to_gtf.py in.gff > out.gtf |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
6 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
7 Requirement: |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
8 GFFParser.py: https://github.com/vipints/GFFtools-GX/blob/master/GFFParser.py |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
9 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
10 Copyright (C) |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
11 2009-2012 Friedrich Miescher Laboratory of the Max Planck Society, Tubingen, Germany. |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
12 2012-2015 Memorial Sloan Kettering Cancer Center New York City, USA. |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
13 """ |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
14 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
15 import re |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
16 import sys |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
17 import GFFParser |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
18 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
19 def printGTF(tinfo): |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
20 """ |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
21 writing result file in GTF format |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
22 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
23 @args tinfo: parsed object from gff file |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
24 @type tinfo: numpy array |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
25 """ |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
26 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
27 for ent1 in tinfo: |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
28 for idx, tid in enumerate(ent1['transcripts']): |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
29 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
30 exons = ent1['exons'][idx] |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
31 cds_exons = ent1['cds_exons'][idx] |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
32 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
33 stop_codon = start_codon = () |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
34 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
35 if ent1['strand'] == '+': |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
36 if cds_exons.any(): |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
37 start_codon = (cds_exons[0][0], cds_exons[0][0]+2) |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
38 stop_codon = (cds_exons[-1][1]-2, cds_exons[-1][1]) |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
39 elif ent1['strand'] == '-': |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
40 if cds_exons.any(): |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
41 start_codon = (cds_exons[-1][1]-2, cds_exons[-1][1]) |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
42 stop_codon = (cds_exons[0][0], cds_exons[0][0]+2) |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
43 else: |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
44 sys.stdout.write('STRAND information missing - %s, skip the transcript - %s\n' % (ent1['strand'], tid[0])) |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
45 pass |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
46 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
47 last_cds_cod = 0 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
48 for idz, ex_cod in enumerate(exons): |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
49 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
50 sys.stdout.write('%s\t%s\texon\t%d\t%d\t.\t%s\t.\tgene_id "%s"; transcript_id "%s"; exon_number "%d"; gene_name "%s"; \n' % (ent1['chr'], ent1['source'], ex_cod[0], ex_cod[1], ent1['strand'], ent1['name'], tid[0], idz+1, ent1['gene_info']['Name'])) |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
51 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
52 if cds_exons.any(): |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
53 try: |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
54 sys.stdout.write('%s\t%s\tCDS\t%d\t%d\t.\t%s\t%d\tgene_id "%s"; transcript_id "%s"; exon_number "%d"; gene_name "%s"; \n' % (ent1['chr'], ent1['source'], cds_exons[idz][0], cds_exons[idz][1], ent1['strand'], cds_exons[idz][2], ent1['name'], tid[0], idz+1, ent1['gene_info']['Name'])) |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
55 last_cds_cod = idz |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
56 except: |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
57 pass |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
58 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
59 if idz == 0: |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
60 sys.stdout.write('%s\t%s\tstart_codon\t%d\t%d\t.\t%s\t%d\tgene_id "%s"; transcript_id "%s"; exon_number "%d"; gene_name "%s"; \n' % (ent1['chr'], ent1['source'], start_codon[0], start_codon[1], ent1['strand'], cds_exons[idz][2], ent1['name'], tid[0], idz+1, ent1['gene_info']['Name'])) |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
61 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
62 if stop_codon: |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
63 sys.stdout.write('%s\t%s\tstop_codon\t%d\t%d\t.\t%s\t%d\tgene_id "%s"; transcript_id "%s"; exon_number "%d"; gene_name "%s"; \n' % (ent1['chr'], ent1['source'], stop_codon[0], stop_codon[1], ent1['strand'], cds_exons[last_cds_cod][2], ent1['name'], tid[0], idz+1, ent1['gene_info']['Name'])) |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
64 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
65 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
66 if __name__ == "__main__": |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
67 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
68 try: |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
69 gff_fname = sys.argv[1] |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
70 except: |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
71 print __doc__ |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
72 sys.exit(-1) |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
73 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
74 Transcriptdb = GFFParser.Parse(gff_fname) |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
75 |
c42c69aa81f8
fixed manually the upload of version 2.1.0 - deleted accidentally added files to the repo
vipints <vipin@cbio.mskcc.org>
parents:
diff
changeset
|
76 printGTF(Transcriptdb) |