comparison mutation_analysis.py @ 104:603a10976e9c draft

Uploaded
author davidvanzessen
date Wed, 22 Jun 2016 10:07:28 -0400
parents 5ffbf40cdd4b
children 01c9993865af
comparison
equal deleted inserted replaced
103:e21cbe15381f 104:603a10976e9c
79 IDlist += [ID] 79 IDlist += [ID]
80 80
81 AALength = (int(max(mutationList, key=lambda i: int(i[4]) if i[4] else 0)[4]) + 1) # [4] is the position of the AA mutation, None if silent 81 AALength = (int(max(mutationList, key=lambda i: int(i[4]) if i[4] else 0)[4]) + 1) # [4] is the position of the AA mutation, None if silent
82 82
83 AA_mutation = [0] * AALength 83 AA_mutation = [0] * AALength
84 AA_mutation_dic = {"ca": AA_mutation[:], "cg": AA_mutation[:], "cm": AA_mutation[:], "un": AA_mutation[:]}
84 AA_mutation_empty = AA_mutation[:] 85 AA_mutation_empty = AA_mutation[:]
85 86
86 aa_mutations_by_id_file = outfile[:outfile.rindex("/")] + "/aa_id_mutations.txt" 87 aa_mutations_by_id_file = outfile[:outfile.rindex("/")] + "/aa_id_mutations.txt"
87 with open(aa_mutations_by_id_file, 'w') as o: 88 with open(aa_mutations_by_id_file, 'w') as o:
88 for ID in mutationListByID.keys(): 89 for ID in mutationListByID.keys():
89 AA_mutation_for_ID = AA_mutation_empty[:] 90 AA_mutation_for_ID = AA_mutation_empty[:]
90 for mutation in mutationListByID[ID]: 91 for mutation in mutationListByID[ID]:
91 if mutation[4]: 92 if mutation[4]:
92 AA_mutation[int(mutation[4])] += 1 93 AA_mutation_position = int(mutation[4])
93 AA_mutation_for_ID[int(mutation[4])] += 1 94 AA_mutation[AA_mutation_position] += 1
95 AA_mutation_for_ID[AA_mutation_position] += 1
96 clss = genedic[ID][:2]
97 AA_mutation_dic[clss][AA_mutation_position] += 1
94 o.write(ID + "\t" + "\t".join([str(x) for x in AA_mutation_for_ID[1:]]) + "\n") 98 o.write(ID + "\t" + "\t".join([str(x) for x in AA_mutation_for_ID[1:]]) + "\n")
95 99
96 100
97 101
98 #absent AA stuff 102 #absent AA stuff
145 149
146 aa_mutations_file = outfile[:outfile.rindex("/")] + "/aa_mutations.txt" 150 aa_mutations_file = outfile[:outfile.rindex("/")] + "/aa_mutations.txt"
147 with open(aa_mutations_file, 'w') as o: 151 with open(aa_mutations_file, 'w') as o:
148 o.write("row.name\t" + "\t".join([str(x) for x in range(1, AALength-1)]) + "\n") 152 o.write("row.name\t" + "\t".join([str(x) for x in range(1, AALength-1)]) + "\n")
149 o.write("mutations.at.position\t" + "\t".join([str(x) for x in AA_mutation[1:]]) + "\n") 153 o.write("mutations.at.position\t" + "\t".join([str(x) for x in AA_mutation[1:]]) + "\n")
154 o.write("AA.at.position\t" + "\t".join([str(x) for x in absentAA]) + "\n")
155
156
157 aa_mutations_file_ca = outfile[:outfile.rindex("/")] + "/aa_mutations_ca.txt"
158 with open(aa_mutations_file_ca, 'w') as o:
159 o.write("row.name\t" + "\t".join([str(x) for x in range(1, AALength-1)]) + "\n")
160 o.write("mutations.at.position\t" + "\t".join([str(x) for x in AA_mutation_dic["ca"][1:]]) + "\n")
161 o.write("AA.at.position\t" + "\t".join([str(x) for x in absentAA]) + "\n")
162
163
164 aa_mutations_file_cg = outfile[:outfile.rindex("/")] + "/aa_mutations_cg.txt"
165 with open(aa_mutations_file_cg, 'w') as o:
166 o.write("row.name\t" + "\t".join([str(x) for x in range(1, AALength-1)]) + "\n")
167 o.write("mutations.at.position\t" + "\t".join([str(x) for x in AA_mutation_dic["cg"][1:]]) + "\n")
168 o.write("AA.at.position\t" + "\t".join([str(x) for x in absentAA]) + "\n")
169
170
171 aa_mutations_file_cm = outfile[:outfile.rindex("/")] + "/aa_mutations_cm.txt"
172 with open(aa_mutations_file_cm, 'w') as o:
173 o.write("row.name\t" + "\t".join([str(x) for x in range(1, AALength-1)]) + "\n")
174 o.write("mutations.at.position\t" + "\t".join([str(x) for x in AA_mutation_dic["cg"][1:]]) + "\n")
150 o.write("AA.at.position\t" + "\t".join([str(x) for x in absentAA]) + "\n") 175 o.write("AA.at.position\t" + "\t".join([str(x) for x in absentAA]) + "\n")
151 176
152 if linecount == 0: 177 if linecount == 0:
153 print "No data, exiting" 178 print "No data, exiting"
154 with open(outfile, 'w') as o: 179 with open(outfile, 'w') as o: