annotate tools/stats/count_gff_features.py @ 0:9071e359b9a3

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:37:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 #!/usr/bin/env python
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2 # This tool takes a gff file as input and counts the number of features in it.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4 import sys, fileinput
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 from galaxy import eggs
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 from galaxy.datatypes.util.gff_util import GFFReaderWrapper
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 from bx.intervals.io import GenomicInterval
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 # Get args.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 input_file = sys.argv[1:]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 # Count features.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 count = 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 for feature in GFFReaderWrapper( fileinput.FileInput( input_file ), fix_strand=True ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 if isinstance( feature, GenomicInterval ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 count += 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 print count