/
Regulation.pm
160 lines (120 loc) · 4.16 KB
/
Regulation.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
=head1 LICENSE
Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Copyright [2016-2018] EMBL-European Bioinformatics Institute
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=cut
=head1 CONTACT
Please email comments or questions to the public Ensembl
developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
Questions may also be sent to the Ensembl help desk at
<http://www.ensembl.org/Help/Contact>.
=cut
package Bio::EnsEMBL::VEP::Pipeline::DumpVEP::Dumper::Regulation;
use strict;
use warnings;
use Scalar::Util qw(weaken);
use Bio::EnsEMBL::VEP::Config;
use Bio::EnsEMBL::VEP::AnnotationSource::Database::RegFeat;
use Bio::EnsEMBL::VEP::AnnotationSource::Cache::RegFeat;
use base qw(Bio::EnsEMBL::VEP::Pipeline::DumpVEP::Dumper);
sub run {
my $self = shift;
my $vep_params = $self->get_vep_params();
my $config = Bio::EnsEMBL::VEP::Config->new($vep_params);
my $region_size = $self->param('region_size');
my $hive_dbc = $self->dbc;
$hive_dbc->disconnect_if_idle() if defined $hive_dbc;
my $as = Bio::EnsEMBL::VEP::AnnotationSource::Database::RegFeat->new({
config => $config,
cache_region_size => $region_size,
});
# manually turn on cell type fetch, we have to do it here to avoid the check killing it
$as->{cell_type} = [1];
my $cache = Bio::EnsEMBL::VEP::AnnotationSource::Cache::RegFeat->new({
config => $config,
cache_region_size => $region_size,
dir => $self->get_cache_dir($vep_params)
});
$self->dump_chrs($as, $cache);
$self->dump_info($as, $self->get_cache_dir($vep_params));
return;
}
sub dump_info {
my ($self, $as, $dir) = @_;
my $info_file = $dir.'/info.txt_regulation';
return if -e $info_file;
open OUT, ">$info_file";
# indicate contains regulation data
print OUT "regulatory\t1\n";
# cell types
my $cell_types = $as->get_available_cell_types;
if($cell_types && @$cell_types) {
print OUT "cell_types\t".join(",", @$cell_types)."\n";
}
my $info = $as->info;
print OUT "source_$_\t".$info->{$_}."\n" for keys %$info;
close OUT;
}
sub get_dumpable_object {
my ($self, $as, $sr, $chr, $s) = @_;
my %split;
push @{$split{$_->{_vep_feature_type}}}, $_ for
map {$self->clean_regfeat($_)}
@{$as->get_features_by_regions_uncached([[$sr, $s]], 1)};
my $obj = { $chr => \%split };
# delete adaptors here before dumping
# they get reattached to the slice within get_features_by_regions_uncached
foreach my $type(keys %{$obj->{$chr}}) {
if(my $rf = $obj->{$chr}->{$type}->[0]) {
delete $rf->{slice}->{adaptor};
delete $rf->{slice}->{coord_system}->{adaptor};
}
}
return $obj;
}
sub clean_regfeat {
my $self = shift;
my $rf = shift;
delete $rf->{$_} for qw(
adaptor
binary_string
bound_start
bound_end
attribute_cache
feature_set
analysis
set
_regulatory_activity
_regulatory_build
overlapping_Peaks
);
if(defined($rf->{binding_matrix})) {
$rf->{_variation_effect_feature_cache}->{seq} = $rf->seq;
foreach my $key(qw(adaptor feature_type analysis dbID)) {
delete $rf->{binding_matrix}->{$key};
}
if (defined($rf->{binding_matrix}->{associated_transcription_factor_complexes})) {
foreach my $tfc (@{$rf->{binding_matrix}->{associated_transcription_factor_complexes}}) {
foreach my $key(qw(adaptor dbID feature_type)) {
delete $tfc->{$key};
}
foreach my $component (@{$tfc->{components}}) {
foreach my $key(qw(adaptor dbID feature_type)) {
delete $component->{$key};
}
}
}
}
}
$rf->{feature_type} = $rf->{feature_type}->{so_name} if $rf->{feature_type};
return $rf;
}
1;