annotate gene_identification.py @ 0:c33d93683a09 draft

Uploaded
author davidvanzessen
date Thu, 13 Oct 2016 10:52:24 -0400
parents
children 012a738edf5a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
1 import re
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
2 import argparse
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
3 import time
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
4 starttime= int(time.time() * 1000)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
5
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
6 parser = argparse.ArgumentParser()
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
7 parser.add_argument("--input", help="The 1_Summary file from an IMGT zip file")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
8 parser.add_argument("--output", help="The annotated output file to be merged back with the summary file")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
9
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
10 args = parser.parse_args()
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
11
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
12 infile = args.input
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
13 #infile = "test_VH-Ca_Cg_25nt/1_Summary_test_VH-Ca_Cg_25nt_241013.txt"
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
14 output = args.output
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
15 #outfile = "identified.txt"
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
16
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
17 dic = dict()
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
18 total = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
19
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
20
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
21 first = True
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
22 IDIndex = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
23 seqIndex = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
24
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
25 with open(infile, 'r') as f: #read all sequences into a dictionary as key = ID, value = sequence
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
26 for line in f:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
27 total += 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
28 linesplt = line.split("\t")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
29 if first:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
30 print "linesplt", linesplt
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
31 IDIndex = linesplt.index("Sequence ID")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
32 seqIndex = linesplt.index("Sequence")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
33 first = False
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
34 continue
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
35
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
36 ID = linesplt[IDIndex]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
37 if len(linesplt) < 28: #weird rows without a sequence
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
38 dic[ID] = ""
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
39 else:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
40 dic[ID] = linesplt[seqIndex]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
41
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
42 print "Number of input sequences:", len(dic)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
43
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
44 #old cm sequence: gggagtgcatccgccccaacccttttccccctcgtctcctgtgagaattccc
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
45 #old cg sequence: ctccaccaagggcccatcggtcttccccctggcaccctcctccaagagcacctctgggggcacagcggccctgggctgcctggtcaaggactacttccccgaaccggtgacggtgtcgtggaactcaggcgccctgaccag
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
46
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
47 #lambda/kappa reference sequence
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
48 searchstrings = {"ca": "catccccgaccagccccaaggtcttcccgctgagcctctgcagcacccagccagatgggaacgtggtcatcgcctgcctgg",
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
49 "cg": "ctccaccaagggcccatcggtcttccccctggcaccctcctccaagagcacctctgggggcacagcggcc",
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
50 "cm": "gggagtgcatccgccccaacc"} #new (shorter) cm sequence
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
51
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
52 compiledregex = {"ca": [],
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
53 "cg": [],
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
54 "cm": []}
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
55
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
56 #lambda/kappa reference sequence variable nucleotides
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
57 ca1 = {38: 't', 39: 'g', 48: 'a', 49: 'g', 51: 'c', 68: 'a', 73: 'c'}
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
58 ca2 = {38: 'g', 39: 'a', 48: 'c', 49: 'c', 51: 'a', 68: 'g', 73: 'a'}
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
59 cg1 = {0: 'c', 33: 'a', 38: 'c', 44: 'a', 54: 't', 56: 'g', 58: 'g', 66: 'g', 132: 'c'}
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
60 cg2 = {0: 'c', 33: 'g', 38: 'g', 44: 'g', 54: 'c', 56: 'a', 58: 'a', 66: 'g', 132: 't'}
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
61 cg3 = {0: 't', 33: 'g', 38: 'g', 44: 'g', 54: 't', 56: 'g', 58: 'g', 66: 'g', 132: 'c'}
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
62 cg4 = {0: 't', 33: 'g', 38: 'g', 44: 'g', 54: 'c', 56: 'a', 58: 'a', 66: 'c', 132: 'c'}
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
63
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
64 #remove last snp for shorter cg sequence --- note, also change varsInCG
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
65 del cg1[132]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
66 del cg2[132]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
67 del cg3[132]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
68 del cg4[132]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
69
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
70 #reference sequences are cut into smaller parts of 'chunklength' length, and with 'chunklength' / 2 overlap
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
71 chunklength = 8
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
72
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
73 #create the chunks of the reference sequence with regular expressions for the variable nucleotides
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
74 for i in range(0, len(searchstrings["ca"]) - chunklength, chunklength / 2):
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
75 pos = i
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
76 chunk = searchstrings["ca"][i:i+chunklength]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
77 result = ""
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
78 varsInResult = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
79 for c in chunk:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
80 if pos in ca1.keys():
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
81 varsInResult += 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
82 result += "[" + ca1[pos] + ca2[pos] + "]"
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
83 else:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
84 result += c
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
85 pos += 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
86 compiledregex["ca"].append((re.compile(result), varsInResult))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
87
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
88 for i in range(0, len(searchstrings["cg"]) - chunklength, chunklength / 2):
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
89 pos = i
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
90 chunk = searchstrings["cg"][i:i+chunklength]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
91 result = ""
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
92 varsInResult = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
93 for c in chunk:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
94 if pos in cg1.keys():
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
95 varsInResult += 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
96 result += "[" + "".join(set([cg1[pos], cg2[pos], cg3[pos], cg4[pos]])) + "]"
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
97 else:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
98 result += c
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
99 pos += 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
100 compiledregex["cg"].append((re.compile(result), varsInResult))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
101
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
102 for i in range(0, len(searchstrings["cm"]) - chunklength, chunklength / 2):
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
103 compiledregex["cm"].append((re.compile(searchstrings["cm"][i:i+chunklength]), False))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
104
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
105
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
106
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
107 def removeAndReturnMaxIndex(x): #simplifies a list comprehension
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
108 m = max(x)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
109 index = x.index(m)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
110 x[index] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
111 return index
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
112
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
113
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
114 start_location = dict()
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
115 hits = dict()
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
116 alltotal = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
117 for key in compiledregex.keys(): #for ca/cg/cm
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
118 regularexpressions = compiledregex[key] #get the compiled regular expressions
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
119 for ID in dic.keys()[0:]: #for every ID
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
120 if ID not in hits.keys(): #ensure that the dictionairy that keeps track of the hits for every gene exists
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
121 hits[ID] = {"ca_hits": 0, "cg_hits": 0, "cm_hits": 0, "ca1": 0, "ca2": 0, "cg1": 0, "cg2": 0, "cg3": 0, "cg4": 0}
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
122 currentIDHits = hits[ID]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
123 seq = dic[ID]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
124 lastindex = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
125 start_zero = len(searchstrings[key]) #allows the reference sequence to start before search sequence (start_locations of < 0)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
126 start = [0] * (len(seq) + start_zero)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
127 for i, regexp in enumerate(regularexpressions): #for every regular expression
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
128 relativeStartLocation = lastindex - (chunklength / 2) * i
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
129 if relativeStartLocation >= len(seq):
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
130 break
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
131 regex, hasVar = regexp
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
132 matches = regex.finditer(seq[lastindex:])
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
133 for match in matches: #for every match with the current regex, only uses the first hit
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
134 lastindex += match.start()
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
135 start[relativeStartLocation + start_zero] += 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
136 if hasVar: #if the regex has a variable nt in it
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
137 chunkstart = chunklength / 2 * i #where in the reference does this chunk start
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
138 chunkend = chunklength / 2 * i + chunklength #where in the reference does this chunk end
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
139 if key == "ca": #just calculate the variable nt score for 'ca', cheaper
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
140 currentIDHits["ca1"] += len([1 for x in ca1 if chunkstart <= x < chunkend and ca1[x] == seq[lastindex + x - chunkstart]])
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
141 currentIDHits["ca2"] += len([1 for x in ca2 if chunkstart <= x < chunkend and ca2[x] == seq[lastindex + x - chunkstart]])
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
142 elif key == "cg": #just calculate the variable nt score for 'cg', cheaper
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
143 currentIDHits["cg1"] += len([1 for x in cg1 if chunkstart <= x < chunkend and cg1[x] == seq[lastindex + x - chunkstart]])
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
144 currentIDHits["cg2"] += len([1 for x in cg2 if chunkstart <= x < chunkend and cg2[x] == seq[lastindex + x - chunkstart]])
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
145 currentIDHits["cg3"] += len([1 for x in cg3 if chunkstart <= x < chunkend and cg3[x] == seq[lastindex + x - chunkstart]])
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
146 currentIDHits["cg4"] += len([1 for x in cg4 if chunkstart <= x < chunkend and cg4[x] == seq[lastindex + x - chunkstart]])
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
147 else: #key == "cm" #no variable regions in 'cm'
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
148 pass
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
149 break #this only breaks when there was a match with the regex, breaking means the 'else:' clause is skipped
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
150 else: #only runs if there were no hits
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
151 continue
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
152 #print "found ", regex.pattern , "at", lastindex, "adding one to", (lastindex - chunklength / 2 * i), "to the start array of", ID, "gene", key, "it's now:", start[lastindex - chunklength / 2 * i]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
153 currentIDHits[key + "_hits"] += 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
154 start_location[ID + "_" + key] = str([(removeAndReturnMaxIndex(start) + 1 - start_zero) for x in range(5) if len(start) > 0 and max(start) > 1])
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
155 #start_location[ID + "_" + key] = str(start.index(max(start)))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
156
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
157
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
158 chunksInCA = len(compiledregex["ca"])
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
159 chunksInCG = len(compiledregex["cg"])
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
160 chunksInCM = len(compiledregex["cm"])
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
161 requiredChunkPercentage = 0.7
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
162 varsInCA = float(len(ca1.keys()) * 2)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
163 varsInCG = float(len(cg1.keys()) * 2) - 2 # -2 because the sliding window doesn't hit the first and last nt twice
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
164 varsInCM = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
165
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
166
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
167
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
168 first = True
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
169 seq_write_count=0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
170 with open(infile, 'r') as f: #read all sequences into a dictionary as key = ID, value = sequence
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
171 with open(output, 'w') as o:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
172 for line in f:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
173 total += 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
174 if first:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
175 o.write("Sequence ID\tbest_match\tnt_hit_percentage\tchunk_hit_percentage\tstart_locations\n")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
176 first = False
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
177 continue
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
178 linesplt = line.split("\t")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
179 if linesplt[2] == "No results":
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
180 pass
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
181 ID = linesplt[1]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
182 currentIDHits = hits[ID]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
183 possibleca = float(len(compiledregex["ca"]))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
184 possiblecg = float(len(compiledregex["cg"]))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
185 possiblecm = float(len(compiledregex["cm"]))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
186 cahits = currentIDHits["ca_hits"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
187 cghits = currentIDHits["cg_hits"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
188 cmhits = currentIDHits["cm_hits"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
189 if cahits >= cghits and cahits >= cmhits: #its a ca gene
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
190 ca1hits = currentIDHits["ca1"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
191 ca2hits = currentIDHits["ca2"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
192 if ca1hits >= ca2hits:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
193 o.write(ID + "\tIGA1\t" + str(int(ca1hits / varsInCA * 100)) + "\t" + str(int(cahits / possibleca * 100)) + "\t" + start_location[ID + "_ca"] + "\n")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
194 else:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
195 o.write(ID + "\tIGA2\t" + str(int(ca2hits / varsInCA * 100)) + "\t" + str(int(cahits / possibleca * 100)) + "\t" + start_location[ID + "_ca"] + "\n")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
196 elif cghits >= cahits and cghits >= cmhits: #its a cg gene
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
197 cg1hits = currentIDHits["cg1"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
198 cg2hits = currentIDHits["cg2"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
199 cg3hits = currentIDHits["cg3"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
200 cg4hits = currentIDHits["cg4"]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
201 if cg1hits >= cg2hits and cg1hits >= cg3hits and cg1hits >= cg4hits: #cg1 gene
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
202 o.write(ID + "\tIGG1\t" + str(int(cg1hits / varsInCG * 100)) + "\t" + str(int(cghits / possiblecg * 100)) + "\t" + start_location[ID + "_cg"] + "\n")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
203 elif cg2hits >= cg1hits and cg2hits >= cg3hits and cg2hits >= cg4hits: #cg2 gene
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
204 o.write(ID + "\tIGG2\t" + str(int(cg2hits / varsInCG * 100)) + "\t" + str(int(cghits / possiblecg * 100)) + "\t" + start_location[ID + "_cg"] + "\n")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
205 elif cg3hits >= cg1hits and cg3hits >= cg2hits and cg3hits >= cg4hits: #cg3 gene
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
206 o.write(ID + "\tIGG3\t" + str(int(cg3hits / varsInCG * 100)) + "\t" + str(int(cghits / possiblecg * 100)) + "\t" + start_location[ID + "_cg"] + "\n")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
207 else: #cg4 gene
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
208 o.write(ID + "\tIGG4\t" + str(int(cg4hits / varsInCG * 100)) + "\t" + str(int(cghits / possiblecg * 100)) + "\t" + start_location[ID + "_cg"] + "\n")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
209 else: #its a cm gene
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
210 o.write(ID + "\tIGM\t100\t" + str(int(cmhits / possiblecm * 100)) + "\t" + start_location[ID + "_cg"] + "\n")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
211 seq_write_count += 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
212
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
213 print "Time: %i" % (int(time.time() * 1000) - starttime)
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
214
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
215 print "Number of sequences written to file:", seq_write_count
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
216
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
217
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
218
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
219
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
220