-
Notifications
You must be signed in to change notification settings - Fork 0
/
CrisprEsQc.pm
237 lines (177 loc) · 7.05 KB
/
CrisprEsQc.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package LIMS2::Model::Plugin::CrisprEsQc;
use strict;
use warnings FATAL => 'all';
use Moose::Role;
use DDP;
use namespace::autoclean;
requires qw( schema check_params throw retrieve log trace );
sub pspec_create_crispr_es_qc {
return {
id => { validate => 'uuid' },
created_by => { validate => 'existing_user', post_filter => 'user_id_for', rename => 'created_by_id' },
created_at => { validate => 'date_time', post_filter => 'parse_date_time', optional => 1 },
species => { validate => 'existing_species', rename => 'species_id' },
sequencing_project => { validate => 'non_empty_string' },
sub_project => { validate => 'non_empty_string' }
};
}
=head create_crispr_es_qc
Create a new crispr_es_qc with attached wells.
=cut
sub create_crispr_es_qc_run {
my ( $self, $params ) = @_;
my $validated_params = $self->check_params( $params, $self->pspec_create_crispr_es_qc );
#these will be created separately
my $wells = delete $validated_params->{wells};
my $qc_run = $self->schema->resultset('CrisprEsQcRuns')->create( $validated_params );
#later this will be moved to its own method as we won't create
#wells when we create the qc
for my $well ( @{ $wells } ) {
$well->{crispr_es_qc_run_id} = $qc_run->id;
$well->{species} = $qc_run->species_id;
$self->create_crispr_es_qc_well( $well );
}
return $qc_run;
}
sub pspec_create_crispr_es_qc_well {
return {
well_id => { validate => 'integer' },
fwd_read => { validate => 'non_empty_string', optional => 1 },
rev_read => { validate => 'non_empty_string', optional => 1 },
crispr_chr_name => { validate => 'existing_chromosome', optional => 1 },
crispr_start => { validate => 'integer', optional => 1},
crispr_end => { validate => 'integer', optional => 1},
analysis_data => { validate => 'json' },
vcf_file => { validate => 'non_empty_string', optional => 1 },
crispr_es_qc_run_id => { validate => 'non_empty_string' },
species => { validate => 'existing_species' },
crispr_damage_type => { validate => 'existing_crispr_damage_type', optional => 1, rename => 'crispr_damage_type_id' },
variant_size => { validate => 'integer', optional => 1 },
accepted => { validate => 'boolean', optional => 1 },
};
}
=head2 create_crispr_es_qc_well
Given a QC run add a well with the given parameters
=cut
sub create_crispr_es_qc_well {
my ( $self, $params ) = @_;
my $validated_params = $self->check_params( $params, $self->pspec_create_crispr_es_qc_well );
# if the qc well has been marked accepted run this logic
if ( $validated_params->{accepted} ) {
my $well = $self->retrieve_well( { id => $validated_params->{well_id} } );
# only mark qc accepted if the linked well is not already accepted in another run
if ( $well->accepted ) {
delete $validated_params->{accepted};
}
# mark the linked well accepted
else {
$well->update( { accepted => 1 } );
}
}
my $species = delete $validated_params->{species};
if ( $validated_params->{crispr_chr_name} ) {
my $chr_name = delete $validated_params->{crispr_chr_name};
my $chr = $self->schema->resultset('Chromosome')->find(
{
name => $chr_name,
species_id => $species,
}
);
$validated_params->{crispr_chr_id} = $chr->id;
}
return $self->schema->resultset('CrisprEsQcWell')->create( $validated_params );
}
sub pspec_retrieve_crispr_es_qc_well {
return {
id => { validate => 'integer' },
};
}
=head2 retrieve_crispr_es_qc_well
Return a crispr_es_qc_run result for a given id
=cut
sub retrieve_crispr_es_qc_well {
my ( $self, $params ) = @_;
my $validated_params = $self->check_params( $params, $self->pspec_retrieve_crispr_es_qc_well );
return $self->retrieve( CrisprEsQcWell => $validated_params );
}
sub pspec_delete_crispr_es_qc_run {
return {
id => { validate => 'non_empty_string' },
};
}
=head2
Delete a run and all of its associated crispr_es_qc_wells
=cut
sub delete_crispr_es_qc_run {
my ( $self, $params ) = @_;
my $validated_params = $self->check_params( $params, $self->pspec_delete_crispr_es_qc_run );
my $run = $self->schema->resultset('CrisprEsQcRuns')->find( $validated_params );
$self->throw(
NotFound => { entity_class => 'CrisprEsQcRuns', search_params => $validated_params }
) unless $run;
#if we can later create plates off this we will have to add a check in here
#to make sure none have been made
$run->crispr_es_qc_wells->delete;
$run->delete;
return 1;
}
sub pspec_retrieve_crispr_es_qc_run {
return {
id => { validate => 'non_empty_string' },
};
}
=head2 retrieve_crispr_es_qc_run
Return a crispr_es_qc_run result for a given id
=cut
sub retrieve_crispr_es_qc_run {
my ( $self, $params ) = @_;
my $validated_params = $self->check_params( $params, $self->pspec_retrieve_crispr_es_qc_run );
return $self->retrieve( CrisprEsQcRuns => $validated_params );
}
=head2 validate_crispr_es_qc_run
Update a crispr es qc run plus all of its wells to validated.
=cut
sub validate_crispr_es_qc_run {
my ( $self, $params ) = @_;
my $crispr_es_qc_run = $self->retrieve_crispr_es_qc_run( $params );
$crispr_es_qc_run->update( { validated => 1 } );
$self->log->info( 'Validated crispr es qc run ' . $crispr_es_qc_run->id );
return;
}
sub pspec_update_crispr_es_qc_well {
return {
id => { validate => 'integer' },
damage_type => {
validate => 'existing_crispr_damage_type',
optional => 1,
rename => 'crispr_damage_type_id'
},
variant_size => { validate => 'integer', optional => 1 },
accepted => { validate => 'boolean_string', optional => 1 },
MISSING_OPTIONAL_VALID => 1,
};
}
=head2 update_crispr_well_damage
Update the crispr_damage type value of a crispr es qc well row
=cut
sub update_crispr_es_qc_well{
my ( $self, $params ) = @_;
my $validated_params = $self->check_params( $params, $self->pspec_update_crispr_es_qc_well );
my $id = delete $validated_params->{id};
my $qc_well = $self->schema->resultset('CrisprEsQcWell')->find( { id => $id } );
unless ( $qc_well ) {
$self->throw(
NotFound => { entity_class => 'CrisprEsQcWell', search_params => { id => $id } } );
}
$qc_well->update( $validated_params );
$self->log->info( "Updated crispr es qc well "
. $qc_well->id . ' to: ' . p( $validated_params ) );
if ( exists $validated_params->{accepted} ) {
my $well = $qc_well->well;
$well->update( { accepted => $validated_params->{accepted} } );
$self->log->info( "Updated $well well accepted " . $validated_params->{accepted} );
}
return $qc_well;
}
1;
__END__