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

5
use Test::More;
6

7
use Bio::EnsEMBL::Test::MultiTestDB;
8
use Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor;
9
use Bio::EnsEMBL::Test::TestUtils;
10 11 12 13 14 15 16 17 18

our $verbose = 0;


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

19

20
my $multi = Bio::EnsEMBL::Test::MultiTestDB->new;
21 22 23 24 25
my $db    = $multi->get_DBAdaptor('core');

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


26 27 28 29
#
# 2-4 ArchiveStableId retrieval
#
my $asi = $asia->fetch_by_stable_id("T1");
30
is( $asi->release, 2, "T1 is from release 2");
31 32

$asi = $asia->fetch_by_stable_id_version("T2", 3);
33
is( $asi->release, 3, "T2 is from release 3");
34 35

$asi = $asia->fetch_by_stable_id_dbname("T1", "release_2");
36
is( $asi->release, 2, "T1 is from release 2");
37

38 39

#
40
# 5 retrieval of an archiveStableId
41
#
42 43 44
$asi = $asia->fetch_by_stable_id( "G1" );
_print_asi( $asi );

45 46
ok( $asi );

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
# 6 retrieval of the event related to a specific stable id
#
my $event = $asi->get_event("G2");

is(ref($event), 'Bio::EnsEMBL::StableIdEvent', "A stable id event was fetched");
is($event->score, 0.54, "Mapping score between G1 and G2");

my $old_archive_stable_id = $event->old_ArchiveStableId;
my $new_archive_stable_id = $event->new_ArchiveStableId;

is($new_archive_stable_id, $asi, "Initial archive is new archive");
is($old_archive_stable_id->stable_id, "G2", "Old stable id");
is($new_archive_stable_id->stable_id, "G1", "New stable id");

$event = $old_archive_stable_id->get_event("G1");

is($event->score, 0.54, "Mapping score between G1 and G2");

$old_archive_stable_id = $event->old_ArchiveStableId;
$new_archive_stable_id = $event->new_ArchiveStableId;

is($old_archive_stable_id->stable_id, "G2", "Old stable id");
is($new_archive_stable_id->stable_id, "G1", "New stable id");


#
# 7 how many predecessors does it have
76
#
77
my $pre_asis = $asi->get_all_predecessors();
78
is( scalar( @$pre_asis ), 2, "G1 has 2 predecessors" );
79 80

for my $asi ( @$pre_asis ) {
81
  debug( "\tPre G1" );
82 83 84 85 86
  _print_asi( $asi );
}


#
87
# 8 transcripts for a gene
88 89 90 91
#
my $transcripts = $pre_asis->[0]->get_all_transcript_archive_ids();

for my $asi ( @$transcripts ) {
92
  debug( "\tTranscripts G1" );
93 94
  _print_asi( $asi );
  
95
  my $tl = $asi->get_all_translation_archive_ids();
96 97 98
  foreach my $asi2 (@$tl) {
    _print_asi( $asi2 );
  }
99 100
}

101
is( scalar( @$transcripts ), 1, "G1 has 1 transcript");
102 103


104
#
105
# 9 no predecessor case
106
#
107
$pre_asis = $pre_asis->[0]->get_all_predecessors();
108
debug( "\tPredecessors: ".scalar( @$pre_asis ) );
109

110
is( scalar( @$pre_asis ), 0, "No predecessors found" );
111

112 113

#
114
# 10 successor case
115 116 117 118 119
#
$asi = $asia->fetch_by_stable_id_dbname( "G4", "release_1" );
my $succ_asis = $asi->get_all_successors();
 
for my $asi ( @$succ_asis ) {
120
  debug( "\tSucc G4.1" );
121 122 123
  _print_asi( $asi );
}

124
is( scalar( @$succ_asis ), 1, "G4 has 1 sucessor" );
125

126
#
127
# 11 no successor case
128
#
129 130 131
$succ_asis = $succ_asis->[0]->get_all_successors();

for my $asi ( @$succ_asis ) {
132
  debug( "\tSucc Succ G4.1" );
133 134 135
  _print_asi( $asi );
}

136
is( scalar( @$succ_asis ), 0, "G4.1 has no sucessors");
137

138

139
#
140
# 12 fetch_successor_history
141 142
#
$asi = $asia->fetch_by_stable_id_dbname( "G2", "release_1" );
143
my $asis = $asia->fetch_successor_history( $asi );
144

145
debug( "\tCurrently related from G2.release_1" );
146 147 148 149
for my $asi ( @$asis ) {
 _print_asi( $asi );
}

150 151
is( $asis->[-1]->db_name, "release_4", "Current release for G2 is release 4");
is( scalar @$asis, 5, "G2 has 5 sucessors");
152

153
#
154
# 13-17 history tree
155 156 157 158 159
#
$asi = $asia->fetch_by_stable_id_dbname( "G2", "release_1" );
my $history = $asi->get_history_tree;

my @asis = @{ $history->get_all_ArchiveStableIds };
160
is( scalar(@asis), 9, "G2 history has 9 related archives");
161 162

my @events = @{ $history->get_all_StableIdEvents };
163
is( scalar(@events), 10, "G2 history has 10 related events");
164

165 166
is( scalar(@{ $history->get_release_display_names }), 4, "G2 has 4 display names");
is( scalar(@{ $history->get_unique_stable_ids }), 3, "G2 has 3 unique stable ids");
167 168 169 170 171 172

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


#
173
# 18-19 check for current version and fetch latest incarnation
174
#
Andy Yates's avatar
Andy Yates committed
175
ok( ! $asi->is_latest, 'Not on the latest version so is_latest is false');
176 177

$asi = $asi->get_latest_incarnation;
Andy Yates's avatar
Andy Yates committed
178
ok($asi->is_latest(), 'Latest incarnation must be the latest version');
179
is($asi->version, 4, 'Latest version is 4');
180

Arne Stabenau's avatar
Arne Stabenau committed
181
#
182
# 20 associated IDs in archive
Arne Stabenau's avatar
Arne Stabenau committed
183
#
184 185 186 187 188 189 190 191
$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
192 193


194
#
195
# 21 archived peptide sequence
196 197 198
#
$asi = $asia->fetch_by_stable_id_version("P2", 1);
ok( $asi->get_peptide eq 'PTWOVERSIONONE*' );
Arne Stabenau's avatar
Arne Stabenau committed
199 200


201 202 203
#
# debug helper
#
204 205 206
sub _print_asi {
  my $asi = shift;

207 208 209 210 211 212 213
  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" );
214
}
215 216
 
done_testing();