Mercurial > repos > davidvanzessen > clonal_sequences_in_paired_samples
comparison RScript.r @ 36:d592dab2fca1 draft
Uploaded
author | davidvanzessen |
---|---|
date | Mon, 31 Aug 2015 09:28:38 -0400 |
parents | 32d8a5abed4c |
children | 623bbe972363 |
comparison
equal
deleted
inserted
replaced
35:32d8a5abed4c | 36:d592dab2fca1 |
---|---|
154 merge.list = patientMerge$merge | 154 merge.list = patientMerge$merge |
155 | 155 |
156 patient1.fuzzy = patient1[!(patient1$merge %in% merge.list),] | 156 patient1.fuzzy = patient1[!(patient1$merge %in% merge.list),] |
157 patient2.fuzzy = patient2[!(patient2$merge %in% merge.list),] | 157 patient2.fuzzy = patient2[!(patient2$merge %in% merge.list),] |
158 | 158 |
159 patient1.fuzzy$merge = paste(patient1.fuzzy$V_Segment_Major_Gene, patient1.fuzzy$J_Segment_Major_Gene, patient1.fuzzy$CDR3_Sense_Sequence) | 159 #patient1.fuzzy$merge = paste(patient1.fuzzy$V_Segment_Major_Gene, patient1.fuzzy$J_Segment_Major_Gene, patient1.fuzzy$CDR3_Sense_Sequence) |
160 patient2.fuzzy$merge = paste(patient2.fuzzy$V_Segment_Major_Gene, patient2.fuzzy$J_Segment_Major_Gene, patient2.fuzzy$CDR3_Sense_Sequence) | 160 #patient2.fuzzy$merge = paste(patient2.fuzzy$V_Segment_Major_Gene, patient2.fuzzy$J_Segment_Major_Gene, patient2.fuzzy$CDR3_Sense_Sequence) |
161 | |
162 patient1.fuzzy$merge = paste(patient1.fuzzy$locus_V, patient1.fuzzy$locus_J, patient1.fuzzy$CDR3_Sense_Sequence) | |
163 patient2.fuzzy$merge = paste(patient2.fuzzy$locus_V, patient2.fuzzy$locus_J, patient2.fuzzy$CDR3_Sense_Sequence) | |
161 | 164 |
162 merge.freq.table = data.frame(table(c(patient1.fuzzy$merge, patient2.fuzzy$merge))) | 165 merge.freq.table = data.frame(table(c(patient1.fuzzy$merge, patient2.fuzzy$merge))) |
163 merge.freq.table.gt.1 = merge.freq.table[merge.freq.table$Freq > 1,] | 166 merge.freq.table.gt.1 = merge.freq.table[merge.freq.table$Freq > 1,] |
164 | 167 |
165 patient1.fuzzy = patient1.fuzzy[patient1.fuzzy$merge %in% merge.freq.table.gt.1$Var1,] | 168 patient1.fuzzy = patient1.fuzzy[patient1.fuzzy$merge %in% merge.freq.table.gt.1$Var1,] |
169 current.merge.1 = patient1.fuzzy[1,"merge"] | 172 current.merge.1 = patient1.fuzzy[1,"merge"] |
170 current.clone.seq.1 = patient1.fuzzy[1,"Clone_Sequence"] | 173 current.clone.seq.1 = patient1.fuzzy[1,"Clone_Sequence"] |
171 current.merge.in.2 = patient2.fuzzy[patient2.fuzzy$merge == current.merge.1,] | 174 current.merge.in.2 = patient2.fuzzy[patient2.fuzzy$merge == current.merge.1,] |
172 | 175 |
173 #agrep/adist the two samples | 176 #agrep/adist the two samples |
174 agrep.match = agrep(current.clone.seq.1, current.merge.in.2$Clone_Sequence, max.distance = 1, costs=list(insertions=0.1, deletions=0.1, substitutions=1)) | 177 agrep.match = agrep(current.clone.seq.1, current.merge.in.2$Clone_Sequence, max.distance = 9, costs=list(insertions=1, deletions=1, substitutions=10)) |
175 | 178 |
176 | 179 |
177 if(length(agrep.match) == 1){ | 180 if(length(agrep.match) == 1){ |
178 current.clone.seq.2 = patient2.fuzzy[agrep.match,"Clone_Sequence"] | 181 current.clone.seq.2 = patient2.fuzzy[agrep.match,"Clone_Sequence"] |
179 patientMerge.new.row = data.frame(merge=current.clone.seq.1, | 182 patientMerge.new.row = data.frame(merge=current.clone.seq.1, |
231 patient2.fuzzy <<- patient2.fuzzy[-c(agrep.match),] | 234 patient2.fuzzy <<- patient2.fuzzy[-c(agrep.match),] |
232 | 235 |
233 | 236 |
234 } else if (length(agrep.match) > 1){ | 237 } else if (length(agrep.match) > 1){ |
235 #multiple matches, whatdo? | 238 #multiple matches, whatdo? |
236 cat(paste("<tr><td>", "Multiple matches found for ", current.merge.1, " in ", patient, "</td></tr>", sep=""), file=logfile, append=T) | 239 cat(paste("<tr><td>", "Multiple matches found for ", current.merge.1, ", ", current.clone.seq.1, " in ", patient, ", ", oneSample, "</td></tr>", sep=""), file=logfile, append=T) |
237 } | 240 } |
238 patient1.fuzzy = patient1.fuzzy[-1,] | 241 patient1.fuzzy = patient1.fuzzy[-1,] |
239 } | 242 } |
240 | 243 |
241 #adist(patient1.fuzzy$Clone_Sequence, patient2.fuzzy$Clone_Sequence, list(insertions=0.1, deletions=0.1, substitutions=1)) | 244 #adist(patient1.fuzzy$Clone_Sequence, patient2.fuzzy$Clone_Sequence, list(insertions=0.1, deletions=0.1, substitutions=1)) |