11 use CXGN
::DB
::Connection
;
12 use CXGN
::DB
::DBICFactory
;
14 use CXGN
::Tools
::Text qw
/commify_number/;
15 use CXGN
::CDBI
::Class
::DBI
::TestSampler
;
16 use CXGN
::Genomic
::CloneIdentifiers qw
/parse_clone_ident/;
20 %config = ( packagename
=> 'CXGN::Genomic::Clone',
28 use_ok
('CXGN::Genomic::Clone');
30 my $chado = CXGN
::DB
::DBICFactory
->open_schema('Bio::Chado::Schema');
31 my $dbh = CXGN
::Genomic
::Clone
->db_Main;
32 foreach my $cid ( 2, 55724,119416 ) {
33 test_random_clone
( $dbh, $cid );
38 ############# SUBROUTINES #########
40 sub test_random_clone
{
44 #test that we can retrieve it
45 my $clone = CXGN
::Genomic
::Clone
->retrieve($id);
46 isa_ok
$clone, 'CXGN::Genomic::Clone';
48 #diag 'testing with clone id '.$clone->clone_id;
50 #check estimated length
51 my ($estlen) = $dbh->selectrow_array('select estimated_length from genomic.clone where clone_id=?',undef,$id);
52 ok
(!defined($estlen) && !defined($clone->estimated_length)
53 || $clone->estimated_length == $estlen
56 ok
($clone->clone_name_with_chromosome || 'does not die','clone_name_with_chromosome method does not die');
58 #check has_a relations
59 ok
( isa
($clone->library_id,'CXGN::Genomic::Library') );
60 ok
( isa
($clone->clone_type_id,'CXGN::Genomic::CloneType') );
61 #check has_many relations
62 my $bad_chromats = grep {! isa
($_,'CXGN::Genomic::Chromat')} $clone->chromat_objects;
63 ok
($bad_chromats == 0);
65 #cursory checks of sql
66 my @sql_args = ( $clone->library_object->shortname,
71 ok
($clone->clone_name_mysql(@sql_args) =~ /concat/i);
72 ok
($clone->clone_name_postgresql(@sql_args) =~ /\|\|/i);
73 ok
($clone->cornell_clone_name_mysql(@sql_args) =~ /concat/i);
74 ok
($clone->cornell_clone_name_postgresql(@sql_args) =~ /\|\|/i);
76 #clone name and cornell clone name
77 my $valid_name_pattern = qr/^[A-Z]{2}_\w+\d{4}[A-Z]\d{2}$/;
78 ok
($clone->clone_name =~ $valid_name_pattern);
79 ok
($clone->clone_name eq $clone->arizona_clone_name);
80 my $valid_cornell_name_pattern =
81 $clone->library_id->shortname eq 'LE_HBa' ?
qr/^P\d{3}[A-Z]\d{2}$/ :
83 ok
($clone->cornell_clone_name =~ $valid_cornell_name_pattern);
84 # warn "clone name was ".$clone->cornell_clone_name;
86 #check that we can retrieve from clone name
87 is
(CXGN
::Genomic
::Clone
->retrieve_from_clone_name($clone->clone_name),
89 'can retrieve self by clone name'
92 ok
($clone->library_id->library_id == $clone->library_object->library_id);
94 #test the chado_feature method
95 my $features = $clone->chado_feature_rs( $chado );
96 can_ok
( $features, 'next', 'first', 'all' );
97 my $feature = $features->single; #< actually execute the query also
99 #check that clone_type_object returns the right stuff
100 ok
(ref($clone->clone_type_object) eq ref($clone->clone_type_id));
101 ok
($clone->clone_type_object->clone_type_id == $clone->clone_type_id->clone_type_id);
103 #check that the sequencing status is a valid value
104 my $seqstatus = $clone->sequencing_status;
105 ok
(grep {$seqstatus eq $_} qw
/in_progress none complete/);
107 #check that the clone's sequence is valid
108 unlike
( $clone->seq || '', qr/[^ACTGXN]/i, 'clone has valid sequence or no sequence');
110 #check that the latest sequence name is kosher
111 my $chado_name = $clone->latest_sequence_name;
112 my $chado_name_parsable = parse_clone_ident
($chado_name,'versioned_bac_seq');
113 ok
( !defined($chado_name) || $chado_name_parsable, 'latest_sequence_name returns a valid value');
115 #check restriction fragment functions
117 #check that intl_clone_name returns something that looks right
118 is
( $clone->intl_clone_name, $clone->library_object->shortname.'-'.$clone->platenum.$clone->wellrow.$clone->wellcol,
119 'intl_clone_name looks OK');
121 my $acc = $clone->genbank_accession( $chado );
122 my @acc = $clone->genbank_accession( $chado );
124 ok
(@acc == 1,'genbank_accession returns 1-element list if has genbank accession');
125 like
($acc,qr/^[A-Z]{2}\d+\.\d+$/,'genbank accession looks correctly formed');
127 ok
(! defined $acc, 'genbank_accession returns undef in scalar context if no accession');
128 ok
(@acc == 0,'genbank_accession returns empty list in list context if no accession');
132 #check clone restriction fragments methods
133 my @seqs = $clone->seq;
135 my $f = $clone->in_silico_restriction_fragment_sizes('HindIII');
136 is
ref($f), 'ARRAY', 'in-silico restriction func returns arrayref';
137 ok
!grep ref,@
$f, 'and the arrayref is flat';
139 if( my @iv = $clone->in_vitro_restriction_fragment_sizes('HindIII') ) {
141 is
ref($iv), 'ARRAY', 'in-vitro restriction func returns arrayref';
142 ok
!(grep {ref} @
$iv), 'invitro arrayref is flat';
144 ok
@iv == 0, 'in_vitro properly returned empty list';
145 SKIP
: { skip
'no in-vitro restriction record',1 };
149 ok
!defined $clone->in_silico_restriction_fragment_sizes('HindIII'), 'no sequence, so no in silico restriction fragments';
150 SKIP
: {skip
'no finished sequence', 3}
153 ##############################################################################