Skip to content

Commit 3a70742

Browse files
Merge branch 'master' of github.com:rust-bio/rust-bio-tools
2 parents 2d12a89 + ec81667 commit 3a70742

File tree

7 files changed

+56
-6
lines changed

7 files changed

+56
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rust-bio-tools"
3-
version = "0.10.3-alpha.0"
3+
version = "0.10.4-alpha.0"
44
authors = ["Johannes Köster <johannes.koester@tu-dortmund.de>", "Erik Clarke <ecl@pennmedicine.upenn.edu>"]
55
description = "A set of fast and robust command line utilities for bioinformatics tasks based on Rust-Bio."
66
license-file = "LICENSE.md"

src/bcf/annotate_dgidb.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,28 @@ pub fn annotate_dgidb(
3333
vcf_path: &str,
3434
api_path: String,
3535
field_name: &str,
36+
datasources: Option<Vec<&str>>,
3637
genes_per_request: usize,
3738
) -> Result<(), Box<dyn Error>> {
38-
let gene_drug_interactions = request_interaction_drugs(vcf_path, api_path, genes_per_request)?;
39+
let gene_drug_interactions =
40+
request_interaction_drugs(vcf_path, api_path, datasources, genes_per_request)?;
3941
modify_vcf_entries(vcf_path, gene_drug_interactions, field_name)
4042
}
4143

4244
fn request_interaction_drugs(
4345
vcf_path: &str,
4446
api_path: String,
47+
datasources_opt: Option<Vec<&str>>,
4548
genes_per_request: usize,
4649
) -> Result<Option<HashMap<String, Vec<(String, Vec<String>)>>>, Box<dyn Error>> {
4750
let mut genes = collect_genes(vcf_path)?;
51+
let datasources = if let Some(entries) = datasources_opt {
52+
let mut b = String::from("&interaction_sources=");
53+
b.push_str(entries.join(",").as_str());
54+
b
55+
} else {
56+
String::new()
57+
};
4858
if genes.is_empty() {
4959
return Ok(None);
5060
}
@@ -57,6 +67,7 @@ fn request_interaction_drugs(
5767
{
5868
let mut slice_api_path = api_path.clone();
5969
slice_api_path.push_str(gene_slice.join(",").as_str());
70+
slice_api_path.push_str(datasources.as_str());
6071
let res: Dgidb = reqwest::get(&slice_api_path)?.json()?;
6172

6273
for term in res.matched_terms {

src/bcf/oncoprint.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use tera::{self, Context, Tera};
1212

1313
use rust_htslib::bcf::{self, Read};
1414

15-
pub fn oncoprint(sample_calls: &HashMap<String, String>) -> Result<(), Box<dyn Error>> {
15+
pub fn oncoprint(
16+
sample_calls: &HashMap<String, String>,
17+
vep_annotation: bool,
18+
) -> Result<(), Box<dyn Error>> {
1619
let mut data = HashMap::new();
1720
for (sample, path) in sample_calls.iter().sorted() {
1821
let mut genes = HashMap::new();
@@ -55,8 +58,16 @@ pub fn oncoprint(sample_calls: &HashMap<String, String>) -> Result<(), Box<dyn E
5558
}
5659

5760
let gene = str::from_utf8(fields[3])?;
58-
let dna_alteration = str::from_utf8(fields[9])?;
59-
let protein_alteration = str::from_utf8(fields[10])?;
61+
let dna_alteration = if vep_annotation {
62+
str::from_utf8(fields[10])?
63+
} else {
64+
str::from_utf8(fields[9])?
65+
};
66+
let protein_alteration = if vep_annotation {
67+
str::from_utf8(fields[11])?
68+
} else {
69+
str::from_utf8(fields[10])?
70+
};
6071

6172
let rec = genes
6273
.entry(gene.to_owned())

src/cli.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ subcommands:
187187
short: f
188188
default_value: dgiDB_drugs
189189
help: Info field name to be used for annotation.
190+
- datasources:
191+
long: sources
192+
short: s
193+
value_name: str
194+
multiple: true
195+
help: |
196+
A list of data sources included in query. If omitted all sources are considered.
197+
A list of all sources can be found at http://dgidb.org/api/v2/interaction_sources.json
190198
- genes-per-request:
191199
long: genes-per-request
192200
short: g
@@ -208,6 +216,9 @@ subcommands:
208216
multiple: true
209217
value_name: NAME=FILE
210218
help: VCF/BCF files to include (single-sample). Name is the sample name that will be used in the oncoprint.
219+
- vep-annotation:
220+
long: vep-annotation
221+
help: Annotation field gets parsed as definded by VEP.
211222

212223
- collapse-reads-to-fragments:
213224
about: |

src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ fn main() -> Result<(), Box<dyn Error>> {
6565
&matches.value_of("vcf").unwrap(),
6666
matches.value_of("api-path").unwrap().to_string(),
6767
&matches.value_of("field").unwrap(),
68+
match matches.is_present("datasources") {
69+
true => Some(matches.values_of("datasources").unwrap().collect()),
70+
false => None,
71+
},
6872
value_t!(matches, "genes-per-request", usize).unwrap(),
6973
),
7074
("oncoprint", Some(matches)) => {
@@ -74,7 +78,7 @@ fn main() -> Result<(), Box<dyn Error>> {
7478
sample_calls.insert(e[0].to_owned(), e[1].to_owned());
7579
}
7680

77-
bcf::oncoprint::oncoprint(&sample_calls)
81+
bcf::oncoprint::oncoprint(&sample_calls, matches.is_present("vep-annotation"))
7882
}
7983
("collapse-reads-to-fragments", Some(matches)) => match matches.subcommand() {
8084
("fastq", Some(matches)) => {
11.8 KB
Binary file not shown.

tests/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,19 @@ fn test_vcf_annotate_dgidb() {
249249
);
250250
}
251251

252+
#[test]
253+
fn test_vcf_annotate_dgidb_drugbank() {
254+
assert!(
255+
Command::new("bash")
256+
.arg("-c")
257+
.arg("target/debug/rbt vcf-annotate-dgidb tests/annotate_dgidb_test.vcf -s DrugBank> /tmp/annotate_dgidb_drugbank_test.bcf")
258+
.spawn().unwrap().wait().unwrap().success());
259+
test_output(
260+
"/tmp/annotate_dgidb_drugbank_test.bcf",
261+
"tests/expected/annotate_dgidb_drugbank_test.bcf",
262+
);
263+
}
264+
252265
#[test]
253266
fn test_stats_fasta_file() {
254267
assert!(Command::new("bash")

0 commit comments

Comments
 (0)