line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# POD documentation - main docs before the code |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
GenOO::GeneCollection::Factory::FromTranscriptCollection - Factory for creating GenOO::GeneCollection object from a Transcript Collection and a hash{transcript_name} = genename |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Creates GenOO::GeneCollection object from a Transcript Collection and a hash |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Preferably use it through the generic GenOO::GeneCollection::Factory |
12
|
|
|
|
|
|
|
my $factory = GenOO::GeneCollection::Factory->create( |
13
|
|
|
|
|
|
|
'FromTranscriptCollection', |
14
|
|
|
|
|
|
|
{ |
15
|
|
|
|
|
|
|
annotation_hash => \%annotation, |
16
|
|
|
|
|
|
|
transcript_collection => $transcript_collection |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
An instance of this class is a concrete factory for the creation of a |
23
|
|
|
|
|
|
|
L<GenOO::GeneCollection> object from a Transcript Collection |
24
|
|
|
|
|
|
|
and a hash that has transcript names as keys and gene names as values. |
25
|
|
|
|
|
|
|
It offers the method "read_collection" (as the consumed role requires) which returns the actual |
26
|
|
|
|
|
|
|
L<GenOO::GeneCollection> object in the form of L<GenOO::RegionCollection::Type::DoubleHashArray>. |
27
|
|
|
|
|
|
|
The latter is the implementation of the L<GenOO::RegionCollection> class based on the complex |
28
|
|
|
|
|
|
|
data structure L<GenOO::Data::Structure::DoubleHashArray>. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 EXAMPLES |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Create a concrete factory |
33
|
|
|
|
|
|
|
my $factory_implementation = GenOO::GeneCollection::Factory->create( |
34
|
|
|
|
|
|
|
'FromTranscriptCollection', |
35
|
|
|
|
|
|
|
{ |
36
|
|
|
|
|
|
|
annotation_hash => \%annotation, |
37
|
|
|
|
|
|
|
transcript_collection => $transcript_collection |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Return the actual GenOO::GeneCollection object |
42
|
|
|
|
|
|
|
my $collection = $factory_implementation->read_collection; |
43
|
|
|
|
|
|
|
print ref($collection) # GenOO::RegionCollection::Type::DoubleHashArray |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Let the code begin... |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
package GenOO::GeneCollection::Factory::FromTranscriptCollection; |
50
|
|
|
|
|
|
|
$GenOO::GeneCollection::Factory::FromTranscriptCollection::VERSION = '1.5.1'; |
51
|
1
|
|
|
1
|
|
8732
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
52
|
1
|
|
|
1
|
|
7739
|
use namespace::autoclean; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
18
|
|
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
1
|
|
132
|
use GenOO::RegionCollection::Type::DoubleHashArray; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
55
|
1
|
|
|
1
|
|
8
|
use GenOO::Gene; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
941
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
has 'annotation_hash' => ( |
58
|
|
|
|
|
|
|
isa => 'HashRef', |
59
|
|
|
|
|
|
|
is => 'ro', |
60
|
|
|
|
|
|
|
required => 1 |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
has 'transcript_collection' => ( |
63
|
|
|
|
|
|
|
isa => 'GenOO::RegionCollection', |
64
|
|
|
|
|
|
|
is => 'ro', |
65
|
|
|
|
|
|
|
required => 1 |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
with 'GenOO::RegionCollection::Factory::Requires'; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
####################################################################### |
71
|
|
|
|
|
|
|
######################## Interface Methods ######################## |
72
|
|
|
|
|
|
|
####################################################################### |
73
|
|
|
|
|
|
|
sub read_collection { |
74
|
1
|
|
|
1
|
0
|
2034
|
my ($self) = @_; |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
65
|
my $collection = GenOO::RegionCollection::Type::DoubleHashArray->new; |
77
|
1
|
|
|
|
|
11
|
my @all_genes = $self->_make_list_of_genes; |
78
|
1
|
|
|
|
|
7
|
foreach my $gene ( @all_genes ) { |
79
|
6
|
|
|
|
|
14
|
$collection->add_record($gene); |
80
|
|
|
|
|
|
|
} |
81
|
1
|
|
|
|
|
5
|
return $collection; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub _make_list_of_genes { |
85
|
1
|
|
|
1
|
|
6
|
my ($self) = @_; |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
5
|
my @outgenes; |
88
|
|
|
|
|
|
|
my %transcripts_for_genename; |
89
|
|
|
|
|
|
|
$self->transcript_collection->foreach_record_do( sub { |
90
|
70
|
|
|
70
|
|
82
|
my ($transcript) = @_; |
91
|
|
|
|
|
|
|
|
92
|
70
|
100
|
|
|
|
3635
|
if (exists $self->annotation_hash->{$transcript->id}){ |
93
|
27
|
|
|
|
|
1399
|
my $gene_name = $self->annotation_hash->{$transcript->id}; |
94
|
27
|
|
|
|
|
37
|
push @{$transcripts_for_genename{$gene_name}}, $transcript; |
|
27
|
|
|
|
|
158
|
|
95
|
|
|
|
|
|
|
} |
96
|
1
|
|
|
|
|
67
|
}); |
97
|
|
|
|
|
|
|
|
98
|
1
|
|
|
|
|
16
|
foreach my $genename (keys %transcripts_for_genename) { |
99
|
5
|
|
|
|
|
13
|
my ($merged_regions,$included_transcripts) = _merge($transcripts_for_genename{$genename}); |
100
|
5
|
|
|
|
|
18
|
for (my $i=0;$i<@$merged_regions;$i++) { |
101
|
6
|
|
|
|
|
169
|
my $gene = GenOO::Gene->new( |
102
|
|
|
|
|
|
|
name => $genename, |
103
|
|
|
|
|
|
|
transcripts => $$included_transcripts[$i] |
104
|
|
|
|
|
|
|
); |
105
|
6
|
|
|
|
|
8
|
foreach my $transcript (@{$gene->transcripts}) { |
|
6
|
|
|
|
|
175
|
|
106
|
27
|
|
|
|
|
555
|
$transcript->gene($gene); |
107
|
|
|
|
|
|
|
} |
108
|
6
|
|
|
|
|
147
|
push @outgenes, $gene; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
|
|
7
|
return @outgenes; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub _merge { |
116
|
5
|
|
|
5
|
|
7
|
my ($regions_ref, $params) = @_; |
117
|
|
|
|
|
|
|
|
118
|
5
|
50
|
|
|
|
15
|
my $offset = exists $params->{'OFFSET'} ? $params->{'OFFSET'} : 0; |
119
|
5
|
50
|
|
|
|
14
|
my $use_strand = exists $params->{'USE_STRAND'} ? $params->{'USE_STRAND'} : 1; |
120
|
|
|
|
|
|
|
|
121
|
5
|
100
|
|
|
|
21
|
my @sorted_regions = (@$regions_ref > 1) ? sort{$a->start <=> $b->start} @$regions_ref : @$regions_ref; |
|
66
|
|
|
|
|
1848
|
|
122
|
|
|
|
|
|
|
|
123
|
5
|
|
|
|
|
13
|
my @merged_regions; |
124
|
|
|
|
|
|
|
my @included_regions; |
125
|
5
|
|
|
|
|
8
|
foreach my $region (@sorted_regions) { |
126
|
|
|
|
|
|
|
|
127
|
27
|
|
|
|
|
29
|
my $merged_region = $merged_regions[-1]; |
128
|
27
|
100
|
100
|
|
|
79
|
if (defined $merged_region and $merged_region->overlaps($region, $use_strand, $offset)) { |
129
|
21
|
50
|
|
|
|
33
|
if (wantarray) { |
130
|
21
|
|
|
|
|
15
|
push @{$included_regions[-1]}, $region; |
|
21
|
|
|
|
|
31
|
|
131
|
|
|
|
|
|
|
} |
132
|
21
|
100
|
|
|
|
439
|
if ($region->stop() > $merged_region->stop) { |
133
|
3
|
|
|
|
|
75
|
$merged_region->stop($region->stop); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
else { |
137
|
6
|
|
|
|
|
185
|
push @merged_regions, GenOO::GenomicRegion->new |
138
|
|
|
|
|
|
|
( |
139
|
|
|
|
|
|
|
start => $region->start, |
140
|
|
|
|
|
|
|
stop => $region->stop, |
141
|
|
|
|
|
|
|
strand => $region->strand, |
142
|
|
|
|
|
|
|
chromosome => $region->chromosome, |
143
|
|
|
|
|
|
|
); |
144
|
6
|
50
|
|
|
|
18
|
if (wantarray) { |
145
|
6
|
|
|
|
|
16
|
push @included_regions,[$region]; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
5
|
50
|
|
|
|
10
|
if (wantarray) { |
151
|
5
|
|
|
|
|
16
|
return (\@merged_regions, \@included_regions); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
else { |
154
|
0
|
|
|
|
|
|
return \@merged_regions; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; |