Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.

Commit 63f57b9

Browse files
committed
Added consensus rank determination
1 parent a6793ce commit 63f57b9

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "taxidTools"]
55
path = taxidTools
66
url = https://github.com/CVUA-RRW/taxidTools
7+
[submodule "scripts/taxidTools"]
8+
path = scripts/taxidTools
9+
url = https://github.com/CVUA-RRW/taxidTools

Snakefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ rule get_consensus_level:
317317
cons = "reports/consensus.tsv"
318318
message:
319319
"Determining consensus ranks"
320+
params:
321+
lineage = config["taxonomy"]["rankedlineage_dmp"],
322+
nodes = config["taxonomy"]["nodes_dmp"],
320323
script:
321324
"../scripts/consensus_levels.py"
322325

@@ -330,6 +333,7 @@ rule write_report:
330333
nderep = "reports/derep_number.txt",
331334
nNfilt = "reports/high_N.txt",
332335
clusterSize = "reports/cluster_size.tsv"
336+
consensus = "reports/consensus.tsv"
333337
output:
334338
"reports/report.html"
335339
params:

scripts/consensus_levels.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import pandas as pd
5+
from taxidTools.taxidTools import Taxdump
6+
7+
def get_consensus_rank(txd, idlist):
8+
lca = txd.lowestCommonNode([str(t) for t in idlist])
9+
return(txd.getRank(lca))
10+
11+
def main(table, outfile, lineage, nodes):
12+
df = pd.read_csv(table, sep = '\t')
13+
14+
df["entries"] = df["query"] + df["query_size"]
15+
16+
dfout = pd.DataFrame()
17+
txd = Taxdump(lineage, nodes)
18+
19+
for entry in set(df["entries"]):
20+
sub = df[df["entries"] == entry].reindex()
21+
22+
new = sub.head(1)[["query_name", "query_taxid", "query_size", "query_relsize"]]
23+
24+
for i in range(0,4):
25+
taxids = list(sub[sub["distance"] <= i]["target_taxid"])
26+
taxids.extend(list(sub.head(1)["query_taxid"]))
27+
rank = get_consensus_rank(txd, taxids)
28+
29+
new[f"Consensus rank with {i} mismatches"] = rank
30+
31+
dfout = dfout.append(new, ignore_index=True)
32+
33+
dfout.to_csv(outfile, sep = '\t')
34+
35+
if __name__ == '__main__':
36+
main(snakemake.input[0], snakemake.output[0], snakemake.params["lineage"], snakemake.params["nodes"])

scripts/taxidTools

Submodule taxidTools added at 7db5eae

scripts/write_report.Rmd

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ derep <- snakemake@input[["derep"]]
4040
nderep <- snakemake@input[["nderep"]]
4141
nNfilt <- snakemake@input[["nNfilt"]]
4242
clusterSize <- snakemake@input[["clusterSize"]]
43+
consensus <- snakemake@input[["consensus"]]
4344
4445
trimming <- snakemake@params[["trimming"]]
4546
database <- snakemake@params[["database"]]
@@ -70,6 +71,37 @@ primers <- snakemake@params[["primers"]]
7071
cat("* Primer file: ", primers)
7172
```
7273

74+
## Consensus ranks
75+
76+
Achievable Taxonomic resolution for each sequence cluster at different distance (number of mismatch) levels.
77+
78+
```{r consensus}
79+
data_table <- read.csv(file = consensus, sep = '\t', check.names = FALSE)
80+
81+
datatable(data_table, filter = list(position = 'top'), rownames = FALSE, escape = FALSE,
82+
extensions= c("ColReorder", "Buttons"),
83+
selection = 'none',
84+
options = list(dom = 'BRrlftpi',
85+
autoWidth=FALSE,
86+
scrollX = TRUE,
87+
lengthMenu = list(c(50, 100, 500, -1),
88+
c('50', '100', '500', 'All')),
89+
ColReorder = TRUE,
90+
buttons = list('copy',
91+
'print',
92+
list(
93+
extend = 'collection',
94+
buttons = c('csv', 'excel', 'pdf'),
95+
text = 'Download'
96+
),
97+
I('colvis')
98+
),
99+
deferRender = TRUE,
100+
scroller = TRUE
101+
)
102+
)
103+
```
104+
73105
## Pairwise distances
74106

75107

0 commit comments

Comments
 (0)