-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plate.pm
173 lines (131 loc) · 3.84 KB
/
Plate.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
161
162
163
164
165
166
167
168
169
170
171
172
173
package LIMS2::ReportGenerator::Plate;
use strict;
use warnings;
use Moose;
use MooseX::ClassAttribute;
use LIMS2::Exception::Implementation;
use Module::Pluggable::Object;
use List::MoreUtils qw( uniq );
use Try::Tiny;
use namespace::autoclean;
extends qw( LIMS2::ReportGenerator );
sub _report_plugins {
return grep { $_->isa( 'LIMS2::ReportGenerator::Plate' ) }
Module::Pluggable::Object->new( search_path => [ 'LIMS2::Report' ], require => 1 )->plugins;
}
## no critic(RequireFinalReturn)
sub report_class_for {
my ( $class, $plate_type ) = @_;
for my $plugin ( $class->_report_plugins ) {
if ( $plugin->handles_plate_type( $plate_type ) ) {
return $plugin;
}
}
LIMS2::Exception::Implementation->throw( "No report class implemented for plate type $plate_type" );
}
## use critic
has plate_name => (
is => 'ro',
isa => 'Str',
lazy_build => 1
);
has plate_id => (
is => 'ro',
isa => 'Int'
);
has plate => (
is => 'ro',
isa => 'LIMS2::Model::Schema::Result::Plate',
lazy_build => 1,
handles => {
species => 'species_id'
}
);
has '+param_names' => (
default => sub { [ 'plate_name' ] }
);
sub plate_types {
confess( "plate_types() must be implemented by a subclass" );
}
sub handles_plate_type {
my ( $class, $plate_type ) = @_;
for my $handled_plate_type ( @{ $class->plate_types } ) {
return 1 if $plate_type eq $handled_plate_type;
}
return;
}
sub _build_plate {
my $self = shift;
my %search = ( type => $self->plate_types );
if ( $self->plate_id ) {
$search{id} = $self->plate_id;
}
elsif ( $self->plate_name ) {
$search{name} = $self->plate_name;
}
else {
LIMS2::Exception::Implementation->throw( "PlateReportGenerator requires one of plate, plate_name, or plate_id be specified" );
}
return $self->model->retrieve_plate( \%search );
}
sub _build_plate_name {
my $self = shift;
return $self->plate->name;
}
sub base_columns {
confess "base_columns() must be implemented by a subclass";
}
sub base_data {
confess "base_data() must be implemented by a subclass";
}
sub design_and_gene_cols {
my ( $self, $well ) = @_;
my $design = $well->design;
my @gene_ids = uniq map { $_->gene_id } $design->genes;
my @gene_symbols;
try {
@gene_symbols = uniq map {
$self->model->retrieve_gene( { species => $self->species, search_term => $_ } )->{gene_symbol}
} @gene_ids;
};
return ( $design->id, join( q{/}, @gene_ids ), join( q{/}, @gene_symbols ) );
}
sub qc_result_cols {
my ( $self, $well ) = @_;
my $result = $well->well_qc_sequencing_result;
if ( $result ) {
return (
$result->test_result_url,
$result->valid_primers,
$self->boolean_str( $result->mixed_reads ),
$self->boolean_str( $result->pass )
);
}
return ('')x4;
}
sub ancestor_cols {
my ( $self, $well, $plate_type ) = @_;
my $ancestors = $well->ancestors->depth_first_traversal($well, 'in');
while ( my $ancestor = $ancestors->next ) {
if ( $ancestor->plate->type_id eq $plate_type ) {
return (
$ancestor->as_string,
$self->qc_result_cols( $ancestor )
);
}
}
return ('')x5;
}
sub pick_counts {
my ( $self, $well, $pick_type ) = @_;
# XXX This assumes the picked wells are immediate descendants of
# $well: we aren't doing a full traversal.
my @picks = grep { $_->plate->type_id eq $pick_type }
$well->descendants->output_wells( $well );
my $picked = scalar @picks;
my $accepted = scalar grep { $_->is_accepted } @picks;
return ( $picked, $accepted );
}
__PACKAGE__->meta->make_immutable;
1;
__END__