annotate reformat.py @ 0:20f12e7c279b draft

Imported from capsule None
author bgruening
date Mon, 05 May 2014 04:23:26 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
1 #!/usr/bin/env python
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
2
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
3 """
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
4 Extract importent information from the standard output file and put it in some standard format, like BED and tabular.
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
5 """
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
6
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
7 import sys
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
8
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
9 bed = open(sys.argv[2], 'w+')
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
10 tabular = open(sys.argv[3], 'w+')
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
11
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
12 for line in open(sys.argv[1]):
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
13 # Sequence 'CRISPRs' (10798 bp)
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
14 if line.startswith('Sequence '):
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
15 organism = line.split("'")[1]
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
16 # CRISPR 1 Range: 679197 - 682529
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
17 if line.startswith('CRISPR '):
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
18 start,end = line.split('Range:')[1].strip().split('-')
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
19 start = start.strip()
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
20 end = end.strip()
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
21 bed.write('%s\t%s\t%s\n' % (organism, start, end))
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
22 if line.rstrip().endswith(']'):
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
23 cols = line.split()
20f12e7c279b Imported from capsule None
bgruening
parents:
diff changeset
24 tabular.write("%s\t%s\t%s\t%s\t%s\t%s\n" % (organism, cols[0], cols[1], cols[2], cols[4].rstrip(','), cols[5]))