Support for Gff version 3 which will be coming from GMOD applications (wormbase, hapmap, etc).

This commit is contained in:
Greg Von Kuster
2007-06-26 15:43:57 +00:00
parent 1e8c4155bf
commit a7336bfaa5
3 changed files with 221 additions and 2 deletions
+70 -1
View File
@@ -5,6 +5,8 @@ import logging, sys, os, csv, tempfile, shutil, re
log = logging.getLogger(__name__)
valid_strand = ['+', '-', '.']
valid_gff3_strand = ['+', '-', '.', '?']
valid_gff3_phase = ['.', '0', '1', '2']
def get_test_fname(fname):
"""Returns test data filename"""
@@ -187,6 +189,70 @@ def is_gff(headers):
except:
return False
def is_gff3(headers):
"""
Determines wether the file is in gff version 3 format
GFF 3 format:
1) adds a mechanism for representing more than one level
of hierarchical grouping of features and subfeatures.
2) separates the ideas of group membership and feature name/id
3) constrains the feature type field to be taken from a controlled
vocabulary.
4) allows a single feature, such as an exon, to belong to more than
one group at a time.
5) provides an explicit convention for pairwise alignments
6) provides an explicit convention for features that occupy disjunct regions
The format consists of 9 columns, separated by tabs (NOT spaces).
Undefined fields are replaced with the "." character, as described in the original GFF spec.
For complete details see http://song.sourceforge.net/gff3.shtml
>>> headers = get_headers(__file__, sep=' ')
>>> is_fasta(headers)
False
>>> fname = get_test_fname('test.gff')
>>> headers = get_headers(fname,sep='\\t')
>>> is_gff(headers)
True
"""
try:
if len(headers) < 2:
return False
for idx, hdr in enumerate(headers):
if len(hdr) > 1 and hdr[0] != '' and not hdr[0].startswith( '#' ):
if len(hdr) != 9:
return False
try:
map( int, [hdr[3]] )
except:
if hdr[3] != '.':
return False
try:
map( int, [hdr[4]] )
except:
if hdr[4] != '.':
return False
if hdr[5] != '.':
try:
score = int(hdr[5])
except:
return False
if (score < 0 or score > 1000):
return False
if hdr[6] not in valid_gff3_strand:
return False
if hdr[7] not in valid_gff3_phase:
return False
if idx > 29:
break
return True
except:
return False
def is_maf(headers):
"""
Determines wether the file is in maf format
@@ -475,6 +541,9 @@ def guess_ext(fname):
>>> fname = get_test_fname('test.gff')
>>> guess_ext(fname)
'gff'
>>> fname = get_test_fname('gff_version_3.gff')
>>> guess_ext(fname)
'gff'
>>> fname = get_test_fname('temp.txt')
>>> file(fname, 'wt').write("a 2\\nc 1")
>>> guess_ext(fname)
@@ -513,7 +582,7 @@ def guess_ext(fname):
if is_column_based(fname, sep='\t'):
headers = get_headers(fname, sep='\t')
if is_gff(headers):
if is_gff(headers) or is_gff3(headers):
return 'gff'
elif is_column_based(fname, sep=' '):
sep2tabs(fname)
+150
View File
@@ -0,0 +1,150 @@
##gff-version 3
##date Tue Jun 26 10:48:17 2007
##sequence-region ctgA 1 50000
##source gbrowse GFFToGalaxyDumper plugin
##NOTE: All features dumped.
ctgA example my_feature 22132 24633 . + . ID=My_feature:f15
ctgA example my_feature 46990 48410 . - . ID=My_feature:f11
ctgA example my_feature 44705 47713 . - . ID=My_feature:f01
ctgA example my_feature 36649 40440 . - . ID=My_feature:f03
ctgA example my_feature 23072 23185 . + . ID=My_feature:f14
ctgA example my_feature 37242 38653 . + . ID=My_feature:f04
ctgA example motif 37497 40559 . - . ID=Motif:m15;Note=7-transmembrane
ctgA example my_feature 36034 38167 . + . ID=My_feature:f09
ctgA example motif 28332 30033 . - . ID=Motif:m02;Note=HOX
ctgA example my_feature 4715 5968 . - . ID=My_feature:f05
ctgA example motif 48253 48366 . + . ID=Motif:m01;Note=WD40
ctgA example BAC 1000 20000 . . . ID=BAC:b101.2;Note=Fingerprinted+BAC+with+end+reads
ctgA example right_end_read 19500 20000 . - . Parent=BAC:b101.2
ctgA example left_end_read 1000 1500 . + . Parent=BAC:b101.2
ctgA example motif 13801 14007 . - . ID=Motif:m05;Note=helix+loop+helix
ctgA example coding 1050 9000 . + . ID=mRNA:EDEN.1;Gene=EDEN
ctgA example CDS 1201 1500 . + 0 Parent=mRNA:EDEN.1
ctgA example CDS 3000 3902 . + 0 Parent=mRNA:EDEN.1
ctgA example CDS 5000 5500 . + 0 Parent=mRNA:EDEN.1
ctgA example CDS 7000 7608 . + 0 Parent=mRNA:EDEN.1
ctgA example processed_transcript 1050 9000 . + . ID=mRNA:EDEN.1
ctgA example 5'-UTR 1050 1200 . + . Parent=mRNA:EDEN.1
ctgA example 3'-UTR 7609 9000 . + . Parent=mRNA:EDEN.1
ctgA est match 5410 7503 . - . ID=EST:agt830.3;Target=agt830.3+1+595
ctgA est HSP 7000 7503 . - . Parent=EST:agt830.3;Target=agt830.3+1+504
ctgA est HSP 5410 5500 . - . Parent=EST:agt830.3;Target=agt830.3+505+595
ctgA example motif 46012 48851 . + . ID=Motif:m09;Note=kinase
ctgA example match 6885 8999 . - . ID=Match:seg03
ctgA example HSP 8306 8999 . - . Parent=Match:seg03
ctgA example HSP 8055 8080 . - . Parent=Match:seg03
ctgA example HSP 7410 7737 . - . Parent=Match:seg03
ctgA example HSP 6885 7241 . - . Parent=Match:seg03
ctgA example my_feature 13280 16394 . + . ID=My_feature:f08
ctgA example match 29771 32937 . + . ID=Match:seg10
ctgA example HSP 29771 29942 . + . Parent=Match:seg10
ctgA example HSP 30042 30340 . + . Parent=Match:seg10
ctgA example HSP 30810 31307 . + . Parent=Match:seg10
ctgA example HSP 31761 31984 . + . Parent=Match:seg10
ctgA example HSP 32374 32937 . + . Parent=Match:seg10
ctgA example match 36616 37227 . - . ID=Match:seg09
ctgA example HSP 37208 37227 . - . Parent=Match:seg09
ctgA example HSP 36616 37057 . - . Parent=Match:seg09
ctgA example motif 11911 15561 . + . ID=Motif:m11;Note=kinase
ctgA est match 1050 3202 . + . ID=EST:agt830.5;Target=agt830.5+1+654
ctgA est HSP 1050 1500 . + . Parent=EST:agt830.5;Target=agt830.5+1+451
ctgA est HSP 3000 3202 . + . Parent=EST:agt830.5;Target=agt830.5+452+654
ctgA example motif 15396 16159 . + . ID=Motif:m03;Note=zinc+finger
ctgA est match 1150 7200 . + . ID=EST:agt767.5;Target=agt767.5+1+1153
ctgA est HSP 1150 1500 . + . Parent=EST:agt767.5;Target=agt767.5+1+351
ctgA est HSP 5000 5500 . + . Parent=EST:agt767.5;Target=agt767.5+352+852
ctgA est HSP 7000 7200 . + . Parent=EST:agt767.5;Target=agt767.5+853+1153
ctgA est match 1050 7300 . + . ID=EST:agt221.5;Target=agt221.5+1+1253
ctgA est HSP 1050 1500 . + . Parent=EST:agt221.5;Target=agt221.5+1+451
ctgA est HSP 5000 5500 . + . Parent=EST:agt221.5;Target=agt221.5+452+952
ctgA est HSP 7000 7300 . + . Parent=EST:agt221.5;Target=agt221.5+953+1253
ctgA example my_feature 19157 22915 . - . ID=My_feature:f13
ctgA est match 8000 9000 . - . ID=EST:agt767.3;Target=agt767.3+1+1001
ctgA est HSP 8000 9000 . - . Parent=EST:agt767.3;Target=agt767.3+1+1001
ctgA example motif 28342 28447 . - . ID=Motif:m10;Note=DEAD+box
ctgA example motif 17667 17690 . + . ID=Motif:m13;Note=DEAD+box
ctgA example trace 44401 45925 . + . ID=name:trace;trace=volvox_trace.scf
ctgA example match 26122 34466 . + . ID=Match:seg02
ctgA example HSP 26122 26126 . + . Parent=Match:seg02
ctgA example HSP 26497 26869 . + . Parent=Match:seg02
ctgA example HSP 27201 27325 . + . Parent=Match:seg02
ctgA example HSP 27372 27433 . + . Parent=Match:seg02
ctgA example HSP 27565 27565 . + . Parent=Match:seg02
ctgA example HSP 27813 28091 . + . Parent=Match:seg02
ctgA example HSP 28093 28201 . + . Parent=Match:seg02
ctgA example HSP 28329 28377 . + . Parent=Match:seg02
ctgA example HSP 28829 29194 . + . Parent=Match:seg02
ctgA example HSP 29517 29702 . + . Parent=Match:seg02
ctgA example HSP 29713 30061 . + . Parent=Match:seg02
ctgA example HSP 30329 30774 . + . Parent=Match:seg02
ctgA example HSP 30808 31306 . + . Parent=Match:seg02
ctgA example HSP 31516 31729 . + . Parent=Match:seg02
ctgA example HSP 31753 32154 . + . Parent=Match:seg02
ctgA example HSP 32595 32696 . + . Parent=Match:seg02
ctgA example HSP 32892 32901 . + . Parent=Match:seg02
ctgA example HSP 33127 33388 . + . Parent=Match:seg02
ctgA example HSP 33439 33443 . + . Parent=Match:seg02
ctgA example HSP 33759 34209 . + . Parent=Match:seg02
ctgA example HSP 34401 34466 . + . Parent=Match:seg02
ctgA example contig 1 50000 . . . ID=Contig:ctgA
ctgA example match 41137 47829 . - . ID=Match:seg14
ctgA example HSP 47449 47829 . - . Parent=Match:seg14
ctgA example HSP 46816 46992 . - . Parent=Match:seg14
ctgA example HSP 46092 46318 . - . Parent=Match:seg14
ctgA example HSP 45790 46022 . - . Parent=Match:seg14
ctgA example HSP 45231 45488 . - . Parent=Match:seg14
ctgA example HSP 44763 45030 . - . Parent=Match:seg14
ctgA example HSP 44065 44556 . - . Parent=Match:seg14
ctgA example HSP 43395 43811 . - . Parent=Match:seg14
ctgA example HSP 42890 43270 . - . Parent=Match:seg14
ctgA example HSP 42057 42474 . - . Parent=Match:seg14
ctgA example HSP 41754 41948 . - . Parent=Match:seg14
ctgA example HSP 41137 41318 . - . Parent=Match:seg14
ctgA example match 12531 15870 . + . ID=Match:seg12
ctgA example HSP 12531 12895 . + . Parent=Match:seg12
ctgA example HSP 13122 13449 . + . Parent=Match:seg12
ctgA example HSP 13452 13745 . + . Parent=Match:seg12
ctgA example HSP 13908 13965 . + . Parent=Match:seg12
ctgA example HSP 13998 14488 . + . Parent=Match:seg12
ctgA example HSP 14564 14899 . + . Parent=Match:seg12
ctgA example HSP 15185 15276 . + . Parent=Match:seg12
ctgA example HSP 15639 15736 . + . Parent=Match:seg12
ctgA example HSP 15745 15870 . + . Parent=Match:seg12
ctgA est match 7500 8000 . - . ID=EST:agt221.3;Target=agt221.3+1+501
ctgA est HSP 7500 8000 . - . Parent=EST:agt221.3;Target=agt221.3+1+501
ctgA example coding 1300 9000 . + . ID=mRNA:EDEN.3;Gene=EDEN
ctgA example CDS 3301 3902 . + 0 Parent=mRNA:EDEN.3
ctgA example CDS 5000 5500 . + 1 Parent=mRNA:EDEN.3
ctgA example CDS 7000 7600 . + 1 Parent=mRNA:EDEN.3
ctgA example processed_transcript 1300 9000 . + . ID=mRNA:EDEN.3
ctgA example 5'-UTR 1300 1500 . + . Parent=mRNA:EDEN.3
ctgA example 5'-UTR 3000 3300 . + . Parent=mRNA:EDEN.3
ctgA example 3'-UTR 7601 9000 . + . Parent=mRNA:EDEN.3
ctgA example match 26503 35904 . - . ID=Match:seg05
ctgA example HSP 35642 35904 . - . Parent=Match:seg05
ctgA example HSP 35333 35507 . - . Parent=Match:seg05
ctgA example HSP 34605 34983 . - . Parent=Match:seg05
ctgA example HSP 34244 34313 . - . Parent=Match:seg05
ctgA example HSP 33438 33868 . - . Parent=Match:seg05
ctgA example HSP 33053 33325 . - . Parent=Match:seg05
ctgA example HSP 32208 32680 . - . Parent=Match:seg05
ctgA example HSP 32010 32057 . - . Parent=Match:seg05
ctgA example HSP 31421 31817 . - . Parent=Match:seg05
ctgA example HSP 31232 31236 . - . Parent=Match:seg05
ctgA example HSP 30465 30798 . - . Parent=Match:seg05
ctgA example HSP 30108 30216 . - . Parent=Match:seg05
ctgA example HSP 29513 29647 . - . Parent=Match:seg05
ctgA example HSP 28777 29058 . - . Parent=Match:seg05
ctgA example HSP 28225 28316 . - . Parent=Match:seg05
ctgA example HSP 27887 28076 . - . Parent=Match:seg05
ctgA example HSP 27448 27860 . - . Parent=Match:seg05
ctgA example HSP 27172 27185 . - . Parent=Match:seg05
ctgA example HSP 26503 26799 . - . Parent=Match:seg05
ctgA example match 49406 50000 . + . ID=Match:seg13
ctgA example HSP 49406 49476 . + . Parent=Match:seg13
ctgA example HSP 49762 50000 . + . Parent=Match:seg13
ctgA example gene 1050 9000 . + . ID=Gene:EDEN;Note=protein+kinase
ctgA example motif 33325 35791 . + . ID=Motif:m04;Note=Ig-like
ctgA example match 31785 32359 . + . ID=Match:seg01
ctgA example HSP 31785 31939 . + . Parent=Match:seg01
ctgA example HSP 32329 32359 . + . Parent=Match:seg01
+1 -1
View File
@@ -112,7 +112,7 @@ A sequence in FASTA format consists of a single-line description, followed by li
**Gff**
GFF lines have nine required fields that must be tab-separated.
GFF lines have nine required fields that must be tab-separated. Gff version 3 is also supported.
-----