-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTSS_putative.py
70 lines (42 loc) · 1.52 KB
/
TSS_putative.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
60
61
62
63
64
65
66
67
68
69
70
from Bio.Seq import Seq
from Bio import SeqIO
import warnings
import re
import sys
import os
from os import remove
from os import path
def parse_fasta(file):
return SeqIO.parse(file, "fasta")
def calculate_orf_without_partial_codon(seq,id):
warnings.filterwarnings("ignore")
table = 1
min_pro_len = 100
for strand, nuc in [(+1, seq), (-1, seq.reverse_complement())]:
file = open("TSS_pos.txt", "a")
for frame in range(3):
for pro in nuc[frame:].translate(table).split("*"):
if len(pro) >= min_pro_len:
first_Met = pro.find('M')
if first_Met>-1:
print ("Gene: %s - %s...[ %s ]...%s - Length: %i, Strand: %i, Frame: %i, M-pos: %i" % (id,pro[:10],pro[first_Met:first_Met+1], pro[-10:], len(pro), strand, frame,first_Met))
file.write(id+"\t"+str(first_Met*3)+"\n")
return
file.close()
def main():
if(len(sys.argv)==1):
print("\n***\n")
print("ERROR: missing .fasta file")
return
print ("Looking for TSS's in fasta: ",sys.argv[1])
print("\n***\n")
fasta_file=sys.argv[1]
if path.exists("TSS_pos.txt"):
remove("TSS_pos.txt")
data = []
for record in parse_fasta(fasta_file):
calculate_orf_without_partial_codon(record.seq,record.id)
print("\n***\n")
print("An output has been generated with the TSS positions of each sequence: TSS_pos.txt")
if __name__ == "__main__":
main()