Mercurial > repos > davidvanzessen > argalaxy_tools
annotate report_clonality/RScript.r @ 55:2a7dc86d8f85 draft
"planemo upload commit 14f5f6a6fa8873c6d7f0f97dfddc0ba02fff3d1d"
author | rhpvorderman |
---|---|
date | Fri, 19 Nov 2021 10:09:54 +0000 |
parents | 81b3eb11ed2c |
children |
rev | line source |
---|---|
54
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1 # ---------------------- load/install packages ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
2 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
3 if (!("gridExtra" %in% rownames(installed.packages()))) { |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
4 install.packages("gridExtra", repos="http://cran.xl-mirror.nl/") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
5 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
6 library(gridExtra) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
7 if (!("ggplot2" %in% rownames(installed.packages()))) { |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
8 install.packages("ggplot2", repos="http://cran.xl-mirror.nl/") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
9 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
10 library(ggplot2) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
11 if (!("plyr" %in% rownames(installed.packages()))) { |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
12 install.packages("plyr", repos="http://cran.xl-mirror.nl/") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
13 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
14 library(plyr) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
15 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
16 if (!("data.table" %in% rownames(installed.packages()))) { |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
17 install.packages("data.table", repos="http://cran.xl-mirror.nl/") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
18 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
19 library(data.table) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
20 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
21 if (!("reshape2" %in% rownames(installed.packages()))) { |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
22 install.packages("reshape2", repos="http://cran.xl-mirror.nl/") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
23 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
24 library(reshape2) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
25 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
26 if (!("lymphclon" %in% rownames(installed.packages()))) { |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
27 install.packages("lymphclon", repos="http://cran.xl-mirror.nl/") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
28 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
29 library(lymphclon) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
30 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
31 # ---------------------- parameters ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
32 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
33 args <- commandArgs(trailingOnly = TRUE) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
34 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
35 infile = args[1] #path to input file |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
36 outfile = args[2] #path to output file |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
37 outdir = args[3] #path to output folder (html/images/data) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
38 clonaltype = args[4] #clonaltype definition, or 'none' for no unique filtering |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
39 ct = unlist(strsplit(clonaltype, ",")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
40 species = args[5] #human or mouse |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
41 locus = args[6] # IGH, IGK, IGL, TRB, TRA, TRG or TRD |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
42 filterproductive = ifelse(args[7] == "yes", T, F) #should unproductive sequences be filtered out? (yes/no) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
43 clonality_method = args[8] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
44 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
45 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
46 # ---------------------- Data preperation ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
47 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
48 print("Report Clonality - Data preperation") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
49 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
50 inputdata = read.table(infile, sep="\t", header=TRUE, fill=T, comment.char="", stringsAsFactors=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
51 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
52 inputdata$Sample = as.character(inputdata$Sample) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
53 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
54 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
55 print(paste("nrows: ", nrow(inputdata))) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
56 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
57 setwd(outdir) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
58 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
59 # remove weird rows |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
60 inputdata = inputdata[inputdata$Sample != "",] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
61 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
62 print(paste("nrows: ", nrow(inputdata))) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
63 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
64 #remove the allele from the V,D and J genes |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
65 inputdata$Top.V.Gene = gsub("[*]([0-9]+)", "", inputdata$Top.V.Gene) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
66 inputdata$Top.D.Gene = gsub("[*]([0-9]+)", "", inputdata$Top.D.Gene) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
67 inputdata$Top.J.Gene = gsub("[*]([0-9]+)", "", inputdata$Top.J.Gene) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
68 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
69 print(paste("nrows: ", nrow(inputdata))) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
70 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
71 #filter uniques |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
72 inputdata.removed = inputdata[NULL,] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
73 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
74 print(paste("nrows: ", nrow(inputdata))) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
75 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
76 inputdata$clonaltype = 1:nrow(inputdata) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
77 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
78 #keep track of the count of sequences in samples or samples/replicates for the front page overview |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
79 input.sample.count = data.frame(data.table(inputdata)[, list(All=.N), by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
80 input.rep.count = data.frame(data.table(inputdata)[, list(All=.N), by=c("Sample", "Replicate")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
81 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
82 PRODF = inputdata |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
83 UNPROD = inputdata |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
84 if(filterproductive){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
85 if("Functionality" %in% colnames(inputdata)) { # "Functionality" is an IMGT column |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
86 #PRODF = inputdata[inputdata$Functionality == "productive" | inputdata$Functionality == "productive (see comment)", ] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
87 PRODF = inputdata[inputdata$Functionality %in% c("productive (see comment)","productive"),] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
88 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
89 PRODF.count = data.frame(data.table(PRODF)[, list(count=.N), by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
90 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
91 UNPROD = inputdata[inputdata$Functionality %in% c("unproductive (see comment)","unproductive"), ] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
92 } else { |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
93 PRODF = inputdata[inputdata$VDJ.Frame != "In-frame with stop codon" & inputdata$VDJ.Frame != "Out-of-frame" & inputdata$CDR3.Found.How != "NOT_FOUND" , ] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
94 UNPROD = inputdata[!(inputdata$VDJ.Frame != "In-frame with stop codon" & inputdata$VDJ.Frame != "Out-of-frame" & inputdata$CDR3.Found.How != "NOT_FOUND" ), ] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
95 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
96 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
97 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
98 for(i in 1:nrow(UNPROD)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
99 if(!is.numeric(UNPROD[i,"CDR3.Length"])){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
100 UNPROD[i,"CDR3.Length"] = 0 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
101 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
102 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
103 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
104 prod.sample.count = data.frame(data.table(PRODF)[, list(Productive=.N), by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
105 prod.rep.count = data.frame(data.table(PRODF)[, list(Productive=.N), by=c("Sample", "Replicate")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
106 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
107 unprod.sample.count = data.frame(data.table(UNPROD)[, list(Unproductive=.N), by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
108 unprod.rep.count = data.frame(data.table(UNPROD)[, list(Unproductive=.N), by=c("Sample", "Replicate")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
109 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
110 clonalityFrame = PRODF |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
111 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
112 #remove duplicates based on the clonaltype |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
113 if(clonaltype != "none"){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
114 clonaltype = paste(clonaltype, ",Sample", sep="") #add sample column to clonaltype, unique within samples |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
115 PRODF$clonaltype = do.call(paste, c(PRODF[unlist(strsplit(clonaltype, ","))], sep = ":")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
116 PRODF = PRODF[!duplicated(PRODF$clonaltype), ] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
117 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
118 UNPROD$clonaltype = do.call(paste, c(UNPROD[unlist(strsplit(clonaltype, ","))], sep = ":")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
119 UNPROD = UNPROD[!duplicated(UNPROD$clonaltype), ] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
120 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
121 #again for clonalityFrame but with sample+replicate |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
122 clonalityFrame$clonaltype = do.call(paste, c(clonalityFrame[unlist(strsplit(clonaltype, ","))], sep = ":")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
123 clonalityFrame$clonality_clonaltype = do.call(paste, c(clonalityFrame[unlist(strsplit(paste(clonaltype, ",Replicate", sep=""), ","))], sep = ":")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
124 clonalityFrame = clonalityFrame[!duplicated(clonalityFrame$clonality_clonaltype), ] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
125 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
126 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
127 if(nrow(PRODF) == 0){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
128 stop("No sequences left after filtering") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
129 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
130 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
131 prod.unique.sample.count = data.frame(data.table(PRODF)[, list(Productive_unique=.N), by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
132 prod.unique.rep.count = data.frame(data.table(PRODF)[, list(Productive_unique=.N), by=c("Sample", "Replicate")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
133 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
134 unprod.unique.sample.count = data.frame(data.table(UNPROD)[, list(Unproductive_unique=.N), by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
135 unprod.unique.rep.count = data.frame(data.table(UNPROD)[, list(Unproductive_unique=.N), by=c("Sample", "Replicate")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
136 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
137 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
138 PRODF$freq = 1 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
139 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
140 if(any(grepl(pattern="_", x=PRODF$ID))){ #the frequency can be stored in the ID with the pattern ".*_freq_.*" |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
141 PRODF$freq = gsub("^[0-9]+_", "", PRODF$ID) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
142 PRODF$freq = gsub("_.*", "", PRODF$freq) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
143 PRODF$freq = as.numeric(PRODF$freq) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
144 if(any(is.na(PRODF$freq))){ #if there was an "_" in the ID, but not the frequency, go back to frequency of 1 for every sequence |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
145 PRODF$freq = 1 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
146 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
147 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
148 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
149 #make a names list with sample -> color |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
150 naive.colors = c('blue4', 'darkred', 'olivedrab3', 'red', 'gray74', 'darkviolet', 'lightblue1', 'gold', 'chartreuse2', 'pink', 'Paleturquoise3', 'Chocolate1', 'Yellow', 'Deeppink3', 'Mediumorchid1', 'Darkgreen', 'Blue', 'Gray36', 'Hotpink', 'Yellow4') |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
151 unique.samples = unique(PRODF$Sample) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
152 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
153 if(length(unique.samples) <= length(naive.colors)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
154 sample.colors = naive.colors[1:length(unique.samples)] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
155 } else { |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
156 sample.colors = rainbow(length(unique.samples)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
157 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
158 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
159 names(sample.colors) = unique.samples |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
160 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
161 print("Sample.colors") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
162 print(sample.colors) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
163 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
164 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
165 #write the complete dataset that is left over, will be the input if 'none' for clonaltype and 'no' for filterproductive |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
166 write.table(PRODF, "allUnique.txt", sep="\t",quote=F,row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
167 #write.table(PRODF, "allUnique.csv", sep=",",quote=F,row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
168 write.table(UNPROD, "allUnproductive.txt", sep="\t",quote=F,row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
169 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
170 print("SAMPLE TABLE:") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
171 print(table(PRODF$Sample)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
172 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
173 #write the samples to a file |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
174 sampleFile <- file("samples.txt") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
175 un = unique(inputdata$Sample) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
176 un = paste(un, sep="\n") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
177 writeLines(un, sampleFile) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
178 close(sampleFile) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
179 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
180 # ---------------------- Counting the productive/unproductive and unique sequences ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
181 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
182 print("Report Clonality - counting productive/unproductive/unique") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
183 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
184 #create the table on the overview page with the productive/unique counts per sample/replicate |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
185 #first for sample |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
186 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
187 sample.count = merge(input.sample.count, prod.sample.count, by="Sample", all.x=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
188 sample.count$perc_prod = round(sample.count$Productive / sample.count$All * 100) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
189 sample.count = merge(sample.count, prod.unique.sample.count, by="Sample", all.x=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
190 sample.count$perc_prod_un = round(sample.count$Productive_unique / sample.count$All * 100) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
191 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
192 sample.count = merge(sample.count , unprod.sample.count, by="Sample", all.x=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
193 sample.count$perc_unprod = round(sample.count$Unproductive / sample.count$All * 100) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
194 sample.count = merge(sample.count, unprod.unique.sample.count, by="Sample", all.x=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
195 sample.count$perc_unprod_un = round(sample.count$Unproductive_unique / sample.count$All * 100) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
196 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
197 #then sample/replicate |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
198 rep.count = merge(input.rep.count, prod.rep.count, by=c("Sample", "Replicate"), all.x=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
199 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
200 print(rep.count) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
201 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
202 fltr = is.na(rep.count$Productive) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
203 if(any(fltr)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
204 rep.count[fltr,"Productive"] = 0 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
205 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
206 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
207 print(rep.count) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
208 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
209 rep.count$perc_prod = round(rep.count$Productive / rep.count$All * 100) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
210 rep.count = merge(rep.count, prod.unique.rep.count, by=c("Sample", "Replicate"), all.x=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
211 rep.count$perc_prod_un = round(rep.count$Productive_unique / rep.count$All * 100) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
212 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
213 rep.count = merge(rep.count, unprod.rep.count, by=c("Sample", "Replicate"), all.x=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
214 rep.count$perc_unprod = round(rep.count$Unproductive / rep.count$All * 100) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
215 rep.count = merge(rep.count, unprod.unique.rep.count, by=c("Sample", "Replicate"), all.x=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
216 rep.count$perc_unprod_un = round(rep.count$Unproductive_unique / rep.count$All * 100) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
217 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
218 rep.count$Sample = paste(rep.count$Sample, rep.count$Replicate, sep="_") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
219 rep.count = rep.count[,names(rep.count) != "Replicate"] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
220 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
221 count = rbind(sample.count, rep.count) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
222 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
223 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
224 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
225 write.table(x=count, file="productive_counting.txt", sep=",",quote=F,row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
226 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
227 # ---------------------- V+J+CDR3 sequence count ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
228 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
229 VJCDR3.count = data.frame(table(clonalityFrame$Top.V.Gene, clonalityFrame$Top.J.Gene, clonalityFrame$CDR3.Seq.DNA)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
230 names(VJCDR3.count) = c("Top.V.Gene", "Top.J.Gene", "CDR3.Seq.DNA", "Count") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
231 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
232 VJCDR3.count = VJCDR3.count[VJCDR3.count$Count > 0,] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
233 VJCDR3.count = VJCDR3.count[order(-VJCDR3.count$Count),] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
234 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
235 write.table(x=VJCDR3.count, file="VJCDR3_count.txt", sep="\t",quote=F,row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
236 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
237 # ---------------------- Frequency calculation for V, D and J ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
238 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
239 print("Report Clonality - frequency calculation V, D and J") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
240 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
241 PRODFV = data.frame(data.table(PRODF)[, list(Length=sum(freq)), by=c("Sample", "Top.V.Gene")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
242 Total = ddply(PRODFV, .(Sample), function(x) data.frame(Total = sum(x$Length))) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
243 PRODFV = merge(PRODFV, Total, by.x='Sample', by.y='Sample', all.x=TRUE) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
244 PRODFV = ddply(PRODFV, c("Sample", "Top.V.Gene"), summarise, relFreq= (Length*100 / Total)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
245 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
246 PRODFD = data.frame(data.table(PRODF)[, list(Length=sum(freq)), by=c("Sample", "Top.D.Gene")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
247 Total = ddply(PRODFD, .(Sample), function(x) data.frame(Total = sum(x$Length))) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
248 PRODFD = merge(PRODFD, Total, by.x='Sample', by.y='Sample', all.x=TRUE) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
249 PRODFD = ddply(PRODFD, c("Sample", "Top.D.Gene"), summarise, relFreq= (Length*100 / Total)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
250 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
251 PRODFJ = data.frame(data.table(PRODF)[, list(Length=sum(freq)), by=c("Sample", "Top.J.Gene")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
252 Total = ddply(PRODFJ, .(Sample), function(x) data.frame(Total = sum(x$Length))) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
253 PRODFJ = merge(PRODFJ, Total, by.x='Sample', by.y='Sample', all.x=TRUE) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
254 PRODFJ = ddply(PRODFJ, c("Sample", "Top.J.Gene"), summarise, relFreq= (Length*100 / Total)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
255 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
256 # ---------------------- Setting up the gene names for the different species/loci ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
257 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
258 print("Report Clonality - getting genes for species/loci") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
259 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
260 Vchain = "" |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
261 Dchain = "" |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
262 Jchain = "" |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
263 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
264 if(species == "custom"){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
265 print("Custom genes: ") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
266 splt = unlist(strsplit(locus, ";")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
267 print(paste("V:", splt[1])) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
268 print(paste("D:", splt[2])) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
269 print(paste("J:", splt[3])) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
270 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
271 Vchain = unlist(strsplit(splt[1], ",")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
272 Vchain = data.frame(v.name = Vchain, chr.orderV = 1:length(Vchain)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
273 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
274 Dchain = unlist(strsplit(splt[2], ",")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
275 if(length(Dchain) > 0){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
276 Dchain = data.frame(v.name = Dchain, chr.orderD = 1:length(Dchain)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
277 } else { |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
278 Dchain = data.frame(v.name = character(0), chr.orderD = numeric(0)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
279 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
280 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
281 Jchain = unlist(strsplit(splt[3], ",")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
282 Jchain = data.frame(v.name = Jchain, chr.orderJ = 1:length(Jchain)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
283 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
284 } else { |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
285 genes = read.table("genes.txt", sep="\t", header=TRUE, fill=T, comment.char="") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
286 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
287 Vchain = genes[grepl(species, genes$Species) & genes$locus == locus & genes$region == "V",c("IMGT.GENE.DB", "chr.order")] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
288 colnames(Vchain) = c("v.name", "chr.orderV") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
289 Dchain = genes[grepl(species, genes$Species) & genes$locus == locus & genes$region == "D",c("IMGT.GENE.DB", "chr.order")] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
290 colnames(Dchain) = c("v.name", "chr.orderD") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
291 Jchain = genes[grepl(species, genes$Species) & genes$locus == locus & genes$region == "J",c("IMGT.GENE.DB", "chr.order")] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
292 colnames(Jchain) = c("v.name", "chr.orderJ") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
293 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
294 useD = TRUE |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
295 if(nrow(Dchain) == 0){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
296 useD = FALSE |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
297 cat("No D Genes in this species/locus") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
298 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
299 print(paste(nrow(Vchain), "genes in V")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
300 print(paste(nrow(Dchain), "genes in D")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
301 print(paste(nrow(Jchain), "genes in J")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
302 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
303 # ---------------------- merge with the frequency count ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
304 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
305 PRODFV = merge(PRODFV, Vchain, by.x='Top.V.Gene', by.y='v.name', all.x=TRUE) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
306 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
307 PRODFD = merge(PRODFD, Dchain, by.x='Top.D.Gene', by.y='v.name', all.x=TRUE) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
308 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
309 PRODFJ = merge(PRODFJ, Jchain, by.x='Top.J.Gene', by.y='v.name', all.x=TRUE) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
310 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
311 # ---------------------- Create the V, D and J frequency plots and write the data.frame for every plot to a file ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
312 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
313 print("Report Clonality - V, D and J frequency plots") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
314 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
315 pV = ggplot(PRODFV) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
316 pV = pV + geom_bar( aes( x=factor(reorder(Top.V.Gene, chr.orderV)), y=relFreq, fill=Sample), stat='identity', position="dodge") + theme(axis.text.x = element_text(angle = 90, hjust = 1)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
317 pV = pV + xlab("Summary of V gene") + ylab("Frequency") + ggtitle("Relative frequency of V gene usage") + scale_fill_manual(values=sample.colors) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
318 pV = pV + theme(panel.background = element_rect(fill = "white", colour="black"),text = element_text(size=15, colour="black"), axis.text.x = element_text(angle = 45, hjust = 1), panel.grid.major.y = element_line(colour = "black"), panel.grid.major.x = element_blank()) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
319 write.table(x=PRODFV, file="VFrequency.txt", sep="\t",quote=F,row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
320 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
321 png("VPlot.png",width = 1280, height = 720) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
322 pV |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
323 dev.off() |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
324 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
325 ggsave("VPlot.pdf", pV, width=13, height=7) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
326 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
327 if(useD){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
328 pD = ggplot(PRODFD) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
329 pD = pD + geom_bar( aes( x=factor(reorder(Top.D.Gene, chr.orderD)), y=relFreq, fill=Sample), stat='identity', position="dodge") + theme(axis.text.x = element_text(angle = 90, hjust = 1)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
330 pD = pD + xlab("Summary of D gene") + ylab("Frequency") + ggtitle("Relative frequency of D gene usage") + scale_fill_manual(values=sample.colors) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
331 pD = pD + theme(panel.background = element_rect(fill = "white", colour="black"),text = element_text(size=15, colour="black"), axis.text.x = element_text(angle = 45, hjust = 1), panel.grid.major.y = element_line(colour = "black"), panel.grid.major.x = element_blank()) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
332 write.table(x=PRODFD, file="DFrequency.txt", sep="\t",quote=F,row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
333 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
334 png("DPlot.png",width = 800, height = 600) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
335 print(pD) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
336 dev.off() |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
337 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
338 ggsave("DPlot.pdf", pD, width=10, height=7) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
339 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
340 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
341 pJ = ggplot(PRODFJ) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
342 pJ = pJ + geom_bar( aes( x=factor(reorder(Top.J.Gene, chr.orderJ)), y=relFreq, fill=Sample), stat='identity', position="dodge") + theme(axis.text.x = element_text(angle = 90, hjust = 1)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
343 pJ = pJ + xlab("Summary of J gene") + ylab("Frequency") + ggtitle("Relative frequency of J gene usage") + scale_fill_manual(values=sample.colors) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
344 pJ = pJ + theme(panel.background = element_rect(fill = "white", colour="black"),text = element_text(size=15, colour="black"), axis.text.x = element_text(angle = 45, hjust = 1), panel.grid.major.y = element_line(colour = "black"), panel.grid.major.x = element_blank()) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
345 write.table(x=PRODFJ, file="JFrequency.txt", sep="\t",quote=F,row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
346 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
347 png("JPlot.png",width = 800, height = 600) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
348 pJ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
349 dev.off() |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
350 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
351 ggsave("JPlot.pdf", pJ) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
352 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
353 # ---------------------- Now the frequency plots of the V, D and J families ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
354 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
355 print("Report Clonality - V, D and J family plots") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
356 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
357 VGenes = PRODF[,c("Sample", "Top.V.Gene")] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
358 VGenes$Top.V.Gene = gsub("-.*", "", VGenes$Top.V.Gene) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
359 VGenes = data.frame(data.table(VGenes)[, list(Count=.N), by=c("Sample", "Top.V.Gene")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
360 TotalPerSample = data.frame(data.table(VGenes)[, list(total=sum(.SD$Count)), by=Sample]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
361 VGenes = merge(VGenes, TotalPerSample, by="Sample") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
362 VGenes$Frequency = VGenes$Count * 100 / VGenes$total |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
363 VPlot = ggplot(VGenes) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
364 VPlot = VPlot + geom_bar(aes( x = Top.V.Gene, y = Frequency, fill = Sample), stat='identity', position='dodge' ) + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
365 ggtitle("Distribution of V gene families") + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
366 ylab("Percentage of sequences") + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
367 scale_fill_manual(values=sample.colors) + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
368 theme(panel.background = element_rect(fill = "white", colour="black"),text = element_text(size=15, colour="black"), axis.text.x = element_text(angle = 45, hjust = 1), panel.grid.major.y = element_line(colour = "black"), panel.grid.major.x = element_blank()) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
369 png("VFPlot.png") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
370 VPlot |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
371 dev.off() |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
372 ggsave("VFPlot.pdf", VPlot) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
373 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
374 write.table(x=VGenes, file="VFFrequency.txt", sep="\t",quote=F,row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
375 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
376 if(useD){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
377 DGenes = PRODF[,c("Sample", "Top.D.Gene")] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
378 DGenes$Top.D.Gene = gsub("-.*", "", DGenes$Top.D.Gene) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
379 DGenes = data.frame(data.table(DGenes)[, list(Count=.N), by=c("Sample", "Top.D.Gene")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
380 TotalPerSample = data.frame(data.table(DGenes)[, list(total=sum(.SD$Count)), by=Sample]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
381 DGenes = merge(DGenes, TotalPerSample, by="Sample") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
382 DGenes$Frequency = DGenes$Count * 100 / DGenes$total |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
383 DPlot = ggplot(DGenes) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
384 DPlot = DPlot + geom_bar(aes( x = Top.D.Gene, y = Frequency, fill = Sample), stat='identity', position='dodge' ) + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
385 ggtitle("Distribution of D gene families") + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
386 ylab("Percentage of sequences") + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
387 scale_fill_manual(values=sample.colors) + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
388 theme(panel.background = element_rect(fill = "white", colour="black"),text = element_text(size=15, colour="black"), axis.text.x = element_text(angle = 45, hjust = 1), panel.grid.major.y = element_line(colour = "black"), panel.grid.major.x = element_blank()) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
389 png("DFPlot.png") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
390 print(DPlot) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
391 dev.off() |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
392 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
393 ggsave("DFPlot.pdf", DPlot) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
394 write.table(x=DGenes, file="DFFrequency.txt", sep="\t",quote=F,row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
395 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
396 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
397 # ---------------------- Plotting the cdr3 length ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
398 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
399 print("Report Clonality - CDR3 length plot") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
400 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
401 CDR3Length = data.frame(data.table(PRODF)[, list(Count=.N), by=c("Sample", "CDR3.Length")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
402 TotalPerSample = data.frame(data.table(CDR3Length)[, list(total=sum(.SD$Count)), by=Sample]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
403 CDR3Length = merge(CDR3Length, TotalPerSample, by="Sample") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
404 CDR3Length$Frequency = CDR3Length$Count * 100 / CDR3Length$total |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
405 CDR3LengthPlot = ggplot(CDR3Length) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
406 CDR3LengthPlot = CDR3LengthPlot + geom_bar(aes( x = factor(reorder(CDR3.Length, as.numeric(CDR3.Length))), y = Frequency, fill = Sample), stat='identity', position='dodge' ) + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
407 ggtitle("Length distribution of CDR3") + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
408 xlab("CDR3 Length") + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
409 ylab("Percentage of sequences") + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
410 scale_fill_manual(values=sample.colors) + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
411 theme(panel.background = element_rect(fill = "white", colour="black"),text = element_text(size=15, colour="black"), axis.text.x = element_text(angle = 45, hjust = 1), panel.grid.major.y = element_line(colour = "black"), panel.grid.major.x = element_blank()) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
412 png("CDR3LengthPlot.png",width = 1280, height = 720) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
413 CDR3LengthPlot |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
414 dev.off() |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
415 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
416 ggsave("CDR3LengthPlot.pdf", CDR3LengthPlot, width=12, height=7) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
417 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
418 write.table(x=CDR3Length, file="CDR3LengthPlot.txt", sep="\t",quote=F,row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
419 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
420 # ---------------------- Plot the heatmaps ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
421 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
422 #get the reverse order for the V and D genes |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
423 revVchain = Vchain |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
424 revDchain = Dchain |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
425 revVchain$chr.orderV = rev(revVchain$chr.orderV) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
426 revDchain$chr.orderD = rev(revDchain$chr.orderD) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
427 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
428 if(useD){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
429 print("Report Clonality - Heatmaps VD") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
430 plotVD <- function(dat){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
431 if(length(dat[,1]) == 0){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
432 return() |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
433 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
434 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
435 img = ggplot() + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
436 geom_tile(data=dat, aes(x=factor(reorder(Top.D.Gene, chr.orderD)), y=factor(reorder(Top.V.Gene, chr.orderV)), fill=relLength)) + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
437 theme(axis.text.x = element_text(angle = 90, hjust = 1)) + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
438 scale_fill_gradient(low="gold", high="blue", na.value="white") + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
439 ggtitle(paste(unique(dat$Sample), " (N=" , sum(dat$Length, na.rm=T) ,")", sep="")) + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
440 xlab("D genes") + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
441 ylab("V Genes") + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
442 theme(panel.background = element_rect(fill = "white", colour="black"),text = element_text(size=15, colour="black"), panel.grid.major = element_line(colour = "gainsboro")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
443 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
444 png(paste("HeatmapVD_", unique(dat[3])[1,1] , ".png", sep=""), width=200+(15*length(Dchain$v.name)), height=100+(15*length(Vchain$v.name))) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
445 print(img) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
446 dev.off() |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
447 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
448 ggsave(paste("HeatmapVD_", unique(dat[3])[1,1] , ".pdf", sep=""), img, height=13, width=8) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
449 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
450 write.table(x=acast(dat, Top.V.Gene~Top.D.Gene, value.var="Length"), file=paste("HeatmapVD_", unique(dat[3])[1,1], ".txt", sep=""), sep="\t",quote=F,row.names=T,col.names=NA) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
451 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
452 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
453 VandDCount = data.frame(data.table(PRODF)[, list(Length=.N), by=c("Top.V.Gene", "Top.D.Gene", "Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
454 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
455 VandDCount$l = log(VandDCount$Length) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
456 maxVD = data.frame(data.table(VandDCount)[, list(max=max(l)), by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
457 VandDCount = merge(VandDCount, maxVD, by.x="Sample", by.y="Sample", all.x=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
458 VandDCount$relLength = VandDCount$l / VandDCount$max |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
459 check = is.nan(VandDCount$relLength) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
460 if(any(check)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
461 VandDCount[check,"relLength"] = 0 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
462 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
463 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
464 completeVD = merge(VandDCount, revVchain, by.x="Top.V.Gene", by.y="v.name", all=TRUE) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
465 completeVD = merge(completeVD, Dchain, by.x="Top.D.Gene", by.y="v.name", all=TRUE) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
466 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
467 fltr = is.nan(completeVD$relLength) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
468 if(all(fltr)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
469 completeVD[fltr,"relLength"] = 0 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
470 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
471 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
472 VDList = split(completeVD, f=completeVD[,"Sample"]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
473 lapply(VDList, FUN=plotVD) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
474 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
475 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
476 print("Report Clonality - Heatmaps VJ") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
477 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
478 plotVJ <- function(dat){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
479 if(length(dat[,1]) == 0){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
480 return() |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
481 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
482 cat(paste(unique(dat[3])[1,1])) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
483 img = ggplot() + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
484 geom_tile(data=dat, aes(x=factor(reorder(Top.J.Gene, chr.orderJ)), y=factor(reorder(Top.V.Gene, chr.orderV)), fill=relLength)) + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
485 theme(axis.text.x = element_text(angle = 90, hjust = 1)) + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
486 scale_fill_gradient(low="gold", high="blue", na.value="white") + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
487 ggtitle(paste(unique(dat$Sample), " (N=" , sum(dat$Length, na.rm=T) ,")", sep="")) + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
488 xlab("J genes") + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
489 ylab("V Genes") + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
490 theme(panel.background = element_rect(fill = "white", colour="black"),text = element_text(size=15, colour="black"), panel.grid.major = element_line(colour = "gainsboro")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
491 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
492 png(paste("HeatmapVJ_", unique(dat[3])[1,1] , ".png", sep=""), width=200+(15*length(Jchain$v.name)), height=100+(15*length(Vchain$v.name))) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
493 print(img) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
494 dev.off() |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
495 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
496 ggsave(paste("HeatmapVJ_", unique(dat[3])[1,1] , ".pdf", sep=""), img, height=11, width=4) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
497 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
498 write.table(x=acast(dat, Top.V.Gene~Top.J.Gene, value.var="Length"), file=paste("HeatmapVJ_", unique(dat[3])[1,1], ".txt", sep=""), sep="\t",quote=F,row.names=T,col.names=NA) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
499 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
500 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
501 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
502 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
503 VandJCount = data.frame(data.table(PRODF)[, list(Length=.N), by=c("Top.V.Gene", "Top.J.Gene", "Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
504 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
505 VandJCount$l = log(VandJCount$Length) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
506 maxVJ = data.frame(data.table(VandJCount)[, list(max=max(l)), by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
507 VandJCount = merge(VandJCount, maxVJ, by.x="Sample", by.y="Sample", all.x=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
508 VandJCount$relLength = VandJCount$l / VandJCount$max |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
509 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
510 check = is.nan(VandJCount$relLength) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
511 if(any(check)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
512 VandJCount[check,"relLength"] = 0 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
513 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
514 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
515 completeVJ = merge(VandJCount, revVchain, by.x="Top.V.Gene", by.y="v.name", all=TRUE) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
516 completeVJ = merge(completeVJ, Jchain, by.x="Top.J.Gene", by.y="v.name", all=TRUE) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
517 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
518 fltr = is.nan(completeVJ$relLength) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
519 if(any(fltr)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
520 completeVJ[fltr,"relLength"] = 1 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
521 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
522 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
523 VJList = split(completeVJ, f=completeVJ[,"Sample"]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
524 lapply(VJList, FUN=plotVJ) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
525 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
526 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
527 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
528 if(useD){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
529 print("Report Clonality - Heatmaps DJ") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
530 plotDJ <- function(dat){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
531 if(length(dat[,1]) == 0){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
532 return() |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
533 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
534 img = ggplot() + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
535 geom_tile(data=dat, aes(x=factor(reorder(Top.J.Gene, chr.orderJ)), y=factor(reorder(Top.D.Gene, chr.orderD)), fill=relLength)) + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
536 theme(axis.text.x = element_text(angle = 90, hjust = 1)) + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
537 scale_fill_gradient(low="gold", high="blue", na.value="white") + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
538 ggtitle(paste(unique(dat$Sample), " (N=" , sum(dat$Length, na.rm=T) ,")", sep="")) + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
539 xlab("J genes") + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
540 ylab("D Genes") + |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
541 theme(panel.background = element_rect(fill = "white", colour="black"),text = element_text(size=15, colour="black"), panel.grid.major = element_line(colour = "gainsboro")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
542 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
543 png(paste("HeatmapDJ_", unique(dat[3])[1,1] , ".png", sep=""), width=200+(15*length(Jchain$v.name)), height=100+(15*length(Dchain$v.name))) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
544 print(img) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
545 dev.off() |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
546 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
547 ggsave(paste("HeatmapDJ_", unique(dat[3])[1,1] , ".pdf", sep=""), img, width=4, height=7) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
548 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
549 write.table(x=acast(dat, Top.D.Gene~Top.J.Gene, value.var="Length"), file=paste("HeatmapDJ_", unique(dat[3])[1,1], ".txt", sep=""), sep="\t",quote=F,row.names=T,col.names=NA) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
550 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
551 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
552 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
553 DandJCount = data.frame(data.table(PRODF)[, list(Length=.N), by=c("Top.D.Gene", "Top.J.Gene", "Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
554 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
555 DandJCount$l = log(DandJCount$Length) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
556 maxDJ = data.frame(data.table(DandJCount)[, list(max=max(l)), by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
557 DandJCount = merge(DandJCount, maxDJ, by.x="Sample", by.y="Sample", all.x=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
558 DandJCount$relLength = DandJCount$l / DandJCount$max |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
559 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
560 check = is.nan(DandJCount$relLength) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
561 if(any(check)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
562 DandJCount[check,"relLength"] = 0 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
563 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
564 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
565 cartegianProductDJ = expand.grid(Top.D.Gene = Dchain$v.name, Top.J.Gene = Jchain$v.name) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
566 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
567 completeDJ = merge(DandJCount, revDchain, by.x="Top.D.Gene", by.y="v.name", all=TRUE) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
568 completeDJ = merge(completeDJ, Jchain, by.x="Top.J.Gene", by.y="v.name", all=TRUE) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
569 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
570 fltr = is.nan(completeDJ$relLength) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
571 if(any(fltr)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
572 completeDJ[fltr, "relLength"] = 1 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
573 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
574 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
575 DJList = split(completeDJ, f=completeDJ[,"Sample"]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
576 lapply(DJList, FUN=plotDJ) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
577 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
578 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
579 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
580 # ---------------------- output tables for the circos plots ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
581 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
582 print("Report Clonality - Circos data") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
583 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
584 for(smpl in unique(PRODF$Sample)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
585 PRODF.sample = PRODF[PRODF$Sample == smpl,] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
586 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
587 fltr = PRODF.sample$Top.V.Gene == "" |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
588 if(any(fltr, na.rm=T)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
589 PRODF.sample[fltr, "Top.V.Gene"] = "NA" |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
590 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
591 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
592 fltr = PRODF.sample$Top.D.Gene == "" |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
593 if(any(fltr, na.rm=T)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
594 PRODF.sample[fltr, "Top.D.Gene"] = "NA" |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
595 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
596 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
597 fltr = PRODF.sample$Top.J.Gene == "" |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
598 if(any(fltr, na.rm=T)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
599 PRODF.sample[fltr, "Top.J.Gene"] = "NA" |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
600 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
601 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
602 v.d = table(PRODF.sample$Top.V.Gene, PRODF.sample$Top.D.Gene) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
603 v.j = table(PRODF.sample$Top.V.Gene, PRODF.sample$Top.J.Gene) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
604 d.j = table(PRODF.sample$Top.D.Gene, PRODF.sample$Top.J.Gene) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
605 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
606 write.table(v.d, file=paste(smpl, "_VD_circos.txt", sep=""), sep="\t", quote=F, row.names=T, col.names=NA) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
607 write.table(v.j, file=paste(smpl, "_VJ_circos.txt", sep=""), sep="\t", quote=F, row.names=T, col.names=NA) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
608 write.table(d.j, file=paste(smpl, "_DJ_circos.txt", sep=""), sep="\t", quote=F, row.names=T, col.names=NA) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
609 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
610 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
611 # ---------------------- calculating the clonality score ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
612 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
613 if("Replicate" %in% colnames(inputdata)) #can only calculate clonality score when replicate information is available |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
614 { |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
615 print("Report Clonality - Clonality") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
616 write.table(clonalityFrame, "clonalityComplete.txt", sep="\t",quote=F,row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
617 if(clonality_method == "boyd"){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
618 samples = split(clonalityFrame, clonalityFrame$Sample, drop=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
619 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
620 for (sample in samples){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
621 res = data.frame(paste=character(0)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
622 sample_id = unique(sample$Sample)[[1]] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
623 for(replicate in unique(sample$Replicate)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
624 tmp = sample[sample$Replicate == replicate,] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
625 clone_table = data.frame(table(tmp$clonaltype)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
626 clone_col_name = paste("V", replicate, sep="") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
627 colnames(clone_table) = c("paste", clone_col_name) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
628 res = merge(res, clone_table, by="paste", all=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
629 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
630 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
631 res[is.na(res)] = 0 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
632 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
633 write.table(res, file=paste("raw_clonality_", sample_id, ".txt", sep=""), sep="\t",quote=F,row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
634 write.table(as.matrix(res[,2:ncol(res)]), file=paste("raw_clonality2_", sample_id, ".txt", sep=""), sep="\t",quote=F,row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
635 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
636 res = read.table(paste("raw_clonality_", sample_id, ".txt", sep=""), header=F, sep="\t", quote="", stringsAsFactors=F, fill=T, comment.char="") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
637 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
638 infer.result = infer.clonality(as.matrix(res[,2:ncol(res)])) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
639 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
640 #print(infer.result) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
641 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
642 write.table(data.table(infer.result[[12]]), file=paste("lymphclon_clonality_", sample_id, ".txt", sep=""), sep="\t",quote=F,row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
643 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
644 res$type = rowSums(res[,2:ncol(res)]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
645 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
646 coincidence.table = data.frame(table(res$type)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
647 colnames(coincidence.table) = c("Coincidence Type", "Raw Coincidence Freq") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
648 write.table(coincidence.table, file=paste("lymphclon_coincidences_", sample_id, ".txt", sep=""), sep="\t",quote=F,row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
649 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
650 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
651 clonalFreq = data.frame(data.table(clonalityFrame)[, list(Type=.N), by=c("Sample", "clonaltype")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
652 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
653 #write files for every coincidence group of >1 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
654 samples = unique(clonalFreq$Sample) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
655 for(sample in samples){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
656 clonalFreqSample = clonalFreq[clonalFreq$Sample == sample,] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
657 if(max(clonalFreqSample$Type) > 1){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
658 for(i in 2:max(clonalFreqSample$Type)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
659 clonalFreqSampleType = clonalFreqSample[clonalFreqSample$Type == i,] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
660 clonalityFrame.sub = clonalityFrame[clonalityFrame$clonaltype %in% clonalFreqSampleType$clonaltype,] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
661 clonalityFrame.sub = clonalityFrame.sub[order(clonalityFrame.sub$clonaltype),] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
662 write.table(clonalityFrame.sub, file=paste("coincidences_", sample, "_", i, ".txt", sep=""), sep="\t",quote=F,row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
663 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
664 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
665 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
666 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
667 clonalFreqCount = data.frame(data.table(clonalFreq)[, list(Count=.N), by=c("Sample", "Type")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
668 clonalFreqCount$realCount = clonalFreqCount$Type * clonalFreqCount$Count |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
669 clonalSum = data.frame(data.table(clonalFreqCount)[, list(Reads=sum(realCount)), by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
670 clonalFreqCount = merge(clonalFreqCount, clonalSum, by.x="Sample", by.y="Sample") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
671 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
672 ct = c('Type\tWeight\n2\t1\n3\t3\n4\t6\n5\t10\n6\t15') |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
673 tcct = textConnection(ct) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
674 CT = read.table(tcct, sep="\t", header=TRUE) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
675 close(tcct) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
676 clonalFreqCount = merge(clonalFreqCount, CT, by.x="Type", by.y="Type", all.x=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
677 clonalFreqCount$WeightedCount = clonalFreqCount$Count * clonalFreqCount$Weight |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
678 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
679 ReplicateReads = data.frame(data.table(clonalityFrame)[, list(Type=.N), by=c("Sample", "Replicate", "clonaltype")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
680 ReplicateReads = data.frame(data.table(ReplicateReads)[, list(Reads=.N), by=c("Sample", "Replicate")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
681 clonalFreqCount$Reads = as.numeric(clonalFreqCount$Reads) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
682 ReplicateReads$Reads = as.numeric(ReplicateReads$Reads) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
683 ReplicateReads$squared = as.numeric(ReplicateReads$Reads * ReplicateReads$Reads) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
684 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
685 ReplicatePrint <- function(dat){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
686 write.table(dat[-1], paste("ReplicateReads_", unique(dat[1])[1,1] , ".txt", sep=""), sep="\t",quote=F,na="-",row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
687 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
688 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
689 ReplicateSplit = split(ReplicateReads, f=ReplicateReads[,"Sample"]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
690 lapply(ReplicateSplit, FUN=ReplicatePrint) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
691 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
692 ReplicateReads = data.frame(data.table(ReplicateReads)[, list(ReadsSum=sum(as.numeric(Reads)), ReadsSquaredSum=sum(as.numeric(squared))), by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
693 clonalFreqCount = merge(clonalFreqCount, ReplicateReads, by.x="Sample", by.y="Sample", all.x=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
694 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
695 ReplicateSumPrint <- function(dat){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
696 write.table(dat[-1], paste("ReplicateSumReads_", unique(dat[1])[1,1] , ".txt", sep=""), sep="\t",quote=F,na="-",row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
697 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
698 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
699 ReplicateSumSplit = split(ReplicateReads, f=ReplicateReads[,"Sample"]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
700 lapply(ReplicateSumSplit, FUN=ReplicateSumPrint) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
701 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
702 clonalFreqCountSum = data.frame(data.table(clonalFreqCount)[, list(Numerator=sum(WeightedCount, na.rm=T)), by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
703 clonalFreqCount = merge(clonalFreqCount, clonalFreqCountSum, by.x="Sample", by.y="Sample", all.x=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
704 clonalFreqCount$ReadsSum = as.numeric(clonalFreqCount$ReadsSum) #prevent integer overflow |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
705 clonalFreqCount$Denominator = (((clonalFreqCount$ReadsSum * clonalFreqCount$ReadsSum) - clonalFreqCount$ReadsSquaredSum) / 2) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
706 clonalFreqCount$Result = (clonalFreqCount$Numerator + 1) / (clonalFreqCount$Denominator + 1) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
707 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
708 ClonalityScorePrint <- function(dat){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
709 write.table(dat$Result, paste("ClonalityScore_", unique(dat[1])[1,1] , ".txt", sep=""), sep="\t",quote=F,na="-",row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
710 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
711 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
712 clonalityScore = clonalFreqCount[c("Sample", "Result")] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
713 clonalityScore = unique(clonalityScore) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
714 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
715 clonalityScoreSplit = split(clonalityScore, f=clonalityScore[,"Sample"]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
716 lapply(clonalityScoreSplit, FUN=ClonalityScorePrint) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
717 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
718 clonalityOverview = clonalFreqCount[c("Sample", "Type", "Count", "Weight", "WeightedCount")] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
719 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
720 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
721 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
722 ClonalityOverviewPrint <- function(dat){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
723 dat = dat[order(dat[,2]),] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
724 write.table(dat[-1], paste("ClonalityOverView_", unique(dat[1])[1,1] , ".txt", sep=""), sep="\t",quote=F,na="-",row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
725 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
726 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
727 clonalityOverviewSplit = split(clonalityOverview, f=clonalityOverview$Sample) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
728 lapply(clonalityOverviewSplit, FUN=ClonalityOverviewPrint) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
729 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
730 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
731 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
732 bak = PRODF |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
733 bakun = UNPROD |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
734 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
735 imgtcolumns = c("X3V.REGION.trimmed.nt.nb","P3V.nt.nb", "N1.REGION.nt.nb", "P5D.nt.nb", "X5D.REGION.trimmed.nt.nb", "X3D.REGION.trimmed.nt.nb", "P3D.nt.nb", "N2.REGION.nt.nb", "P5J.nt.nb", "X5J.REGION.trimmed.nt.nb", "X3V.REGION.trimmed.nt.nb", "X5D.REGION.trimmed.nt.nb", "X3D.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb", "N1.REGION.nt.nb", "N2.REGION.nt.nb", "P3V.nt.nb", "P5D.nt.nb", "P3D.nt.nb", "P5J.nt.nb") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
736 if(all(imgtcolumns %in% colnames(inputdata))) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
737 { |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
738 print("found IMGT columns, running junction analysis") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
739 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
740 #ensure certain columns are in the data (files generated with older versions of IMGT Loader) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
741 col.checks = c("N.REGION.nt.nb", "N1.REGION.nt.nb", "N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
742 for(col.check in col.checks){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
743 if(!(col.check %in% names(PRODF))){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
744 print(paste(col.check, "not found adding new column")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
745 if(nrow(PRODF) > 0){ #because R is anoying... |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
746 PRODF[,col.check] = 0 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
747 } else { |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
748 PRODF = cbind(PRODF, data.frame(N3.REGION.nt.nb=numeric(0), N4.REGION.nt.nb=numeric(0))) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
749 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
750 if(nrow(UNPROD) > 0){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
751 UNPROD[,col.check] = 0 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
752 } else { |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
753 UNPROD = cbind(UNPROD, data.frame(N3.REGION.nt.nb=numeric(0), N4.REGION.nt.nb=numeric(0))) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
754 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
755 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
756 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
757 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
758 PRODF.with.D = PRODF[nchar(PRODF$Top.D.Gene, keepNA=F) > 2,] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
759 PRODF.no.D = PRODF[nchar(PRODF$Top.D.Gene, keepNA=F) < 4,] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
760 write.table(PRODF.no.D, "productive_no_D.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
761 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
762 UNPROD.with.D = UNPROD[nchar(UNPROD$Top.D.Gene, keepNA=F) > 2,] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
763 UNPROD.no.D = UNPROD[nchar(UNPROD$Top.D.Gene, keepNA=F) < 4,] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
764 write.table(UNPROD.no.D, "unproductive_no_D.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
765 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
766 num_median = function(x, na.rm=T) { as.numeric(median(x, na.rm=na.rm)) } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
767 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
768 newData = data.frame(data.table(PRODF.with.D)[,list(unique=.N, |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
769 VH.DEL=mean(.SD$X3V.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
770 P1=mean(.SD$P3V.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
771 N1=mean(rowSums(.SD[,c("N.REGION.nt.nb", "N1.REGION.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
772 P2=mean(.SD$P5D.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
773 DEL.DH=mean(.SD$X5D.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
774 DH.DEL=mean(.SD$X3D.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
775 P3=mean(.SD$P3D.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
776 N2=mean(rowSums(.SD[,c("N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
777 P4=mean(.SD$P5J.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
778 DEL.JH=mean(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
779 Total.Del=mean(rowSums(.SD[,c("X3V.REGION.trimmed.nt.nb", "X5D.REGION.trimmed.nt.nb", "X3D.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
780 Total.N=mean(rowSums(.SD[,c("N.REGION.nt.nb", "N1.REGION.nt.nb", "N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
781 Total.P=mean(rowSums(.SD[,c("P3V.nt.nb", "P5D.nt.nb", "P3D.nt.nb", "P5J.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
782 Median.CDR3.l=as.double(median(as.numeric(.SD$CDR3.Length), na.rm=T))), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
783 by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
784 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
785 write.table(newData, "junctionAnalysisProd_mean_wD.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
786 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
787 newData = data.frame(data.table(PRODF.with.D)[,list(unique=.N, |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
788 VH.DEL=num_median(.SD$X3V.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
789 P1=num_median(.SD$P3V.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
790 N1=num_median(rowSums(.SD[,c("N.REGION.nt.nb", "N1.REGION.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
791 P2=num_median(.SD$P5D.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
792 DEL.DH=num_median(.SD$X5D.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
793 DH.DEL=num_median(.SD$X3D.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
794 P3=num_median(.SD$P3D.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
795 N2=num_median(rowSums(.SD[,c("N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
796 P4=num_median(.SD$P5J.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
797 DEL.JH=num_median(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
798 Total.Del=num_median(rowSums(.SD[,c("X3V.REGION.trimmed.nt.nb", "X5D.REGION.trimmed.nt.nb", "X3D.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
799 Total.N=num_median(rowSums(.SD[,c("N.REGION.nt.nb", "N1.REGION.nt.nb", "N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
800 Total.P=num_median(rowSums(.SD[,c("P3V.nt.nb", "P5D.nt.nb", "P3D.nt.nb", "P5J.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
801 Median.CDR3.l=as.double(median(as.numeric(.SD$CDR3.Length), na.rm=T))), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
802 by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
803 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
804 write.table(newData, "junctionAnalysisProd_median_wD.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
805 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
806 newData = data.frame(data.table(UNPROD.with.D)[,list(unique=.N, |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
807 VH.DEL=mean(.SD$X3V.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
808 P1=mean(.SD$P3V.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
809 N1=mean(rowSums(.SD[,c("N.REGION.nt.nb", "N1.REGION.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
810 P2=mean(.SD$P5D.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
811 DEL.DH=mean(.SD$X5D.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
812 DH.DEL=mean(.SD$X3D.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
813 P3=mean(.SD$P3D.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
814 N2=mean(rowSums(.SD[,c("N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
815 P4=mean(.SD$P5J.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
816 DEL.JH=mean(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
817 Total.Del=mean(rowSums(.SD[,c("X3V.REGION.trimmed.nt.nb", "X5D.REGION.trimmed.nt.nb", "X3D.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
818 Total.N=mean(rowSums(.SD[,c("N.REGION.nt.nb", "N1.REGION.nt.nb", "N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
819 Total.P=mean(rowSums(.SD[,c("P3V.nt.nb", "P5D.nt.nb", "P3D.nt.nb", "P5J.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
820 Median.CDR3.l=as.double(median(as.numeric(.SD$CDR3.Length), na.rm=T))), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
821 by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
822 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
823 write.table(newData, "junctionAnalysisUnProd_mean_wD.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
824 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
825 newData = data.frame(data.table(UNPROD.with.D)[,list(unique=.N, |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
826 VH.DEL=num_median(.SD$X3V.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
827 P1=num_median(.SD$P3V.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
828 N1=num_median(rowSums(.SD[,c("N.REGION.nt.nb", "N1.REGION.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
829 P2=num_median(.SD$P5D.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
830 DEL.DH=num_median(.SD$X5D.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
831 DH.DEL=num_median(.SD$X3D.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
832 P3=num_median(.SD$P3D.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
833 N2=num_median(rowSums(.SD[,c("N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
834 P4=num_median(.SD$P5J.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
835 DEL.JH=num_median(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
836 Total.Del=num_median(rowSums(.SD[,c("X3V.REGION.trimmed.nt.nb", "X5D.REGION.trimmed.nt.nb", "X3D.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
837 Total.N=num_median(rowSums(.SD[,c("N.REGION.nt.nb", "N1.REGION.nt.nb", "N2.REGION.nt.nb", "N3.REGION.nt.nb", "N4.REGION.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
838 Total.P=num_median(rowSums(.SD[,c("P3V.nt.nb", "P5D.nt.nb", "P3D.nt.nb", "P5J.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
839 Median.CDR3.l=as.double(median(as.numeric(.SD$CDR3.Length), na.rm=T))), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
840 by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
841 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
842 write.table(newData, "junctionAnalysisUnProd_median_wD.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
843 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
844 #---------------- again for no-D |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
845 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
846 newData = data.frame(data.table(PRODF.no.D)[,list(unique=.N, |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
847 VH.DEL=mean(.SD$X3V.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
848 P1=mean(.SD$P3V.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
849 N1=mean(.SD$N.REGION.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
850 P2=mean(.SD$P5J.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
851 DEL.JH=mean(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
852 Total.Del=mean(rowSums(.SD[,c("X3V.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
853 Total.N=mean(.SD$N.REGION.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
854 Total.P=mean(rowSums(.SD[,c("P3V.nt.nb", "P5J.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
855 Median.CDR3.l=as.double(median(as.numeric(.SD$CDR3.Length), na.rm=T))), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
856 by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
857 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
858 write.table(newData, "junctionAnalysisProd_mean_nD.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
859 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
860 newData = data.frame(data.table(PRODF.no.D)[,list(unique=.N, |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
861 VH.DEL=num_median(.SD$X3V.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
862 P1=num_median(.SD$P3V.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
863 N1=num_median(.SD$N.REGION.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
864 P2=num_median(.SD$P5J.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
865 DEL.JH=num_median(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
866 Total.Del=num_median(rowSums(.SD[,c("X3V.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
867 Total.N=num_median(.SD$N.REGION.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
868 Total.P=num_median(rowSums(.SD[,c("P3V.nt.nb", "P5J.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
869 Median.CDR3.l=as.double(median(as.numeric(.SD$CDR3.Length), na.rm=T))), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
870 by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
871 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
872 write.table(newData, "junctionAnalysisProd_median_nD.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
873 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
874 newData = data.frame(data.table(UNPROD.no.D)[,list(unique=.N, |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
875 VH.DEL=mean(.SD$X3V.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
876 P1=mean(.SD$P3V.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
877 N1=mean(.SD$N.REGION.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
878 P2=mean(.SD$P5J.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
879 DEL.JH=mean(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
880 Total.Del=mean(rowSums(.SD[,c("X3V.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
881 Total.N=mean(.SD$N.REGION.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
882 Total.P=mean(rowSums(.SD[,c("P3V.nt.nb", "P5J.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
883 Median.CDR3.l=as.double(median(as.numeric(.SD$CDR3.Length), na.rm=T))), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
884 by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
885 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
886 write.table(newData, "junctionAnalysisUnProd_mean_nD.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
887 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
888 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
889 newData = data.frame(data.table(UNPROD.no.D)[,list(unique=.N, |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
890 VH.DEL=num_median(.SD$X3V.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
891 P1=num_median(.SD$P3V.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
892 N1=num_median(.SD$N.REGION.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
893 P2=num_median(.SD$P5J.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
894 DEL.JH=num_median(.SD$X5J.REGION.trimmed.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
895 Total.Del=num_median(rowSums(.SD[,c("X3V.REGION.trimmed.nt.nb", "X5J.REGION.trimmed.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
896 Total.N=num_median(.SD$N.REGION.nt.nb, na.rm=T), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
897 Total.P=num_median(rowSums(.SD[,c("P3V.nt.nb", "P5J.nt.nb"), with=F], na.rm=T)), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
898 Median.CDR3.l=as.double(median(as.numeric(.SD$CDR3.Length), na.rm=T))), |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
899 by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
900 newData[,sapply(newData, is.numeric)] = round(newData[,sapply(newData, is.numeric)],1) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
901 write.table(newData, "junctionAnalysisUnProd_median_nD.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
902 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
903 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
904 PRODF = bak |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
905 UNPROD = bakun |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
906 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
907 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
908 # ---------------------- D reading frame ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
909 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
910 D.REGION.reading.frame = PRODF[,c("Sample", "D.REGION.reading.frame")] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
911 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
912 chck = is.na(D.REGION.reading.frame$D.REGION.reading.frame) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
913 if(any(chck)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
914 D.REGION.reading.frame[chck,"D.REGION.reading.frame"] = "No D" |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
915 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
916 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
917 D.REGION.reading.frame.1 = data.frame(data.table(D.REGION.reading.frame)[, list(Freq=.N), by=c("Sample", "D.REGION.reading.frame")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
918 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
919 D.REGION.reading.frame.2 = data.frame(data.table(D.REGION.reading.frame)[, list(sample.sum=sum(as.numeric(.SD$D.REGION.reading.frame), na.rm=T)), by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
920 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
921 D.REGION.reading.frame = merge(D.REGION.reading.frame.1, D.REGION.reading.frame.2, by="Sample") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
922 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
923 D.REGION.reading.frame$percentage = round(D.REGION.reading.frame$Freq / D.REGION.reading.frame$sample.sum * 100, 1) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
924 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
925 write.table(D.REGION.reading.frame, "DReadingFrame.txt" , sep="\t",quote=F,row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
926 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
927 D.REGION.reading.frame = ggplot(D.REGION.reading.frame) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
928 D.REGION.reading.frame = D.REGION.reading.frame + geom_bar(aes( x = D.REGION.reading.frame, y = percentage, fill=Sample), stat='identity', position='dodge' ) + ggtitle("D reading frame") + xlab("Frame") + ylab("Frequency") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
929 D.REGION.reading.frame = D.REGION.reading.frame + scale_fill_manual(values=sample.colors) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
930 D.REGION.reading.frame = D.REGION.reading.frame + theme(panel.background = element_rect(fill = "white", colour="black"),text = element_text(size=15, colour="black"), axis.text.x = element_text(angle = 45, hjust = 1), panel.grid.major.y = element_line(colour = "black"), panel.grid.major.x = element_blank()) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
931 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
932 png("DReadingFrame.png") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
933 D.REGION.reading.frame |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
934 dev.off() |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
935 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
936 ggsave("DReadingFrame.pdf", D.REGION.reading.frame) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
937 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
938 # ---------------------- AA composition in CDR3 ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
939 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
940 AACDR3 = PRODF[,c("Sample", "CDR3.Seq")] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
941 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
942 TotalPerSample = data.frame(data.table(AACDR3)[, list(total=sum(nchar(as.character(.SD$CDR3.Seq)))), by=Sample]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
943 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
944 AAfreq = list() |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
945 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
946 for(i in 1:nrow(TotalPerSample)){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
947 sample = TotalPerSample$Sample[i] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
948 AAfreq[[i]] = data.frame(table(unlist(strsplit(as.character(AACDR3[AACDR3$Sample == sample,c("CDR3.Seq")]), "")))) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
949 AAfreq[[i]]$Sample = sample |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
950 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
951 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
952 AAfreq = ldply(AAfreq, data.frame) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
953 AAfreq = merge(AAfreq, TotalPerSample, by="Sample", all.x = T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
954 AAfreq$freq_perc = as.numeric(AAfreq$Freq / AAfreq$total * 100) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
955 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
956 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
957 AAorder = read.table(sep="\t", header=TRUE, text="order.aa\tAA\n1\tR\n2\tK\n3\tN\n4\tD\n5\tQ\n6\tE\n7\tH\n8\tP\n9\tY\n10\tW\n11\tS\n12\tT\n13\tG\n14\tA\n15\tM\n16\tC\n17\tF\n18\tL\n19\tV\n20\tI") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
958 AAfreq = merge(AAfreq, AAorder, by.x='Var1', by.y='AA', all.x=TRUE) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
959 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
960 AAfreq = AAfreq[!is.na(AAfreq$order.aa),] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
961 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
962 AAfreqplot = ggplot(AAfreq) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
963 AAfreqplot = AAfreqplot + geom_bar(aes( x=factor(reorder(Var1, order.aa)), y = freq_perc, fill = Sample), stat='identity', position='dodge' ) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
964 AAfreqplot = AAfreqplot + annotate("rect", xmin = 0.5, xmax = 2.5, ymin = 0, ymax = Inf, fill = "red", alpha = 0.2) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
965 AAfreqplot = AAfreqplot + annotate("rect", xmin = 3.5, xmax = 4.5, ymin = 0, ymax = Inf, fill = "blue", alpha = 0.2) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
966 AAfreqplot = AAfreqplot + annotate("rect", xmin = 5.5, xmax = 6.5, ymin = 0, ymax = Inf, fill = "blue", alpha = 0.2) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
967 AAfreqplot = AAfreqplot + annotate("rect", xmin = 6.5, xmax = 7.5, ymin = 0, ymax = Inf, fill = "red", alpha = 0.2) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
968 AAfreqplot = AAfreqplot + ggtitle("Amino Acid Composition in the CDR3") + xlab("Amino Acid, from Hydrophilic (left) to Hydrophobic (right)") + ylab("Percentage") + scale_fill_manual(values=sample.colors) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
969 AAfreqplot = AAfreqplot + theme(panel.background = element_rect(fill = "white", colour="black"),text = element_text(size=15, colour="black"), panel.grid.major.y = element_line(colour = "black"), panel.grid.major.x = element_blank()) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
970 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
971 png("AAComposition.png",width = 1280, height = 720) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
972 AAfreqplot |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
973 dev.off() |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
974 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
975 ggsave("AAComposition.pdf", AAfreqplot, width=12, height=7) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
976 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
977 write.table(AAfreq, "AAComposition.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
978 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
979 # ---------------------- AA median CDR3 length ---------------------- |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
980 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
981 median.aa.l = data.frame(data.table(PRODF)[, list(median=as.double(median(as.numeric(.SD$CDR3.Length, na.rm=T), na.rm=T))), by=c("Sample")]) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
982 write.table(median.aa.l, "AAMedianBySample.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=F) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
983 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
984 if(clonaltype != "none"){ |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
985 #generate the "Sequences that are present in more than one replicate" dataset |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
986 clonaltype.in.replicates = inputdata |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
987 clonaltype.in.replicates = clonaltype.in.replicates[clonaltype.in.replicates$Functionality %in% c("productive (see comment)","productive"),] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
988 clonaltype.in.replicates = clonaltype.in.replicates[!(is.na(clonaltype.in.replicates$ID) | is.na(clonaltype.in.replicates$Top.V.Gene) | is.na(clonaltype.in.replicates$Top.J.Gene)),] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
989 clonaltype = unlist(strsplit(clonaltype, ",")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
990 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
991 clonaltype.in.replicates$clonaltype = do.call(paste, c(clonaltype.in.replicates[clonaltype], sep = ":")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
992 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
993 clonaltype.in.replicates = clonaltype.in.replicates[!duplicated(clonaltype.in.replicates$clonaltype),] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
994 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
995 clonaltype = clonaltype[-which(clonaltype == "Sample")] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
996 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
997 clonaltype.in.replicates$clonaltype = do.call(paste, c(clonaltype.in.replicates[clonaltype], sep = ":")) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
998 clonaltype.in.replicates = clonaltype.in.replicates[,c("clonaltype","Replicate", "ID", "Sequence", "Sample")] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
999 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1000 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1001 write.table(clonaltype.in.replicates, "clonaltypes_replicates_before_table.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1002 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1003 clonaltype.counts = data.frame(table(clonaltype.in.replicates$clonaltype)) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1004 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1005 write.table(clonaltype.counts, "clonaltypes_counts.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1006 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1007 names(clonaltype.counts) = c("clonaltype", "coincidence") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1008 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1009 clonaltype.counts = clonaltype.counts[clonaltype.counts$coincidence > 1,] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1010 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1011 clonaltype.in.replicates = clonaltype.in.replicates[clonaltype.in.replicates$clonaltype %in% clonaltype.counts$clonaltype,] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1012 clonaltype.in.replicates = merge(clonaltype.in.replicates, clonaltype.counts, by="clonaltype") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1013 clonaltype.in.replicates = clonaltype.in.replicates[order(-clonaltype.in.replicates$coincidence, clonaltype.in.replicates$clonaltype, clonaltype.in.replicates$Replicate),c("coincidence","clonaltype", "Sample", "Replicate", "ID", "Sequence")] |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1014 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1015 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1016 write.table(clonaltype.in.replicates, "clonaltypes_replicates.txt" , sep="\t",quote=F,na="-",row.names=F,col.names=T) |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1017 } else { |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1018 cat("No clonaltype", file="clonaltypes_replicates_before_table.txt") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1019 cat("No clonaltype", file="clonaltypes_counts.txt") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1020 cat("No clonaltype", file="clonaltypes_replicates.txt") |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1021 } |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1022 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1023 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1024 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1025 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1026 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1027 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1028 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1029 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1030 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1031 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1032 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1033 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1034 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1035 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1036 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1037 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1038 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1039 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1040 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1041 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1042 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1043 |
81b3eb11ed2c
"planemo upload commit 6c0195cc4de6a34e2c46d875be4fc2157a21cdf6"
rhpvorderman
parents:
52
diff
changeset
|
1044 |