Browse files

Merge branch 'develop' of /software/vertres/git/origin/vr-codebase in…

…to develop
  • Loading branch information...
2 parents e002913 + dc9444d commit 414ebf571507598e02ce1514c74a2ffc373d3178 @pd3 pd3 committed Jul 10, 2012
View
125 modules/VRTrack/AutoQC.pm
@@ -0,0 +1,125 @@
+package VRTrack::AutoQC;
+
+=head1 NAME
+
+VRTrack::AutoQC - Sequence Tracking Mapstats AutoQC Test result object
+
+=head1 SYNOPSIS
+ my $autoqc = VRTrack::AutoQC->new($vrtrack, $id);
+
+ $autoqc->id('104');
+
+=head1 DESCRIPTION
+
+An object describing the properties of an autoqc test result for a mapstats entry.
+
+=head1 AUTHOR
+
+mp15@sanger.ac.uk (author)
+
+=head1 METHODS
+
+=cut
+
+use strict;
+use warnings;
+use Carp qw(cluck confess);
+
+use base qw(VRTrack::Named_obj);
+
+###############################################################################
+# Class methods
+###############################################################################
+
+=head2 new
+
+ Arg [1] : database handle to seqtracking database
+ Arg [2] : autoqc id
+ Example : my $autoqc = VRTrack::AutoQC->new($vrtrack, $id)
+ Description: Returns AutoQC object by autoqc_id
+ Returntype : VRTrack::AutoQC object
+
+=cut
+
+sub new {
+ my $class = shift;
+ my $self = $class->SUPER::new(@_);
+ return $self;
+}
+
+=head2 fields_dispatch
+
+ Arg [1] : none
+ Example : my $fieldsref = $lane->fields_dispatch();
+ Description: Returns hashref dispatch table keyed on database field
+ Used internally for new and update methods
+ Returntype : hashref
+
+=cut
+
+sub fields_dispatch {
+ my $self = shift;
+
+ my %fields = (
+ autoqc_id => sub { $self->id(@_)},
+ mapstats_id => sub { $self->mapstats_id(@_) },
+ test => sub { $self->test(@_)},
+ result => sub { $self->result(@_)},
+ reason => sub { $self->reason(@_)},
+ );
+
+ return \%fields;
+}
+
+=head2 create
+
+ Arg [1] : database handle to seqtracking database
+ Arg [2] : autoqc test
+ Arg [3] : autoqc result
+ Arg [4] : autoqc reason
+ Example : my $autoqc = VRTrack::AutoQC->new($vrtrack,$test,$result,$reason);
+ Description: Class method. Creates new AutoQC object in the database.
+ Returntype : VRTrack::AutoQC object
+
+=cut
+
+sub create {
+ my ($self, $vrtrack,$test,$result,$reason) = @_;
+ return $self->SUPER::create($vrtrack, test => $test, result=> $result, reason => $reason);
+}
+
+
+###############################################################################
+# Object methods
+###############################################################################
+
+=head2 id
+
+ Arg [1] : id (optional)
+ Example : my $id = $autoqc->id();
+ $autoqc->id('104');
+ Description: Get/Set for ID of an autoqc object
+ Returntype : Internal ID integer
+
+=cut
+
+sub test {
+ my $self = shift;
+ return $self->_get_set('test', 'string', @_);
+}
+sub result {
+ my $self = shift;
+ return $self->_get_set('result', 'number', @_);
+}
+sub reason {
+ my $self = shift;
+ return $self->_get_set('reason', 'string', @_);
+}
+sub mapstats_id {
+ my $self = shift;
+ return $self->_get_set('mapstats_id', 'number', @_);
+}
+
+
+1;
+
View
6 modules/VRTrack/Factory.pm
@@ -134,11 +134,9 @@ sub databases {
my %tables = map { s/`//g; s/^$db\.//; $_ => 1 } $dbh->tables();
- foreach my $etable (keys %expected_tables) {
- next DB unless exists $tables{$etable};
- }
+ next DB unless exists $tables{schema_version};
foreach my $table (keys %tables) {
- next DB unless exists $expected_tables{$table};
+ next DB unless exists $expected_tables{$table}; # we're assuming no schema update will ever drop a table
}
my $sql = qq[ select * from schema_version ];
View
76 modules/VRTrack/Mapstats.pm
@@ -26,6 +26,7 @@ use strict;
use warnings;
use Carp qw(cluck confess);
use VRTrack::Image;
+use VRTrack::AutoQC;
use VRTrack::Mapper;
use VRTrack::Assembly;
use VRTrack::Exome_design;
@@ -957,6 +958,52 @@ sub image_ids {
return $self->_get_child_ids('VRTrack::Image');
}
+=head2 add_autoqc
+
+ Arg [1] : autoqc test
+ Arg [2] : autoqc result
+ Arg [3] : autoqc reason
+ Example : my $autoqc = $mapstats->add_autoqc('NPG QC status',0,'The lane failed the NPG QC check, so auto-fail');
+ Description: Adds an autoqc test result to mapstats; If object already exists for this test, updates the result and reason.
+ Returntype : VRTrack::AutoQC object
+
+=cut
+
+sub add_autoqc {
+
+ my ($self,$test,$result,$reason) = @_;
+ my $dbh = $self->{vrtrack}->{_dbh};
+ my $sql = qq[select autoqc_id from autoqc where mapstats_id = ? and test = ?];
+ my $sth = $dbh->prepare($sql);
+
+ $sth->execute($self->id(), $test);
+ my $row = $sth->fetchrow_hashref;
+ if ($row) {
+ my $autoqc_id = $row->{'autoqc_id'};
+ my $autoqc = $self->get_autoqc_by_id($autoqc_id);
+ $autoqc->result($result);
+ $autoqc->reason($reason);
+ $autoqc->update;
+ return $autoqc;
+ }
+ else{
+ return $self->_add_child_object(undef, 'VRTrack::AutoQC', $test,$result,$reason );
+ }
+}
+
+=head2 get_autoqc_by_id
+
+ Arg [1] : file name
+ Example : my $autoqc = $mapstats->get_autoqc_by_id(100);
+ Description: retrieve autoqc object on this mapstats by autoqc id
+ Returntype : VRTrack::AutoQC object
+
+=cut
+
+sub get_autoqc_by_id {
+ my $self = shift;
+ return $self->_get_child_by_field_value('autoqcs', 'id', @_);
+}
=head2 changed
@@ -968,6 +1015,35 @@ sub image_ids {
=cut
+=head2 autoqcs
+
+ Arg [1] : None
+ Example : my $autoqcs = $mapstats-->autoqcs();
+ Description: Returns a ref to an array of auto qc test results associated with these mapstas
+ Returntype : ref to array of VRTrack::AutoQC objects
+
+=cut
+
+sub autoqcs {
+ my $self = shift;
+ return $self->_get_child_objects('VRTrack::AutoQC');
+}
+
+=head2 autoqc_ids
+
+ Arg [1] : None
+ Example : my $ids = $mapstats--->autoqc_ids();
+ Description: Returns a ref to an array of the autoqc ids that are associated with these mapstas
+ Returntype : ref to array of ids
+
+=cut
+
+sub autoqc_ids {
+ my $self = shift;
+ return $self->_get_child_ids('VRTrack::AutoQC');
+}
+
+
=head2 descendants
View
93 modules/VRTrack/VRTrack.pm
@@ -46,7 +46,7 @@ use VRTrack::File;
use VRTrack::Core_obj;
use VRTrack::History;
-use constant SCHEMA_VERSION => '19';
+use constant SCHEMA_VERSION => '20';
our $DEFAULT_PORT = 3306;
@@ -346,6 +346,39 @@ sub hierarchy_path_of_lane {
my ($self, $lane, $template) = @_;
($lane && ref($lane) && $lane->isa('VRTrack::Lane')) || confess "A VRTrack::Lane must be supplied\n";
+ return $self->hierarchy_path_of_object($lane,$template);
+}
+
+=head2 hierarchy_path_of_object
+
+ Arg [1] : VRTrack::Project, VRTrack::Sample, VRTrack::Library or VRTrack::Lane object
+ Arg [2] : hierarchy template (Optional)
+ Example : my $lane_hier = $track->hierarchy_path_of_object($vrlane);
+ Description: Retrieve the hierarchy path for a project, sample, library or lane according
+ to the template defined by environment variable 'DATA_HIERARCHY', to the
+ root of the hierarchy. Template defaults to:
+ 'project:sample:technology:library:lane'
+ Possible terms are 'genus', 'species-subspecies', 'strain',
+ 'individual', 'project', 'projectid', 'sample', 'technology',
+ 'library', 'lane'. ('strain' and 'individual' are synonymous)
+ Does not check the filesystem.
+ Returns undef if hierarchy cannot be built.
+ Returntype : string
+
+=cut
+
+sub hierarchy_path_of_object {
+ my ($self, $object, $template) = @_;
+
+ # Object types
+ my %object_type = ('VRTrack::Project' => 'project',
+ 'VRTrack::Sample' => 'sample',
+ 'VRTrack::Library' => 'library',
+ 'VRTrack::Lane' => 'lane');
+
+ (defined($object) && exists($object_type{ref($object)})) || confess "A recognised object type must be supplied\n";
+
+
# For all acceptable terms, we generate the corresponding word, but for
# others we just append the term itself to the hierarchy. This allows for
# words like DATA or TRACKING to be injected into the hierarchy without much
@@ -354,12 +387,15 @@ sub hierarchy_path_of_lane {
# Since not all possible terms might be used in the template, we will only
# create objects if necessary (accessing db is expensive).
my %objs;
- my $get_lane = sub { return $lane; };
- my $get_lib = sub { $objs{library} ||= VRTrack::Library->new($self, $lane->library_id); return $objs{library}; };
- my $get_sample = sub { $objs{sample} ||= VRTrack::Sample->new($self, &{$get_lib}->sample_id); return $objs{sample}; };
- my $get_project = sub { $objs{project} ||= VRTrack::Project->new($self, &{$get_sample}->project_id); return $objs{project}; };
- my $get_individual = sub { $objs{individual} ||= VRTrack::Individual->new($self, &{$get_sample}->individual_id); return $objs{individual}; };
- my $get_species = sub { $objs{species} ||= VRTrack::Species->new($self, &{$get_individual}->species_id); return $objs{species}; };
+
+ $objs{$object_type{ref($object)}} = $object; # set input object
+
+ my $get_lane = sub { return $objs{lane}; };
+ my $get_lib = sub { $objs{library} ||= eval { VRTrack::Library->new($self, &{$get_lane}->library_id) }; return $objs{library}; };
+ my $get_sample = sub { $objs{sample} ||= eval { VRTrack::Sample->new($self, &{$get_lib}->sample_id) }; return $objs{sample}; };
+ my $get_project = sub { $objs{project} ||= eval { VRTrack::Project->new($self, &{$get_sample}->project_id) }; return $objs{project}; };
+ my $get_individual = sub { $objs{individual} ||= eval { VRTrack::Individual->new($self, &{$get_sample}->individual_id) }; return $objs{individual}; };
+ my $get_species = sub { $objs{species} ||= eval { VRTrack::Species->new($self, &{$get_individual}->species_id) }; return $objs{species}; };
my %terms = (genus => $get_species,
'species-subspecies' => $get_species,
strain => $get_individual,
@@ -376,7 +412,7 @@ sub hierarchy_path_of_lane {
$template = $ENV{DATA_HIERARCHY} || 'project:sample:technology:library:lane';
}
my @path = split(/:/, $template);
-
+
my @hier_path_bits;
foreach my $term (@path) {
my $get_method = $terms{$term};
@@ -414,6 +450,8 @@ sub hierarchy_path_of_lane {
else {
push(@hier_path_bits, $term);
}
+
+ last if $term eq $object_type{ref($object)}; # Finish at object directory
}
return File::Spec->catdir(@hier_path_bits);
@@ -1404,7 +1442,7 @@ CREATE TABLE `schema_version` (
PRIMARY KEY (`schema_version`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-insert into schema_version(schema_version) values (19);
+insert into schema_version(schema_version) values (20);
--
-- Table structure for table `assembly`
@@ -1462,7 +1500,7 @@ CREATE TABLE `file` (
`raw_reads` bigint(20) unsigned DEFAULT NULL,
`raw_bases` bigint(20) unsigned DEFAULT NULL,
`mean_q` float unsigned DEFAULT NULL,
- `md5` varchar(40) DEFAULT NULL,
+ `md5` char(32) DEFAULT NULL,
`note_id` mediumint(8) unsigned DEFAULT NULL,
`changed` datetime NOT NULL DEFAULT '0000-00-00',
`latest` tinyint(1) DEFAULT '0',
@@ -1480,7 +1518,7 @@ DROP TABLE IF EXISTS `image`;
CREATE TABLE `image` (
`image_id` mediumint(8) unsigned NOT NULL auto_increment,
`mapstats_id` mediumint(8) unsigned NOT NULL DEFAULT 0,
- `name` varchar(40) NOT NULL DEFAULT '',
+ `name` varchar(255) NOT NULL DEFAULT '',
`caption` varchar(40) DEFAULT NULL,
`image` MEDIUMBLOB,
PRIMARY KEY (`image_id`),
@@ -1628,7 +1666,7 @@ CREATE TABLE `seq_request` (
DROP TABLE IF EXISTS `library_type`;
CREATE TABLE `library_type` (
`library_type_id` smallint(5) unsigned NOT NULL auto_increment,
- `name` varchar(40) NOT NULL DEFAULT '',
+ `name` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`library_type_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
@@ -1639,7 +1677,7 @@ CREATE TABLE `library_type` (
DROP TABLE IF EXISTS `mapper`;
CREATE TABLE `mapper` (
`mapper_id` smallint(5) unsigned NOT NULL auto_increment,
- `name` varchar(40) NOT NULL DEFAULT '',
+ `name` varchar(255) NOT NULL DEFAULT '',
`version` varchar(40) NOT NULL DEFAULT 0,
PRIMARY KEY (`mapper_id`),
UNIQUE KEY `name_v` (`name`, `version`)
@@ -1710,7 +1748,7 @@ CREATE TABLE `mapstats` (
DROP TABLE IF EXISTS `population`;
CREATE TABLE `population` (
`population_id` smallint(5) unsigned NOT NULL auto_increment,
- `name` varchar(40) NOT NULL DEFAULT '',
+ `name` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`population_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
@@ -1776,7 +1814,7 @@ CREATE TABLE `project` (
DROP TABLE IF EXISTS `study`;
CREATE TABLE `study` (
`study_id` smallint(5) unsigned NOT NULL auto_increment,
-`name` varchar(40) NOT NULL DEFAULT '',
+`name` varchar(255) NOT NULL DEFAULT '',
`acc` varchar(40) DEFAULT NULL,
`ssid` mediumint(8) unsigned DEFAULT NULL,
`note_id` mediumint(8) unsigned DEFAULT NULL,
@@ -1806,7 +1844,7 @@ CREATE TABLE `sample` (
`sample_id` smallint(5) unsigned NOT NULL DEFAULT 0,
`project_id` smallint(5) unsigned NOT NULL DEFAULT 0,
`ssid` mediumint(8) unsigned DEFAULT NULL,
- `name` varchar(40) NOT NULL DEFAULT '',
+ `name` varchar(255) NOT NULL DEFAULT '',
`hierarchy_name` varchar(40) NOT NULL DEFAULT '',
`individual_id` smallint(5) unsigned DEFAULT NULL,
`note_id` mediumint(8) unsigned DEFAULT NULL,
@@ -1826,7 +1864,7 @@ CREATE TABLE `sample` (
DROP TABLE IF EXISTS `seq_centre`;
CREATE TABLE `seq_centre` (
`seq_centre_id` smallint(5) unsigned NOT NULL auto_increment,
- `name` varchar(40) NOT NULL DEFAULT '',
+ `name` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`seq_centre_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
@@ -1837,7 +1875,7 @@ CREATE TABLE `seq_centre` (
DROP TABLE IF EXISTS `seq_tech`;
CREATE TABLE `seq_tech` (
`seq_tech_id` smallint(5) unsigned NOT NULL auto_increment,
- `name` varchar(40) NOT NULL DEFAULT '',
+ `name` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`seq_tech_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
@@ -1849,14 +1887,31 @@ DROP TABLE IF EXISTS `submission`;
CREATE TABLE `submission` (
`submission_id` smallint(5) unsigned NOT NULL auto_increment,
`date` datetime NOT NULL DEFAULT '0000-00-00',
- `name` varchar(40) NOT NULL DEFAULT '',
+ `name` varchar(255) NOT NULL DEFAULT '',
`acc` varchar(40) DEFAULT NULL,
PRIMARY KEY (`submission_id`),
UNIQUE KEY `acc` (`acc`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
+-- Table structure for table `autoqc`
+--
+
+DROP TABLE IF EXISTS `autoqc`;
+CREATE TABLE `autoqc`
+(
+ `autoqc_id` mediumint(8) unsigned NOT NULL auto_increment,
+ mapstats_id mediumint(8) unsigned NOT NULL DEFAULT 0,
+ test varchar(50) NOT NULL default '',
+ result tinyint(1) DEFAULT 0,
+ reason varchar(200) NOT NULL default '',
+ PRIMARY KEY (`autoqc_id`),
+ KEY `mapstats_id` (`mapstats_id`),
+ UNIQUE KEY `mapstats_test` (`mapstats_id`, `test`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+--
-- Views
--
View
38 scripts/vrtracking_tool
@@ -371,28 +371,22 @@ sub get_vrtrack_objects
sub get_vrtrack_directory
{
- my ($vrtrack, $vrobject) = @_;
- if ($vrobject->isa('VRTrack::Lane')) {
- return $vrtrack->hierarchy_path_of_lane_name($vrobject->name);
- }
- #project:sample:technology:library
- elsif ($vrobject->isa('VRTrack::Library')) {
- my $sample = VRTrack::Sample->new($vrtrack, $vrobject->sample_id);
- my $project = VRTrack::Project->new($vrtrack, $sample->project_id);
- my $seq_tech_name = $vrobject->seq_tech() ? $vrobject->seq_tech->name : 'SLX';
- return File::Spec->catdir($project->hierarchy_name, $sample->hierarchy_name, $seq_tech_name, $vrobject->hierarchy_name);
- }
- elsif ($vrobject->isa('VRTrack::Sample')) {
- my $project = VRTrack::Project->new($vrtrack, $vrobject->project_id);
- return File::Spec->catdir($project->hierarchy_name, $vrobject->hierarchy_name)
- }
- elsif ($vrobject->isa('VRTrack::Project')) {
- return $vrobject->hierarchy_name;
- }
- else {
- croak "Unable to retrieve the tracking directory as the tracking object type is not recognised.\n";
- }
-}
+ my ($vrtrack, $vrobject) = @_;
+
+ my %recognised_type = ('VRTrack::Project' => 1,
+ 'VRTrack::Sample' => 1,
+ 'VRTrack::Library' => 1,
+ 'VRTrack::Lane' => 1);
+
+ # Check object
+ croak "Unable to retrieve the tracking directory as the tracking object is not defined.\n" unless defined $vrobject;
+ croak "Unable to retrieve the tracking directory as the tracking object type is not recognised.\n" unless $recognised_type{ref($vrobject)};
+
+ my $vrtrack_directory = $vrtrack->hierarchy_path_of_object($vrobject);
+ croak "Unable to retrieve the tracking directory as could not build hierarchy path for tracking object.\n" unless defined $vrtrack_directory;
+
+ return $vrtrack_directory;
+}
sub get_reset_flag_objects
{
View
16 sql/VRTrack_schema_19_to_20.sql
@@ -0,0 +1,16 @@
+ALTER TABLE `file` MODIFY `md5` char(32);
+ALTER TABLE `image` MODIFY `name` varchar(255);
+ALTER TABLE `library` MODIFY `name` varchar(255);
+ALTER TABLE `library_type` MODIFY `name` varchar(255);
+ALTER TABLE `mapper` MODIFY `name` varchar(255);
+ALTER TABLE `population` MODIFY `name` varchar(255);
+ALTER TABLE `study` MODIFY `name` varchar(255);
+ALTER TABLE `sample` MODIFY `name` varchar(255);
+ALTER TABLE `seq_centre` MODIFY `name` varchar(255);
+ALTER TABLE `seq_tech` MODIFY `name` varchar(255);
+ALTER TABLE `submission` MODIFY `name` varchar(255);
+
+DROP TABLE IF EXISTS `autoqc`;
+CREATE TABLE `autoqc` (`autoqc_id` mediumint(8) unsigned NOT NULL auto_increment, mapstats_id mediumint(8) unsigned NOT NULL DEFAULT 0, test varchar(50) NOT NULL default '', result tinyint(1) DEFAULT 0, reason varchar(200) NOT NULL default '', PRIMARY KEY (`autoqc_id`), KEY `mapstats_id` (`mapstats_id`), UNIQUE KEY `mapstats_test` (`mapstats_id`, `test`)) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+update schema_version set schema_version=20;
View
31 t/VRTrack/hierarchy_noreq.t
@@ -1,6 +1,7 @@
#!/usr/bin/perl -w
use strict;
use warnings;
+use Test::Exception;
BEGIN {
use Test::Most;
@@ -11,7 +12,7 @@ BEGIN {
plan skip_all => "Skipping all tests because VRTrack tests have not been configured";
}
else {
- plan tests => 134;
+ plan tests => 149;
}
use_ok('VRTrack::VRTrack');
@@ -269,6 +270,34 @@ is $vrtrack->hierarchy_path_of_lane($vrlane), 'species/foo/lib_a', 'hierarchy_pa
# $ENV{DATA_HIERARCHY} = 'genus:species-subspecies:project:strain:sample:technology:library:lane';
# is $vrtrack->hierarchy_path_of_lane($vrlane) ,'genus/species_subspecies/Project_test2/Individual_test/sample_a/seq_tech_test/lib_a/lane_a', 'hierarchy_path_of_lane works with DATA_HIERARCHY set to all items';
+# test hierarchy_path_of_object
+$ENV{DATA_HIERARCHY} = 'projectssid:project:individual:sample:technology:library:lane';
+is $vrtrack->hierarchy_path_of_object($vrproj), '1111/Project_htest', 'hierarchy_path_of_object works for project';
+is $vrtrack->hierarchy_path_of_object($sample), '1111/Project_htest/Individual_test/sample_a', 'hierarchy_path_of_object works for sample';
+is $vrtrack->hierarchy_path_of_object($library), '1111/Project_htest/Individual_test/sample_a/seq_tech_test/lib_a', 'hierarchy_path_of_object works for library';
+is $vrtrack->hierarchy_path_of_object($vrlane), '1111/Project_htest/Individual_test/sample_a/seq_tech_test/lib_a/lane_a', 'hierarchy_path_of_object works for lane';
+
+$ENV{DATA_HIERARCHY} = 'projectssid:project:genus:species-subspecies:individual:sample:technology:library:lane';
+is $vrtrack->hierarchy_path_of_object($vrlane), undef, 'hierarchy_path_of_object returns undef if hierarchy cannot be built (no species data)';
+my $species = $ind->add_species('Genus species subspecies');
+$ind->update();
+is $ind->species->name(), 'Genus species subspecies', 'added species to individual';
+is $vrtrack->hierarchy_path_of_object($vrlane), '1111/Project_htest/Genus/species_subspecies/Individual_test/sample_a/seq_tech_test/lib_a/lane_a', 'hierarchy_path_of_object works with species data';
+$ENV{DATA_HIERARCHY} = 'TRACKING:genus:species-subspecies:strain:individual:project:projectid:projectssid:sample:technology:library:lane';
+is $vrtrack->hierarchy_path_of_object($vrproj), undef, 'hierarchy_path_of_object returns undef if hierarchy cannot be built (impossible structure)';
+is $vrtrack->hierarchy_path_of_object($vrlane), 'TRACKING/Genus/species_subspecies/Individual_test/Individual_test/Project_htest/1/1111/sample_a/seq_tech_test/lib_a/lane_a', 'hierarchy_path_of_object finds all hierarchy terms';
+
+delete $ENV{DATA_HIERARCHY};
+is $vrtrack->hierarchy_path_of_object($vrlane), 'Project_htest/sample_a/seq_tech_test/lib_a/lane_a', 'hierarchy_path_of_object defaults to project:sample:technology:library:lane';
+$ENV{DATA_HIERARCHY} = 'project:genus:species-subspecies:sample:lane';
+is $vrtrack->hierarchy_path_of_object($vrlane, 'SUPPLIED_HIERARCHY:project:sample:lane'), 'SUPPLIED_HIERARCHY/Project_htest/sample_a/lane_a', 'hierarchy_path_of_object works for hierarchy supplied as parameter';
+
+throws_ok { $vrtrack->hierarchy_path_of_object($ind) } qr/A recognised object type must be supplied/, 'hierarchy_path_of_object throws for VRTrack::Individual';
+throws_ok { $vrtrack->hierarchy_path_of_object($species) } qr/A recognised object type must be supplied/, 'hierarchy_path_of_object throws for VRTrack::Species';
+throws_ok { $vrtrack->hierarchy_path_of_object('scalar') } qr/A recognised object type must be supplied/, 'hierarchy_path_of_object throws for unrecognised object';
+throws_ok { $vrtrack->hierarchy_path_of_object(undef) } qr/A recognised object type must be supplied/, 'hierarchy_path_of_object throws for undef object';
+
+
# test descendants using lane
$vrlane->update;
my @children = @{$vrlane->descendants};
View
30 t/VRTrack/non_core_classes.t
@@ -11,11 +11,12 @@ BEGIN {
plan skip_all => "Skipping all tests because VRTrack tests have not been configured";
}
else {
- plan tests => 51;
+ plan tests => 63;
}
use_ok('VRTrack::VRTrack');
use_ok('VRTrack::Image');
+ use_ok('VRTrack::AutoQC');
use_ok('VRTrack::Individual');
use_ok('VRTrack::Lane');
use_ok('VRTrack::Mapper');
@@ -51,6 +52,33 @@ ok $image->update, 'update worked on image';
$image = VRTrack::Image->new($vrtrack, $image_id);
is_deeply [$image->id, $image->name, $image->image], [$image_id, $image_name, $imagedata], 'after update, the things really were set';
+# AutoQC
+my $reason='The lane failed the NPG QC check, so auto-fail';
+ok my $autoqc = VRTrack::AutoQC->create($vrtrack, 'NPG QC status', 0, $reason), 'autoqc create worked';
+my $autoqc_id = $autoqc->id;
+$autoqc = VRTrack::AutoQC->new($vrtrack, $autoqc_id);
+is $autoqc->id, $autoqc_id, 'AutoQC new returned the autoqc we made before';
+is $autoqc->reason(),$reason, 'autoqc reason stored correctly';
+
+# test autoqc getters/setters
+my $qc_test = 'autoqc_qc_test_name_changed';
+is $autoqc->test($qc_test), $qc_test, 'autoqc test name could be get/set';
+my $qc_reason= 'modified test result reason';
+is $autoqc->reason($qc_reason), $qc_reason, 'autoqc reason name could be get/set';
+my $qc_result= 0;
+is $autoqc->result($qc_result), $qc_result, 'autoqc result could be updated';
+ok $autoqc->update, 'update worked on autoqc';
+
+# Add autoqcs to mapping stats
+my $mapstats = "VRTrack::Mapstats"->create($vrtrack);
+ok $autoqc = $mapstats->add_autoqc('NPG QC status',1,'The lane failed the NPG QC check'),'added autoqc to mapping stats';
+my @autoqc_statuses = @{ $mapstats->autoqcs() };
+is scalar @autoqc_statuses,1, 'got autoqc array ref back from db';
+
+# update autoqc test result
+ok $autoqc = $mapstats->add_autoqc('NPG QC status',0,'The lane passed the NPG QC check'),'re-added (updated) an autoqc test';
+is $autoqc->result(), 0, 'autoqc result was updated';
+
# individual
# setting species_id and population id for the first individual
my $ind_name = "test ind";

0 comments on commit 414ebf5

Please sign in to comment.