diff shm_csr.r @ 7:ad9be244b104 draft

Uploaded
author davidvanzessen
date Mon, 07 Nov 2016 03:04:07 -0500
parents 012a738edf5a
children 3968d04b5724
line wrap: on
line diff
--- a/shm_csr.r	Tue Nov 01 10:48:38 2016 -0400
+++ b/shm_csr.r	Mon Nov 07 03:04:07 2016 -0500
@@ -119,9 +119,9 @@
 if(empty.region.filter == "FR1") {
 	regions = c("CDR1", "FR2", "CDR2", "FR3")
 } else if (empty.region.filter == "CDR1") {
-	regions = c("FR2", "CDR2", "FR3", "CDR3")
+	regions = c("FR2", "CDR2", "FR3")
 } else if (empty.region.filter == "FR2") {
-	regions = c("CDR2", "FR3", "CDR3")
+	regions = c("CDR2", "FR3")
 }
 
 sum_by_row = function(x, columns) { sum(as.numeric(x[columns]), na.rm=T) }
@@ -229,11 +229,25 @@
 		matrx[9,z] = round(matrx[9,x] / matrx[9,y], digits=1)
 
 		if(fname == "sum"){
-			matrx[10,x] = round(f(rowSums(tmp[,c("FR2.IMGT.Nb.of.nucleotides", "FR3.IMGT.Nb.of.nucleotides")], na.rm=T)), digits=1)
+			
+			regions.fr = regions[grepl("FR", regions)]
+			regions.fr = paste(regions.fr, ".IMGT.Nb.of.nucleotides", sep="")
+			regions.cdr = regions[grepl("CDR", regions)]
+			regions.cdr = paste(regions.cdr, ".IMGT.Nb.of.nucleotides", sep="")
+			
+			if(length(regions.fr) > 1){ #in case there is only on FR region (rowSums needs >1 column)
+				matrx[10,x] = round(f(rowSums(tmp[,regions.fr], na.rm=T)), digits=1)
+			} else {
+				matrx[10,x] = round(f(tmp[,regions.fr], na.rm=T), digits=1)
+			}
 			matrx[10,y] = round(f(tmp$VRegionNucleotides, na.rm=T), digits=1)
 			matrx[10,z] = round(matrx[10,x] / matrx[10,y] * 100, digits=1)
 
-			matrx[11,x] = round(f(rowSums(tmp[,c("CDR1.IMGT.Nb.of.nucleotides", "CDR2.IMGT.Nb.of.nucleotides")], na.rm=T)), digits=1)
+			if(length(regions.cdr) > 1){ #in case there is only on CDR region
+				matrx[11,x] = round(f(rowSums(tmp[,regions.cdr], na.rm=T)), digits=1)
+			} else {
+				matrx[11,x] = round(f(tmp[,regions.cdr], na.rm=T), digits=1)
+			}
 			matrx[11,y] = round(f(tmp$VRegionNucleotides, na.rm=T), digits=1)
 			matrx[11,z] = round(matrx[11,x] / matrx[11,y] * 100, digits=1)
 		}