-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathalignIsoformers.py
executable file
·60 lines (57 loc) · 1.76 KB
/
alignIsoformers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#from __future__ import division, with_statement
'''
Copyright 2010, 陈同 ([email protected]).
Please see the license file for legal information.
===========================================================
'''
__author__ = 'chentong & ct586[9]'
__author_email__ = '[email protected]'
#=========================================================
import sys
import ctIO
import os
def main():
print >>sys.stderr, "Print the result to current directory"
lenS = len(sys.argv)
if lenS != 3 and lenS != 2:
print >>sys.stderr, 'Using python %s seqfile(for.c) [locus](optional)' % sys.argv[0]
sys.exit(0)
#--------------------------------
seqDict = {}
ctIO.readseq(sys.argv[1], seqDict)
locusDict = {}
if lenS == 2:
locusL = seqDict.keys()
locusL.sort()
elif lenS == 3:
locusL = [line.strip() for line in open(sys.argv[2])]
for line in locusL:
line = line.strip()
dot = line.find('.')
locus = line[:dot]
after = line[dot:]
if locus in locusDict:
locusDict[locus].append(after)
else:
locusDict[locus] = [after]
#--------------------------------
fhl = open('locusHasIsoforms', 'w')
for locus, afterL in locusDict.items():
if len(afterL) < 2:
continue
filename = locus+'.fa'
fh = open(filename, 'w')
for after in afterL:
newLoc = locus+after
print >>fhl, newLoc
print >>fh, '>%s' % newLoc
print >>fh, seqDict[newLoc]
fh.close()
cmd = 't_coffee ' + filename
os.system(cmd)
#---------------------------
fhl.close()
if __name__ == '__main__':
main()