archiveStableId.t 3.81 KB
Newer Older
1 2
use strict;
use warnings;
3
no warnings qw(uninitialized);
4 5 6

BEGIN { $| = 1;  
	use Test;
7
	plan tests => 20;
8 9
}

10
use Bio::EnsEMBL::Test::MultiTestDB;
11
use Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor;
12
use Bio::EnsEMBL::Test::TestUtils;
13 14 15 16 17 18 19 20 21

our $verbose = 0;


#
# 1 ArchiveStableId adaptor compiles
#
ok(1);

22

23
my $multi = Bio::EnsEMBL::Test::MultiTestDB->new;
24 25 26 27 28
my $db    = $multi->get_DBAdaptor('core');

my $asia = $db->get_ArchiveStableIdAdaptor();


29 30 31 32 33 34 35 36 37 38 39 40
#
# 2-4 ArchiveStableId retrieval
#
my $asi = $asia->fetch_by_stable_id("T1");
ok( $asi->release == 2);

$asi = $asia->fetch_by_stable_id_version("T2", 3);
ok( $asi->release == 3);

$asi = $asia->fetch_by_stable_id_dbname("T1", "release_2");
ok( $asi->release == 2);

41 42

#
43
# 5 retrieval of an archiveStableId
44
#
45 46 47
$asi = $asia->fetch_by_stable_id( "G1" );
_print_asi( $asi );

48 49
ok( $asi );

50 51 52 53

#
# 6 how many predecessors does it have
#
54
my $pre_asis = $asi->get_all_predecessors();
55
ok( scalar( @$pre_asis ) == 2 );
56 57

for my $asi ( @$pre_asis ) {
58
  debug( "\tPre G1" );
59 60 61 62 63
  _print_asi( $asi );
}


#
64
# 7 transcripts for a gene
65 66 67 68
#
my $transcripts = $pre_asis->[0]->get_all_transcript_archive_ids();

for my $asi ( @$transcripts ) {
69
  debug( "\tTranscripts G1" );
70 71
  _print_asi( $asi );
  
72
  my $tl = $asi->get_all_translation_archive_ids();
73 74 75
  foreach my $asi2 (@$tl) {
    _print_asi( $asi2 );
  }
76 77 78 79 80
}

ok( scalar( @$transcripts ) == 1);


81 82 83
#
# 8 no predecessor case
#
84
$pre_asis = $pre_asis->[0]->get_all_predecessors();
85
debug( "\tPredecessors: ".scalar( @$pre_asis ) );
86

87 88
ok( scalar( @$pre_asis ) == 0 );

89 90

#
91
# 9 successor case
92 93 94 95 96
#
$asi = $asia->fetch_by_stable_id_dbname( "G4", "release_1" );
my $succ_asis = $asi->get_all_successors();
 
for my $asi ( @$succ_asis ) {
97
  debug( "\tSucc G4.1" );
98 99 100 101 102
  _print_asi( $asi );
}

ok( scalar( @$succ_asis ) == 1 );

103 104 105
#
# 10 no successor case
#
106 107 108
$succ_asis = $succ_asis->[0]->get_all_successors();

for my $asi ( @$succ_asis ) {
109
  debug( "\tSucc Succ G4.1" );
110 111 112 113 114
  _print_asi( $asi );
}

ok( scalar( @$succ_asis ) == 0 );

115

116
#
117
# 11 fetch_successor_history
118 119
#
$asi = $asia->fetch_by_stable_id_dbname( "G2", "release_1" );
120
my $asis = $asia->fetch_successor_history( $asi );
121

122
debug( "\tCurrently related from G2.release_1" );
123 124 125 126
for my $asi ( @$asis ) {
 _print_asi( $asi );
}

127 128
ok(( $asis->[-1]->db_name eq "release_4" ) &&
   ( scalar @$asis == 5 ));
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
#
# 12-16 history tree
#
$asi = $asia->fetch_by_stable_id_dbname( "G2", "release_1" );
my $history = $asi->get_history_tree;

my @asis = @{ $history->get_all_ArchiveStableIds };
ok( scalar(@asis) == 9);

my @events = @{ $history->get_all_StableIdEvents };
ok( scalar(@events) == 10);

ok( scalar(@{ $history->get_release_display_names }) == 4);
ok( scalar(@{ $history->get_unique_stable_ids }) == 3);

my ($x, $y) = @{ $history->coords_by_ArchiveStableId($asi) };
ok( $x == 0 and $y == 1 );


#
# 17-18 check for current version and fetch latest incarnation
#
ok( ! $asi->is_latest );

$asi = $asi->get_latest_incarnation;
155
ok( $asi->is_latest and $asi->version == 3 );
156

Arne Stabenau's avatar
Arne Stabenau committed
157
#
158
# 19 associated IDs in archive
Arne Stabenau's avatar
Arne Stabenau committed
159
#
160 161 162 163 164 165 166 167
$asi = $asia->fetch_by_stable_id_version( "G2", "2" );
my @assoc = @{ $asi->get_all_associated_archived };
ok( scalar(@assoc) == 2 and
    $assoc[0]->[0]->type eq 'Gene' and
    $assoc[0]->[1]->type eq 'Transcript' and
    $assoc[0]->[2]->type eq 'Translation' and
    $assoc[0]->[3] =~ /^PT/
);
Arne Stabenau's avatar
Arne Stabenau committed
168 169


170 171 172 173 174
#
# 20 archived peptide sequence
#
$asi = $asia->fetch_by_stable_id_version("P2", 1);
ok( $asi->get_peptide eq 'PTWOVERSIONONE*' );
Arne Stabenau's avatar
Arne Stabenau committed
175 176


177 178 179
#
# debug helper
#
180 181 182
sub _print_asi {
  my $asi = shift;

183 184 185 186 187 188 189
  debug( "\ttype: ".$asi->type().
         "\n\tstable id: ".$asi->stable_id().
	 "\n\tversion: ".$asi->version().
	 "\n\tdbname: ".$asi->db_name().
	 "\n\tTranscripts: ".(join(", ", map { $_->stable_id } @{ $asi->get_all_transcript_archive_ids })).
	 "\n\tTranslations: ".(join(", ", map { $_->stable_id } @{ $asi->get_all_translation_archive_ids })).
	 "\n\tPeptide: ".$asi->get_peptide."\n" );
190 191
}