-
Notifications
You must be signed in to change notification settings - Fork 23
/
plotUnknownResults.R
79 lines (59 loc) · 2.69 KB
/
plotUnknownResults.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
args = commandArgs(trailingOnly=TRUE)
file_prefix <- ""
if(length(args) >= 1)
{
stopifnot(length(args) >= 1)
file_prefix <- args[[1]]
} else
{
file_prefix <- "/scratch/tmp/MetaMap/hmp_set7"
file_prefix <- "tmp/hmp7_2_miniSeq+H"
}
# Rscript plotUnknownResults.R /scratch/tmp/hmp_set7_run2/withAll.wimpAnalysis.unknown
file_out <- paste(file_prefix, ".U.plots.pdf", sep = "")
idty <- read.delim(paste(file_prefix, ".U.lengthAndIdentitiesPerTaxonID", sep = ""), stringsAsFactors = F, na.strings = "", header = T)
shifted <- read.delim(paste(file_prefix, ".U.shiftedHistogramsPerTaxonID", sep = ""), stringsAsFactors = F, na.strings = "", header = T)
potDistr <- read.delim(paste(file_prefix, ".U.WIMP", sep = ""), stringsAsFactors = F, na.strings = "", header = T)
potDistr <- potDistr[potDistr[[1]] == "definedGenomes",]
pdf(file_out)
par(mfrow=c(3,3))
taxonIDs <- unique(potDistr[["taxonID"]])
potDistr[["taxonID_directIndirect"]] <- paste(potDistr[["taxonID"]], potDistr[["directIndirect"]], sep = "_")
for(taxonID in taxonIDs)
{
for(dI in c("direct", "indirect"))
{
idty_local <- idty[(idty[["taxonID"]] == taxonID) & (idty[["directIndirect"]] == dI),]
identities <- idty_local[["Identity"]]
lengths <- idty_local[["Length"]]
taxonName <- unique(potDistr[["Name"]][potDistr[["taxonID"]] == taxonID])[[1]]
n_reads <- length(identities)
f <- n_reads / dim(idty)[[1]]
plotIdentifier <- paste(taxonID, dI, sep = "_")
if(f >= 0.001)
{
f_both_pot <- potDistr[["PotFrequency"]][potDistr[["taxonID"]] == taxonID][[1]]
f_direct <- potDistr[["EMFrequency_direct"]][potDistr[["taxonID"]] == taxonID][[1]]
f_indirect <- potDistr[["EMFrequency_indirect"]][potDistr[["taxonID"]] == taxonID][[1]]
hist(lengths, main = paste("Read lengths", plotIdentifier), cex.main = 0.7)
if(any((shifted[["directIndirect"]] == dI) & (shifted[["taxonID"]] == taxonID)))
{
barplot_shifted_y <- shifted[["P"]][(shifted[["directIndirect"]] == dI) & (shifted[["taxonID"]] == taxonID)]
names(barplot_shifted_y) <- shifted[["identity"]][(shifted[["directIndirect"]] == dI) & (shifted[["taxonID"]] == taxonID)]
barplot_shifted_y <- barplot_shifted_y[order(as.numeric(names(barplot_shifted_y)))]
barplot(barplot_shifted_y, main = taxonName, cex.main = 0.7)
}
else
{
plot(0,0)
}
hist(identities, main = paste(plotIdentifier, " ", n_reads, " r.; ", f_both_pot, sep = ""), cex.main = 0.7)
if(f_both_pot > f)
{
cat(paste(plotIdentifier, ": ", f, " (from idty) vs ", f_both_pot, " (from distr)\n", sep = ""))
}
}
}
}
dev.off()
cat(paste("\nProduced file ", file_out, "\n\n", sep = ""))