comparison RScript.r @ 50:7dd7cefcf72d draft

Uploaded
author davidvanzessen
date Thu, 08 Oct 2015 10:07:28 -0400
parents 7658e9f3d416
children 17e677c72e49
comparison
equal deleted inserted replaced
49:7658e9f3d416 50:7dd7cefcf72d
188 second.match.filter = merge.filter & sequence.filter & second.sample.filter 188 second.match.filter = merge.filter & sequence.filter & second.sample.filter
189 189
190 first.rows = patient.fuzzy[first.match.filter,] 190 first.rows = patient.fuzzy[first.match.filter,]
191 second.rows = patient.fuzzy[second.match.filter,] 191 second.rows = patient.fuzzy[second.match.filter,]
192 192
193 first.rows.v = table(first.rows$V_Segment_Major_Gene)
194 first.rows.v = names(first.rows.v[which.max(first.rows.v)])
195 first.rows.j = table(first.rows$J_Segment_Major_Gene)
196 first.rows.j = names(first.rows.j[which.max(first.rows.j)])
197
193 first.sum = data.frame(merge = first.clone.sequence, 198 first.sum = data.frame(merge = first.clone.sequence,
194 Patient = patient, 199 Patient = patient,
195 Receptor = first.rows[1,"Receptor"], 200 Receptor = first.rows[1,"Receptor"],
196 Sample = first.rows[1,"Sample"], 201 Sample = first.rows[1,"Sample"],
197 Cell_Count = first.rows[1,"Cell_Count"], 202 Cell_Count = first.rows[1,"Cell_Count"],
198 Clone_Molecule_Count_From_Spikes = sum(first.rows$Clone_Molecule_Count_From_Spikes), 203 Clone_Molecule_Count_From_Spikes = sum(first.rows$Clone_Molecule_Count_From_Spikes),
199 Log10_Frequency = log10(sum(first.rows$Frequency)), 204 Log10_Frequency = log10(sum(first.rows$Frequency)),
200 Total_Read_Count = sum(first.rows$Total_Read_Count), 205 Total_Read_Count = sum(first.rows$Total_Read_Count),
201 dsPerM = sum(first.rows$dsPerM), 206 dsPerM = sum(first.rows$dsPerM),
202 J_Segment_Major_Gene = sort(table(first.rows$J_Segment_Major_Gene),decreasing=TRUE)[1], 207 J_Segment_Major_Gene = first.rows.j,
203 V_Segment_Major_Gene = sort(table(first.rows$V_Segment_Major_Gene),decreasing=TRUE)[1], 208 V_Segment_Major_Gene = first.rows.v,
204 Clone_Sequence = first.clone.sequence, 209 Clone_Sequence = first.clone.sequence,
205 CDR3_Sense_Sequence = first.rows[1,"CDR3_Sense_Sequence"], 210 CDR3_Sense_Sequence = first.rows[1,"CDR3_Sense_Sequence"],
206 Related_to_leukemia_clone = F, 211 Related_to_leukemia_clone = F,
207 Frequency = sum(first.rows$Frequency), 212 Frequency = sum(first.rows$Frequency),
208 locus_V = first.rows[1,"locus_V"], 213 locus_V = first.rows[1,"locus_V"],
211 normalized_read_count = sum(first.rows$normalized_read_count), 216 normalized_read_count = sum(first.rows$normalized_read_count),
212 paste = first.rows[1,"paste"], 217 paste = first.rows[1,"paste"],
213 min_cell_paste = first.rows[1,"min_cell_paste"]) 218 min_cell_paste = first.rows[1,"min_cell_paste"])
214 219
215 if(nrow(second.rows) > 0){ 220 if(nrow(second.rows) > 0){
221 second.rows.v = table(second.rows$V_Segment_Major_Gene)
222 second.rows.v = names(second.rows.v[which.max(second.rows.v)])
223 second.rows.j = table(second.rows$J_Segment_Major_Gene)
224 second.rows.j = names(second.rows.j[which.max(second.rows.j)])
225
216 second.sum = data.frame(merge = first.clone.sequence, 226 second.sum = data.frame(merge = first.clone.sequence,
217 Patient = patient, 227 Patient = patient,
218 Receptor = second.rows[1,"Receptor"], 228 Receptor = second.rows[1,"Receptor"],
219 Sample = second.rows[1,"Sample"], 229 Sample = second.rows[1,"Sample"],
220 Cell_Count = second.rows[1,"Cell_Count"], 230 Cell_Count = second.rows[1,"Cell_Count"],
221 Clone_Molecule_Count_From_Spikes = sum(second.rows$Clone_Molecule_Count_From_Spikes), 231 Clone_Molecule_Count_From_Spikes = sum(second.rows$Clone_Molecule_Count_From_Spikes),
222 Log10_Frequency = log10(sum(second.rows$Frequency)), 232 Log10_Frequency = log10(sum(second.rows$Frequency)),
223 Total_Read_Count = sum(second.rows$Total_Read_Count), 233 Total_Read_Count = sum(second.rows$Total_Read_Count),
224 dsPerM = sum(second.rows$dsPerM), 234 dsPerM = sum(second.rows$dsPerM),
225 J_Segment_Major_Gene = sort(table(second.rows$J_Segment_Major_Gene),decreasing=TRUE)[1], 235 J_Segment_Major_Gene = second.rows.j,
226 V_Segment_Major_Gene = sort(table(second.rows$V_Segment_Major_Gene),decreasing=TRUE)[1], 236 V_Segment_Major_Gene = second.rows.v,
227 Clone_Sequence = first.clone.sequence, 237 Clone_Sequence = first.clone.sequence,
228 CDR3_Sense_Sequence = second.rows[1,"CDR3_Sense_Sequence"], 238 CDR3_Sense_Sequence = second.rows[1,"CDR3_Sense_Sequence"],
229 Related_to_leukemia_clone = F, 239 Related_to_leukemia_clone = F,
230 Frequency = sum(second.rows$Frequency), 240 Frequency = sum(second.rows$Frequency),
231 locus_V = second.rows[1,"locus_V"], 241 locus_V = second.rows[1,"locus_V"],
236 min_cell_paste = second.rows[1,"min_cell_paste"]) 246 min_cell_paste = second.rows[1,"min_cell_paste"])
237 247
238 patientMerge = rbind(patientMerge, merge(first.sum, second.sum, by="merge")) 248 patientMerge = rbind(patientMerge, merge(first.sum, second.sum, by="merge"))
239 patient.fuzzy = patient.fuzzy[!(first.match.filter | second.match.filter),] 249 patient.fuzzy = patient.fuzzy[!(first.match.filter | second.match.filter),]
240 250
251 hidden.clone.sequences = c(first.rows[-1,"Clone_Sequence"], second.rows[second.rows$Clone_Sequence != first.clone.sequence,"Clone_Sequence"])
252 merge.list[["second"]] = append(merge.list[["second"]], hidden.clone.sequences)
241 253
242 if(sum(first.match.filter) == 1 & sum(second.match.filter) == 1){ 254 if(sum(first.match.filter) == 1 & sum(second.match.filter) == 1){
243 second.clone.sequence = patient.fuzzy[second.match.filter, "Clone_Sequence"] 255 second.clone.sequence = patient.fuzzy[second.match.filter, "Clone_Sequence"]
244 if(nchar(first.clone.sequence) == nchar(second.clone.sequence)){ 256 if(first.clone.sequence != second.clone.sequence){
245 merge.list[["second"]] = append(merge.list[["second"]], second.clone.sequence) 257 #merge.list[["second"]] = append(merge.list[["second"]], second.clone.sequence)
246 } 258 }
247 } 259 }
248 260
249 if(nrow(first.rows) > 1 | nrow(second.rows) > 1){ 261 if(nrow(first.rows) > 1 | nrow(second.rows) > 1){
250 262