diff mutation_analysis.py @ 26:2433a1e110e1 draft

Uploaded
author davidvanzessen
date Wed, 08 Apr 2015 05:25:52 -0400
parents d84c9791d8c4
children 362ef99f9405
line wrap: on
line diff
--- a/mutation_analysis.py	Tue Apr 07 07:32:43 2015 -0400
+++ b/mutation_analysis.py	Wed Apr 08 05:25:52 2015 -0400
@@ -26,6 +26,9 @@
 cdr2Index = 0
 fr3Index = 0
 first=True
+IDlist = []
+mutationList = []
+
 with open(infile, 'r') as i:
   for line in i:
 		if first:
@@ -49,6 +52,23 @@
 		mutationdic[ID + "_CDR2"] = [mutationMatcher.match(x).groups() for x in linesplt[cdr2Index].split("|") if x]
 		mutationdic[ID + "_FR2-CDR2"] = mutationdic[ID + "_FR2"] + mutationdic[ID + "_CDR2"]
 		mutationdic[ID + "_FR3"] = [mutationMatcher.match(x).groups() for x in linesplt[fr3Index].split("|") if x]
+		
+		mutationList += mutationdic[ID + "_FR1"] + mutationdic[ID + "_CDR1"] + mutationdic[ID + "_FR2"] + mutationdic[ID + "_CDR2"] + mutationdic[ID + "_FR3"]
+		
+		IDlist += [ID]
+
+
+AA_mutation = [0] * (int(max(mutationList, key=lambda i:int(i[4]) if i[4] else 0)[4]) + 1)
+
+for mutation in mutationList:
+	if mutation[4]: #if non silent mutation
+		AA_mutation[int(mutation[4])] += 1
+		
+print AA_mutation
+
+aa_mutations_file = outfile[:outfile.rindex("/")] + "/aa_mutations.txt"
+with open(aa_mutations_file, 'w') as o:
+	o.write(",".join([str(x) for x in AA_mutation]) + "\n")
     
 if linecount == 0:
 	print "No data, exiting"
@@ -72,7 +92,6 @@
 aggctatIndex = 0
 atagcctIndex = 0
 first = True
-IDlist = []
 with open(infile, 'r') as i:
 	for line in i:
 		if first:
@@ -94,7 +113,7 @@
 		WRCYCount[ID] = sum([1 for (x,y,z) in WRCY if z and z != "CDR3" and any([(x <= int(where) <= y) for (frm, where, to, a,b,c,d) in mutationdic[ID + "_" + z]])])
 		WACount[ID] = sum([1 for (x,y,z) in WA if z and z != "CDR3" and any([(x <= int(where) <= y) for (frm, where, to, a,b,c,d) in mutationdic[ID + "_" + z]])])
 		TWCount[ID] = sum([1 for (x,y,z) in TW if z and z != "CDR3" and any([(x <= int(where) <= y) for (frm, where, to, a,b,c,d) in mutationdic[ID + "_" + z]])])
-		IDlist += [ID]
+		
 
 
 directory = outfile[:outfile.rfind("/") + 1]