comparison imgtconvert.py @ 4:021d39f6bb0e draft

Uploaded
author davidvanzessen
date Fri, 06 Jun 2014 04:34:44 -0400
parents 191d0df65d28
children 387fce4a1dd4
comparison
equal deleted inserted replaced
3:191d0df65d28 4:021d39f6bb0e
30 30
31 dirContents = os.listdir(inputFolder) 31 dirContents = os.listdir(inputFolder)
32 if len(dirContents) == 1: 32 if len(dirContents) == 1:
33 inputFolder = os.path.join(inputFolder, dirContents[0]) 33 inputFolder = os.path.join(inputFolder, dirContents[0])
34 if os.path.isdir(inputFolder): 34 if os.path.isdir(inputFolder):
35 print "is dir"
36 dirContents = os.listdir(inputFolder) 35 dirContents = os.listdir(inputFolder)
37 files = sorted([os.path.join(inputFolder, f) for f in dirContents]) 36 files = sorted([os.path.join(inputFolder, f) for f in dirContents if os.path.isfile(os.path.join(inputFolder, f))])
38 37
39 if len(files) % 3 is not 0: 38 if len(files) % 3 is not 0:
40 stop_err("Files in zip not a multiple of 3, it should contain the all the 1_, 5_ and 6_ files for a sample") 39 stop_err("Files in zip not a multiple of 3, it should contain the all the 1_, 5_ and 6_ files for a sample")
41 import sys 40 import sys
42 sys.exit() 41 sys.exit()
76 for col in added_junction_columns: 75 for col in added_junction_columns:
77 tmp[col] = fJunction[col] 76 tmp[col] = fJunction[col]
78 77
79 outFrame = tmp 78 outFrame = tmp
80 79
80
81
81 for triple in triplets[1:]: 82 for triple in triplets[1:]:
82 fSummary = pd.read_csv(triple[0], sep="\t") 83 fSummary = pd.read_csv(triple[0], sep="\t")
83 fSequence = pd.read_csv(triple[1], sep="\t") 84 fSequence = pd.read_csv(triple[1], sep="\t")
84 fJunction = pd.read_csv(triple[2], sep="\t") 85 fJunction = pd.read_csv(triple[2], sep="\t")
85 86
108 for col in added_junction_columns: 109 for col in added_junction_columns:
109 tmp[col] = fJunction[col] 110 tmp[col] = fJunction[col]
110 111
111 outFrame = outFrame.append(tmp) 112 outFrame = outFrame.append(tmp)
112 113
114
113 outFrame.columns = [u'ID', u'VDJ Frame', u'Top V Gene', u'Top D Gene', u'Top J Gene', u'CDR1 Seq', u'CDR1 Length', u'CDR2 Seq', u'CDR2 Length', u'CDR3 Seq', u'CDR3 Length', u'CDR3 Seq DNA', u'CDR3 Length DNA', u'Strand', u'CDR3 Found How', u'Functionality', 'V-REGION identity %', 'V-REGION identity nt', 'D-REGION reading frame', 'AA JUNCTION', 'Functionality comment', 'Sequence', 'FR1-IMGT', 'FR2-IMGT', 'FR3-IMGT', 'CDR3-IMGT', 'JUNCTION', 'J-REGION', 'FR4-IMGT', 'P3V-nt nb', 'N1-REGION-nt nb', 'P5D-nt nb', 'P3D-nt nb', 'N2-REGION-nt nb', 'P5J-nt nb', '3V-REGION trimmed-nt nb', '5D-REGION trimmed-nt nb', '3D-REGION trimmed-nt nb', '5J-REGION trimmed-nt nb'] 115 outFrame.columns = [u'ID', u'VDJ Frame', u'Top V Gene', u'Top D Gene', u'Top J Gene', u'CDR1 Seq', u'CDR1 Length', u'CDR2 Seq', u'CDR2 Length', u'CDR3 Seq', u'CDR3 Length', u'CDR3 Seq DNA', u'CDR3 Length DNA', u'Strand', u'CDR3 Found How', u'Functionality', 'V-REGION identity %', 'V-REGION identity nt', 'D-REGION reading frame', 'AA JUNCTION', 'Functionality comment', 'Sequence', 'FR1-IMGT', 'FR2-IMGT', 'FR3-IMGT', 'CDR3-IMGT', 'JUNCTION', 'J-REGION', 'FR4-IMGT', 'P3V-nt nb', 'N1-REGION-nt nb', 'P5D-nt nb', 'P3D-nt nb', 'N2-REGION-nt nb', 'P5J-nt nb', '3V-REGION trimmed-nt nb', '5D-REGION trimmed-nt nb', '3D-REGION trimmed-nt nb', '5J-REGION trimmed-nt nb']
114 116
115 #vPattern = re.compile(r"|TRBV[0-9]{1,2}-?[0-9]?") #mouse 117 """
116 #vPattern = re.compile(r"IGHV[1-9]-[0-9ab]+-?[1-9]?") #human 118 IGHV[0-9]-[0-9ab]+-?[0-9]?D?
117 vPattern = re.compile(r"IGHV[1-9]-[0-9ab]+-?[1-9]?|TRBV[0-9]{1,2}-?[0-9]?") #mouse and human 119 TRBV[0-9]{1,2}-?[0-9]?-?[123]?
120 IGKV[0-3]D?-[0-9]{1,2}
121 IGLV[0-9]-[0-9]{1,2}
122 TRAV[0-9]{1,2}(-[1-46])?(/DV[45678])?
123 TRGV[234589]
124 TRDV[1-3]
118 125
119 #dPattern = re.compile(r"TRBD1|TRBD2") #mouse 126 IGHD[0-9]-[0-9ab]+
120 #dPattern = re.compile(r"IGHD[1-9]-[0-9ab]+") #human 127 TRBD[12]
121 dPattern = re.compile(r"IGHD[1-9]-[0-9ab]+|TRBD1|TRBD2") #mouse and human 128 TRDD[1-3]
122 129
130 IGHJ[1-6]
131 TRBJ[12]-[1-7]
132 IGKJ[1-5]
133 IGLJ[12367]
134 TRAJ[0-9]{1,2}
135 TRGJP?[12]
136 TRDJ[1-4]
137 """
123 138
124 #jPattern = re.compile(r"TRBJ[12]-[1-7]") #mouse 139 vPattern = [r"(IGHV[0-9]-[0-9ab]+-?[0-9]?D?)",
125 #jPattern = re.compile(r"IGHJ[1-6]") #human 140 r"(TRBV[0-9]{1,2}-?[0-9]?-?[123]?)",
126 jPattern = re.compile(r"IGHJ[1-6]|TRBJ[12]-[1-7]") #mouse and human 141 r"(IGKV[0-3]D?-[0-9]{1,2})",
142 r"(IGLV[0-9]-[0-9]{1,2})",
143 r"(TRAV[0-9]{1,2}(-[1-46])?(/DV[45678])?)",
144 r"(TRGV[234589])",
145 r"(TRDV[1-3])"]
146
147 dPattern = [r"(IGHD[0-9]-[0-9ab]+)",
148 r"(TRBD[12])",
149 r"(TRDD[1-3])"]
150
151 jPattern = [r"(IGHJ[1-6])",
152 r"(TRBJ[12]-[1-7])",
153 r"(IGKJ[1-5])",
154 r"(IGLJ[12367])",
155 r"(TRAJ[0-9]{1,2})",
156 r"(TRGJP?[12])",
157 r"(TRDJ[1-4])"]
158
159 vPattern = re.compile(r"|".join(vPattern))
160
161 dPattern = re.compile(r"|".join(dPattern))
162
163 jPattern = re.compile(r"|".join(jPattern))
127 164
128 165
129 def filterGenes(s, pattern): 166 def filterGenes(s, pattern):
130 if type(s) is not str: 167 if type(s) is not str:
131 return "NA" 168 return "NA"
133 if res: 170 if res:
134 return res.group(0) 171 return res.group(0)
135 return "NA" 172 return "NA"
136 173
137 174
175
138 outFrame["Top V Gene"] = outFrame["Top V Gene"].apply(lambda x: filterGenes(x, vPattern)) 176 outFrame["Top V Gene"] = outFrame["Top V Gene"].apply(lambda x: filterGenes(x, vPattern))
139 outFrame["Top D Gene"] = outFrame["Top D Gene"].apply(lambda x: filterGenes(x, dPattern)) 177 outFrame["Top D Gene"] = outFrame["Top D Gene"].apply(lambda x: filterGenes(x, dPattern))
140 outFrame["Top J Gene"] = outFrame["Top J Gene"].apply(lambda x: filterGenes(x, jPattern)) 178 outFrame["Top J Gene"] = outFrame["Top J Gene"].apply(lambda x: filterGenes(x, jPattern))
141 179
142 180 print outFrame
143 181
144 tmp = outFrame["VDJ Frame"] 182 tmp = outFrame["VDJ Frame"]
145 tmp = tmp.replace("in-frame", "In-frame") 183 tmp = tmp.replace("in-frame", "In-frame")
146 tmp = tmp.replace("null", "Out-of-frame") 184 tmp = tmp.replace("null", "Out-of-frame")
147 tmp = tmp.replace("out-of-frame", "Out-of-frame") 185 tmp = tmp.replace("out-of-frame", "Out-of-frame")