Mercurial > repos > davidvanzessen > mutation_analysis
comparison sequence_overview.r @ 76:becea91089ed draft
Uploaded
author | davidvanzessen |
---|---|
date | Mon, 09 May 2016 03:45:39 -0400 |
parents | |
children | c5c86d15cb94 |
comparison
equal
deleted
inserted
replaced
75:14749ced7ff2 | 76:becea91089ed |
---|---|
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 | |
19 IDs = dat[,c("Sequence.ID", "seq_conc", "best_match")] | |
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) | |
41 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) | |
42 | |
43 for(i in 1:nrow(dat)){ | |
44 ca1 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & IDs$best_match == "ca1",] | |
45 ca2 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & IDs$best_match == "ca2",] | |
46 | |
47 cg1 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & IDs$best_match == "cg1",] | |
48 cg2 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & IDs$best_match == "cg2",] | |
49 cg3 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & IDs$best_match == "cg3",] | |
50 cg4 = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & IDs$best_match == "cg4",] | |
51 | |
52 cm = IDs[IDs$seq_conc == dat[i,c("seq_conc")] & IDs$best_match == "cm",] | |
53 | |
54 id = as.numeric(dat[i,"seq_conc"]) | |
55 | |
56 if(nrow(ca1) > 0){ | |
57 cat(tbl(ca1), file=paste("ca1_", id, ".html", sep="")) | |
58 } | |
59 | |
60 if(nrow(ca2) > 0){ | |
61 cat(tbl(ca2), file=paste("ca2_", id, ".html", sep="")) | |
62 } | |
63 | |
64 if(nrow(cg1) > 0){ | |
65 cat(tbl(cg1), file=paste("cg1_", id, ".html", sep="")) | |
66 } | |
67 | |
68 if(nrow(cg2) > 0){ | |
69 cat(tbl(cg2), file=paste("cg2_", id, ".html", sep="")) | |
70 } | |
71 | |
72 if(nrow(cg3) > 0){ | |
73 cat(tbl(cg3), file=paste("cg3_", id, ".html", sep="")) | |
74 } | |
75 | |
76 if(nrow(cg4) > 0){ | |
77 cat(tbl(cg4), file=paste("cg4_", id, ".html", sep="")) | |
78 } | |
79 | |
80 if(nrow(cm) > 0){ | |
81 cat(tbl(cm), file=paste("cm_", id, ".html", sep="")) | |
82 } | |
83 | |
84 ca1.html = make.link(id, "ca1", nrow(ca1)) | |
85 ca2.html = make.link(id, "ca2", nrow(ca2)) | |
86 | |
87 cg1.html = make.link(id, "cg1", nrow(cg1)) | |
88 cg2.html = make.link(id, "cg2", nrow(cg2)) | |
89 cg3.html = make.link(id, "cg3", nrow(cg3)) | |
90 cg4.html = make.link(id, "cg4", nrow(cg4)) | |
91 | |
92 cm.html = make.link(id, "cm", nrow(cm)) | |
93 | |
94 rw = c(as.character(dat[i,"seq_conc"]), ca1.html, ca2.html, cg1.html, cg2.html, cg3.html, cg4.html, cm.html) | |
95 | |
96 cat(tr(rw), file=main.html, append=T) | |
97 } | |
98 | |
99 cat("</table>", file=main.html, append=T) |