source: trunk/PERL_SCRIPTS/SAI/SAI_demo.pl

Last change on this file was 17618, checked in by westram, 6 years ago
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6BEGIN {
7  if (not exists $ENV{'ARBHOME'}) { die "Environment variable \$ARBHOME has to be defined"; }
8  my $arbhome = $ENV{'ARBHOME'};
9  push @INC, "$arbhome/lib";
10  push @INC, "$arbhome/PERL_SCRIPTS/GENOME";
11  push @INC, "$arbhome/PERL_SCRIPTS/SAI";
12  1;
13}
14
15use ARB;
16use SAI;
17
18# -----------------------
19
20sub expectEntry($$) {
21  my ($gb_father,$key) = @_;
22  my $gb = ARB::search($gb_father, $key, 'NONE');
23  defined $gb || die "Expected entry '$key' in '".ARB::get_db_path($gb_father)."'";
24  return $gb;
25}
26
27# -----------------------
28
29SAI::connectDB();
30
31my @SAI = ();
32SAI::scanSAIs(@SAI);
33
34print "SAIs in current database:\n";
35foreach (@SAI) {
36  print "- $_\n";
37}
38
39my $sai_name = 'POS_VAR_BY_PARSIMONY';
40my $gb_posvar = SAI::findSAI($sai_name);
41if ($gb_posvar) {
42  print "Details for SAI '$sai_name':\n";
43
44  my @alis = ();
45  SAI::getSAIalignments($gb_posvar,@alis);
46
47  print "- Contains information for the following alignments:\n";
48  foreach my $ali (@alis) {
49    print "  - $ali\n";
50    my $gb_ali = expectEntry($gb_posvar, $ali);
51
52    my $gb_cat = expectEntry($gb_ali, '_CATEGORIES');
53    my $cat    = ARB::read_string($gb_cat);
54    print "    cat='$cat'\n";
55
56    my $gb_data = expectEntry($gb_ali, 'data');
57    my $data = ARB::read_string($gb_data);
58    # print "    data='$data'\n";
59    print "    data contains ".length($data)." characters.\n";
60
61    my $gb_freqs = expectEntry($gb_ali, 'FREQUENCIES');
62    my @freq_entries = ( 'NA', 'NC', 'NG', 'NU');
63    foreach my $fentry (@freq_entries) {
64      my $gb_f = expectEntry($gb_freqs, $fentry);
65      my @values = ();
66      SAI::readIntegerArray($gb_f,@values);
67      print "    $fentry contains ".scalar(@values)." integer values, ";
68      my $sum = 0;
69      foreach (@values) { $sum += $_; }
70      print "    $fentry sum is $sum\n";
71    }
72  }
73}
74else {
75  print "No such SAI '$sai_name'\n";
76}
77
78SAI::disconnectDB();
79
Note: See TracBrowser for help on using the repository browser.