0
|
1 =head1 LICENSE
|
|
2
|
|
3 Copyright (c) 1999-2012 The European Bioinformatics Institute and
|
|
4 Genome Research Limited. All rights reserved.
|
|
5
|
|
6 This software is distributed under a modified Apache license.
|
|
7 For license details, please see
|
|
8
|
|
9 http://www.ensembl.org/info/about/code_licence.html
|
|
10
|
|
11 =head1 CONTACT
|
|
12
|
|
13 Please email comments or questions to the public Ensembl
|
|
14 developers list at <dev@ensembl.org>.
|
|
15
|
|
16 Questions may also be sent to the Ensembl help desk at
|
|
17 <helpdesk@ensembl.org>.
|
|
18
|
|
19 =cut
|
|
20
|
|
21 package Bio::EnsEMBL::IndividualSliceFactory;
|
|
22
|
|
23 use strict;
|
|
24 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
|
|
25 use Bio::EnsEMBL::Utils::Sequence qw(reverse_comp);
|
|
26 use Bio::EnsEMBL::Slice;
|
|
27 use Bio::EnsEMBL::Mapper;
|
|
28 use Bio::EnsEMBL::Utils::Exception qw(throw deprecate warning);
|
|
29 use Scalar::Util qw(weaken);
|
|
30
|
|
31 =head2 new
|
|
32 =cut
|
|
33
|
|
34 sub new{
|
|
35 my $caller = shift;
|
|
36 my $class = ref($caller) || $caller;
|
|
37
|
|
38 #creates many IndividualSlice objects from the Population
|
|
39
|
|
40 my ($population_name, $coord_system, $start, $end, $strand, $seq_region_name, $seq_region_length, $adaptor) = rearrange(['POPULATION', 'COORD_SYSTEM','START','END','STRAND','SEQ_REGION_NAME','SEQ_REGION_LENGTH', 'ADAPTOR'],@_);
|
|
41
|
|
42 my $self = bless {
|
|
43 population_name => $population_name,
|
|
44 coord_system => $coord_system,
|
|
45 start => $start,
|
|
46 end => $end,
|
|
47 strand => $strand,
|
|
48 seq_region_name => $seq_region_name,
|
|
49 seq_region_length => $seq_region_length},$class;
|
|
50
|
|
51 $self->adaptor($adaptor);
|
|
52 return $self;
|
|
53 }
|
|
54
|
|
55 sub adaptor {
|
|
56 my $self = shift;
|
|
57
|
|
58 if(@_) {
|
|
59 my $ad = shift;
|
|
60 if($ad && (!ref($ad) || !$ad->isa('Bio::EnsEMBL::DBSQL::BaseAdaptor'))) {
|
|
61 throw('Adaptor argument must be a Bio::EnsEMBL::DBSQL::BaseAdaptor');
|
|
62 }
|
|
63 weaken($self->{'adaptor'} = $ad);
|
|
64 }
|
|
65
|
|
66 return $self->{'adaptor'}
|
|
67 }
|
|
68
|
|
69 sub get_all_IndividualSlice{
|
|
70 my $self = shift;
|
|
71
|
|
72 my $slice;
|
|
73 if(!$self->adaptor) {
|
|
74 warning('Cannot get IndividualSlice features without attached adaptor');
|
|
75 return '';
|
|
76 }
|
|
77 my $variation_db = $self->adaptor->db->get_db_adaptor('variation');
|
|
78
|
|
79 unless($variation_db) {
|
|
80 warning("Variation database must be attached to core database to " .
|
|
81 "retrieve variation information" );
|
|
82 return '';
|
|
83 }
|
|
84 #get the AlleleFeatures in the Population
|
|
85 my $af_adaptor = $variation_db->get_AlleleFeatureAdaptor;
|
|
86
|
|
87 if( $af_adaptor ) {
|
|
88 #set the adaptor to retrieve data from genotype table
|
|
89 $af_adaptor->from_IndividualSlice(1);
|
|
90 #get the Individual for the given strain
|
|
91 my $population_adaptor = $variation_db->get_PopulationAdaptor;
|
|
92 my $individual_adaptor = $variation_db->get_IndividualAdaptor;
|
|
93 if ($population_adaptor && $individual_adaptor){
|
|
94 $slice = Bio::EnsEMBL::Slice->new(-coord_system => $self->{'coord_system'},
|
|
95 -start => $self->{'start'},
|
|
96 -end => $self->{'end'},
|
|
97 -strand => $self->{'strand'},
|
|
98 -seq_region_name => $self->{'seq_region_name'},
|
|
99 -seq_region_length => $self->{'seq_region_length'},
|
|
100 -adaptor => $self->adaptor
|
|
101 );
|
|
102 my $population = $population_adaptor->fetch_by_name($self->{'population_name'});
|
|
103 #check that there is such population in the database
|
|
104 if (defined $population){
|
|
105 #get all the AlleleFeatures in the $population and the Slice given
|
|
106 my $allele_features = $af_adaptor->fetch_all_by_Slice($slice,$population);
|
|
107 #get Individuals in the Population
|
|
108 my $individuals = $individual_adaptor->fetch_all_by_Population($population);
|
|
109 return $self->_rearrange_Individuals_Alleles($individuals,$allele_features);
|
|
110 }
|
|
111 else{
|
|
112 warning("Population not in the database");
|
|
113 return '';
|
|
114
|
|
115 }
|
|
116 }
|
|
117 else{
|
|
118 warning("Not possible to retrieve PopulationAdaptor from the variation database");
|
|
119 return '';
|
|
120 }
|
|
121 }
|
|
122
|
|
123 else{
|
|
124 warning("Not possible to retrieve AlleleFeatureAdaptor from variation database");
|
|
125 return '';
|
|
126 }
|
|
127 }
|
|
128
|
|
129 sub _rearrange_Individuals_Alleles{
|
|
130 my $self = shift;
|
|
131 my $individuals = shift;
|
|
132 my $allele_features;
|
|
133 my $individual_slice;
|
|
134 #create the hash with all the individuals
|
|
135 my %individuals_ids;
|
|
136 #foreach of the individual, create the IndividualSlice object and add it to the mapping hash
|
|
137 foreach my $individual (@{$individuals}){
|
|
138 $individual_slice = Bio::EnsEMBL::Variation::IndividualSlice->new(
|
|
139 -coord_system => $self->{'coord_system'},
|
|
140 -start => $self->{'$start'},
|
|
141 -end => $self->{'end'},
|
|
142 -strand => $self->{'strand'},
|
|
143 -seq_region_name => $self->{'seq_region_name'},
|
|
144 -seq_region_length => $self->{'seq_region_length'},
|
|
145 -individual => $individual->name);
|
|
146
|
|
147 $individuals_ids{$individual->dbID} = $individual_slice;
|
|
148 }
|
|
149
|
|
150 #and rearrange all the AlleleFeatures to the individuals
|
|
151 foreach my $allele_feature (@{$allele_features}){
|
|
152 $individuals_ids{$allele_feature->{'_sample_id'}}->add_AlleleFeature($allele_feature);
|
|
153 }
|
|
154 my @result = values %individuals_ids;
|
|
155 return \@result;
|
|
156 }
|
|
157
|
|
158
|
|
159 1;
|