Skip to content

Commit ec81667

Browse files
Limiting dgidb query results to specific sources (#55)
* Add parameter for dgidb data sources * Added test * Update src/cli.yaml Co-authored-by: Johannes Köster <johannes.koester@tu-dortmund.de> Co-authored-by: Johannes Köster <johannes.koester@tu-dortmund.de>
1 parent a473f5a commit ec81667

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

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/cli.yaml

Lines changed: 8 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

src/main.rs

Lines changed: 4 additions & 0 deletions
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)) => {
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)