-
Notifications
You must be signed in to change notification settings - Fork 55
/
TissueExpression.pm
119 lines (90 loc) · 3.51 KB
/
TissueExpression.pm
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
=head1 CONTACT
Konrad Karczewski <[email protected]>
=cut
=head1 NAME
TissueExpression
=head1 SYNOPSIS
mv TissueExpression.pm ~/.vep/Plugins
perl variant_effect_predictor.pl -i variations.vcf --plugin TissueExpression
=head1 DESCRIPTION
A VEP plugin that overlays GTEx data on transcripts.
Requires DBD::SQLite (>=1.4.2).
=cut
package TissueExpression;
use strict;
use warnings;
our $debug = 1;
our $ddebug = 0;
use Bio::EnsEMBL::Variation::Utils::BaseVepPlugin;
use DBI;
use base qw(Bio::EnsEMBL::Variation::Utils::BaseVepPlugin);
sub get_header_info {
return {
TissueExpression => "GTEx data"
};
}
sub feature_types {
return ['Transcript'];
}
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
foreach my $parameter (@{$self->params}) {
my @param = split /:/, $parameter;
if (scalar @param == 2) {
$self->{$param[0]} = $param[1];
}
}
$self->{db_location} = $self->{db_location} || 'gtex.db';
$self->{tissues} = $self->{tissues} || 'all';
$self->{expressed_cutoff} = $self->{expressed_cutoff} || 0.1;
if ($self->{db_location} eq 'mysql') {
my $db_info = "DBI:mysql:mysql_read_default_group=loftee;mysql_read_default_file=~/.my.cnf";
$self->{database} = DBI->connect($db_info, undef, undef) or die "Cannot connect to mysql using " . $db_info . "\n";
} else {
$self->{database} = DBI->connect("dbi:SQLite:dbname=" . $self->{db_location}, "", "") or die "Cannot find gtex.db\n";
}
$self->{tissues_only} = $self->{tissues_only} || 'false';
if ($debug) {
print "Read LOFTEE parameters\n";
while (my ($key, $value) = each(%$self)) {
print $key . " : " . $value . "\n";
}
}
return $self;
}
sub run {
my ($self, $transcript_variation_allele) = @_;
my $transcript = $transcript_variation_allele->transcript_variation->transcript;
my $transcript_tissue;
if (exists($transcript->{expression_cache})) {
$transcript_tissue = $transcript->{expression_cache};
} else {
my $sql_statement;
if ($self->{tissues} eq 'all') {
$sql_statement = $self->{database}->prepare("SELECT * FROM tissues WHERE transcript = ?");
$sql_statement->execute($transcript->stable_id());
} else {
my @sql_parameters = split /,/, $self->{tissues};
$sql_statement = $self->{database}->prepare("SELECT * FROM tissues WHERE transcript = ? AND tissue IN " . join(', ', ('?') x @sql_parameters));
unshift(@sql_parameters, $transcript->stable_id());
$sql_statement->execute(@sql_parameters);
}
my @tissue_entries = ();
while (my $entry = $sql_statement->fetchrow_hashref) {
$entry->{tissue} =~ s/ /_/g;
if ($entry->{expression} > $self->{expressed_cutoff}) {
unless (lc($self->{tissues_only}) eq 'false') {
push(@tissue_entries, $entry->{tissue});
} else {
push(@tissue_entries, $entry->{tissue} . ":" . $entry->{expression});
}
}
}
$transcript_tissue = join("&", @tissue_entries);
print "Tissues: " . $transcript_tissue . "\n" if $ddebug;
$transcript->{expression_cache} = $transcript_tissue;
}
return { TissueExpression => $transcript_tissue };
}
1;