2 # See the NOTICE file distributed with this work for additional information
3 # regarding copyright ownership.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
20 batch_id_history.pl - find stable IDs in the
archive
24 find_stable_ids_in_archive.pl [arguments]
28 --host=hOST database host HOST
29 --port=PORT database port PORT
30 --user=USER database username USER
31 --dbname=NAME database name NAME
32 --stable_id_file=FILE read stable ID list from FILE
36 --pass=PASS database passwort PASS
37 --outfile=FILE write output to FILE
38 --pep_seq print peptide sequence
43 This script reads a list of stable IDs from a file and sees
if it can find them
44 in the stable ID
archive. It will print the ID history
for each of them and
45 optinally the peptide sequence found there as well. Note that
this will not
46 print the full history network, but rather branch out from your focus stable ID
47 only. If you are interested in the full network, have a look at
53 Patrick Meidl <meidl@ebi.ac.uk>, Ensembl core API team
57 Please post comments/questions to the Ensembl development list
64 no warnings
'uninitialized';
73 my ($host, $port, $user, $pass, $dbname, $stable_id_file, $outfile, $pep_seq);
81 "stable_id_file=s", \$stable_id_file,
82 "outfile=s", \$outfile,
86 # check required params
87 unless ($host && $port && $user && $dbname && $stable_id_file) {
88 die
"ERROR: Unable to run script.\nNeed host, port, user, dbname and stable_id_file parameters.\n";
91 # connect to database and get adaptors
100 my $aa = $db->get_ArchiveStableIdAdaptor;
102 # read list of stable IDs from file
104 open($infh,
"<", $stable_id_file) or
105 die(
"Can't open $stable_id_file for reading: $!");
107 # get output filehandle
110 open($outfh,
">", $outfile) or die(
"Can't open $outfile for writing: $!");
115 while (my $sid = <$infh>) {
117 # skip comments and empty lines
118 next
if (/^#/ or /^\s?\n$/);
121 print $outfh
"\n$sid\n\n";
123 my $archive_id = $aa->fetch_by_stable_id($sid);
125 unless ($archive_id) {
126 print $outfh
" Not found in database.\n";
130 my $history = $archive_id->get_history_tree;
131 next unless $history;
133 if ($history->is_incomplete) {
134 print $outfh
" NOTE: History tree is incomplete.\n\n";
139 # get unique stable IDs (regardless of version)
140 my @unique_ids = @{ $history->get_unique_stable_ids };
143 foreach my $id (@unique_ids) {
144 $matrix->[$i++]->[0] = $id;
147 # get all releases for which we have nodes in this graph
148 my @releases = @{ $history->get_release_display_names };
151 foreach my $release (@releases) {
152 $matrix->[scalar(@unique_ids)]->[$j++] = $release;
155 # print a "graphical" representation of the tree
156 my $fmt =
" %-20s" . (
"%-6s" x scalar(@releases)) .
"\n";
158 foreach my $a_id (@{ $history->get_all_ArchiveStableIds }) {
159 my ($x, $y) = @{ $history->coords_by_ArchiveStableId($a_id) };
160 $matrix->[$y]->[$x+1] = $a_id->version;
163 for (my $i = 0; $i < @$matrix; $i++) {
164 print $outfh sprintf($fmt, @{ $matrix->[$i] });
167 # current versions in history
168 print $outfh
"\n Current stable IDs in this tree:\n";
169 my @current = @{ $history->get_all_current_ArchiveStableIds };
171 map { print $outfh
" ".$_->stable_id.
".".$_->version.
"\n" } @current;
173 print $outfh
" none\n";