-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdgidb.pl
124 lines (108 loc) · 4.92 KB
/
dgidb.pl
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env perl
# find genes that are druggable from dgidb.org. Script taken from that site.
#You may need to install the CPAN JSON package before this script will work
#http://www.cpan.org/modules/INSTALL.html
#On a mac you can do the following:
# First configure the 'cpan' tool
# % sudo cpan
# Then at a cpan prompt:
# % get JSON
# % make JSON
# % install JSON
# % q
use strict;
use warnings;
use JSON;
use HTTP::Request::Common;
use LWP::UserAgent;
use Getopt::Long;
use Data::Dumper qw(Dumper);
my $domain = 'http://dgidb.genome.wustl.edu/';
my $api_path = '/api/v1/interactions.json';
my $genes;
my $interaction_sources;
my $gene_categories;
my $interaction_types;
my $source_trust_levels;
my $anti_neoplastic_only = '';
my $help;
my %properties = ( genes => \$genes, interaction_sources => \$interaction_sources, interaction_types => \$interaction_types, gene_categories => \$gene_categories, source_trust_levels => \$source_trust_levels );
my $ua = LWP::UserAgent->new;
parse_opts();
my $resp = $ua->request(POST $domain . $api_path, get_params_for_request());
if ($resp->is_success) {
print_response(decode_json($resp->content));
} else {
print "Something went wrong! Did you specify any genes?\n";
exit 1;
}
sub parse_opts {
GetOptions (
'genes=s' => \$genes,
'interaction_sources:s' => \$interaction_sources,
'interaction_types:s' => \$interaction_types,
'gene_categories:s' => \$gene_categories,
'source_trust_levels:s' => \$source_trust_levels,
'antineoplastic_only' => \$anti_neoplastic_only,
'help' => \$help,
);
if (!$genes || $help){
print "\n\nFor complete API documentation refer to http://dgidb.genome.wustl.edu/api";
print "\n\nRequired parameters:";
print "\n--genes (List of gene symbols. Use offical entrez symbols for best results)";
print "\n\nOptional parameters:";
print "\n--interaction_sources (Limit results to those from particular data sources. e.g. 'DrugBank', 'PharmGKB', 'TALC', 'TEND', 'TTD', 'MyCancerGenome')";
print "\n--interaction_types (Limit results to interactions with drugs that have a particular mechanism of action. e.g. 'inhibitor', 'antibody', etc.)";
print "\n--gene_categories (Limit results to genes with a particular druggable gene type. e.g. 'KINASE', 'ION CHANNEL', etc.)";
print "\n--source_trust_levels (Limit results based on trust level of the interaction source. e.g. 'Expert curated' or 'Non-curated')";
print "\n--antineoplastic_only (Limit results to anti-cancer drugs only)";
print "\n--help (Show this documentation)";
print "\n\nExample usage:";
print "\n./perl_example.pl --genes='FLT3'";
print "\n./perl_example.pl --genes='FLT3,EGFR,KRAS'";
print "\n./perl_example.pl --genes='FLT3,EGFR' --interaction_sources='TALC,TEND'";
print "\n./perl_example.pl --genes='FLT3,EGFR' --gene_categories='KINASE'";
print "\n./perl_example.pl --genes='FLT3,EGFR' --interaction_types='inhibitor'";
print "\n./perl_example.pl --genes='FLT3,EGFR' --source_trust_levels='Expert curated'";
print "\n./perl_example.pl --genes='FLT3,EGFR' --antineoplastic_only";
print "\n./perl_example.pl --genes='FLT3,EGFR,KRAS' --interaction_sources='TALC,TEND,MyCancerGenome' --gene_categories='KINASE' --interaction_types='inhibitor' --antineoplastic_only";
print "\n\n";
exit 1;
}
}
sub get_params_for_request {
my %params;
for (keys %properties) {
$params{$_} = ${$properties{$_}} if ${$properties{$_}};
}
if ($anti_neoplastic_only) {
$params{drug_types} = 'antineoplastic';
}
return \%params;
}
sub print_response {
my $json_ref = shift;
my %response_body = %{$json_ref};
print "gene_name\tdrug_name\tinteraction_type\tsource\tgene_categories\n";
#loop over each search term that was definitely matched
for (@{$response_body{matchedTerms}}) {
my $gene_name = $_->{geneName};
my @gene_categories = @{$_->{geneCategories}};
my @gene_categories_sort = sort @gene_categories;
my $gene_categories = join(",", @gene_categories_sort);
$gene_categories = lc($gene_categories);
#loop over any interactions for this gene
foreach my $interaction(@{$_->{interactions}}){
my $source = $interaction->{'source'};
my $drug_name = $interaction->{'drugName'};
my $interaction_type = $interaction->{'interactionType'};
print "$gene_name\t$drug_name\t$interaction_type\t$source\t$gene_categories\n";
}
}
#loop over each search term that wasn't matched definitely
#and print suggestions if it was ambiguous
for (@{$response_body{unmatchedTerms}}) {
print "\n" . 'Unmatched search term: ', $_->{searchTerm}, "\n";
print 'Possible suggestions: ', join(",", @{$_->{suggestions}}), "\n";
}
}