76
|
1 library(reshape2)
|
|
2
|
|
3 args <- commandArgs(trailingOnly = TRUE)
|
|
4
|
|
5 gene.matches = args[1]
|
|
6 sequence.file = args[2]
|
|
7 outputdir = args[3]
|
|
8 main.html = "index.html"
|
|
9
|
|
10 setwd(outputdir)
|
|
11
|
|
12 genes = read.table(gene.matches, header=T, sep="\t", fill=T)
|
|
13 sequences = read.table(sequence.file, header=T, sep="\t", fill=T, stringsAsFactors=F, quote="")
|
|
14
|
|
15 dat = merge(sequences, genes, by="Sequence.ID")
|
|
16
|
|
17 dat$seq_conc = paste(dat$CDR1.IMGT, dat$CDR2.IMGT, dat$CDR3.IMGT, dat$FR2.IMGT, dat$FR3.IMGT)
|
|
18
|
78
|
19 IDs = dat[,c("Sequence.ID", "seq_conc", "best_match", "Functionality")]
|
76
|
20 IDs$best_match = as.character(IDs$best_match)
|
|
21
|
|
22 #dat = data.frame(data.table(dat)[, list(freq=.N), by=c("best_match", "seq_conc")])
|
|
23
|
|
24 dat = data.frame(table(dat$best_match, dat$seq_conc))
|
|
25
|
|
26 dat = dat[dat$Freq > 1,]
|
|
27
|
|
28 names(dat) = c("best_match", "seq_conc", "Freq")
|
|
29
|
|
30 dat$seq_conc = factor(dat$seq_conc)
|
|
31
|
|
32 dat = dat[order(nchar(as.character(dat$seq_conc))),]
|
|
33
|
|
34 #writing html from R...
|
|
35 td = function(val) { paste("<td>", val, "</td>", sep="") }
|
|
36 tr = function(val) { capture.output(cat("<tr>", td(val), "</tr>", sep="")) }
|
|
37 make.link = function(id, clss, val) { paste("<a href='", clss, "_", id, ".html'>", val, "</a>", sep="") }
|
|
38 tbl = function(df) { res = "<table border='1'>"; for(i in 1:nrow(df)){ res = paste(res, tr(df[i,]), sep=""); }; res = paste(res, "</table>"); }
|
|
39
|
|
40 cat("<table border='1'>", file=main.html, append=F)
|
77
|
41 cat("<caption>CDR1+CDR2+CDR3+FR2+FR3 sequences that show up more than once</caption>", file=main.html, append=T)
|
76
|
42 cat("<tr><th>Sequence</th><th>ca1</th><th>ca2</th><th>cg1</th><th>cg2</th><th>cg3</th><th>cg4</th><th>cm</th></tr>", file=main.html, append=T)
|
|
43
|
|
44 for(i in 1:nrow(dat)){
|
|
45 ca1 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & IDs$best_match == "ca1",]
|
|
46 ca2 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & IDs$best_match == "ca2",]
|
|
47
|
|
48 cg1 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & IDs$best_match == "cg1",]
|
|
49 cg2 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & IDs$best_match == "cg2",]
|
|
50 cg3 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & IDs$best_match == "cg3",]
|
|
51 cg4 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & IDs$best_match == "cg4",]
|
|
52
|
|
53 cm = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & IDs$best_match == "cm",]
|
|
54
|
|
55 id = as.numeric(dat[i,"seq_conc"])
|
|
56
|
|
57 if(nrow(ca1) > 0){
|
|
58 cat(tbl(ca1), file=paste("ca1_", id, ".html", sep=""))
|
|
59 }
|
|
60
|
|
61 if(nrow(ca2) > 0){
|
|
62 cat(tbl(ca2), file=paste("ca2_", id, ".html", sep=""))
|
|
63 }
|
|
64
|
|
65 if(nrow(cg1) > 0){
|
|
66 cat(tbl(cg1), file=paste("cg1_", id, ".html", sep=""))
|
|
67 }
|
|
68
|
|
69 if(nrow(cg2) > 0){
|
|
70 cat(tbl(cg2), file=paste("cg2_", id, ".html", sep=""))
|
|
71 }
|
|
72
|
|
73 if(nrow(cg3) > 0){
|
|
74 cat(tbl(cg3), file=paste("cg3_", id, ".html", sep=""))
|
|
75 }
|
|
76
|
|
77 if(nrow(cg4) > 0){
|
|
78 cat(tbl(cg4), file=paste("cg4_", id, ".html", sep=""))
|
|
79 }
|
|
80
|
|
81 if(nrow(cm) > 0){
|
|
82 cat(tbl(cm), file=paste("cm_", id, ".html", sep=""))
|
|
83 }
|
|
84
|
|
85 ca1.html = make.link(id, "ca1", nrow(ca1))
|
|
86 ca2.html = make.link(id, "ca2", nrow(ca2))
|
|
87
|
|
88 cg1.html = make.link(id, "cg1", nrow(cg1))
|
|
89 cg2.html = make.link(id, "cg2", nrow(cg2))
|
|
90 cg3.html = make.link(id, "cg3", nrow(cg3))
|
|
91 cg4.html = make.link(id, "cg4", nrow(cg4))
|
|
92
|
|
93 cm.html = make.link(id, "cm", nrow(cm))
|
|
94
|
|
95 rw = c(as.character(dat[i,"seq_conc"]), ca1.html, ca2.html, cg1.html, cg2.html, cg3.html, cg4.html, cm.html)
|
|
96
|
|
97 cat(tr(rw), file=main.html, append=T)
|
|
98 }
|
|
99
|
|
100 cat("</table>", file=main.html, append=T)
|