1 | # =============================================================== # |
---|
2 | # # |
---|
3 | # File : SAI.pm # |
---|
4 | # Purpose : Basic SAI access # |
---|
5 | # # |
---|
6 | # Coded by Ralf Westram (coder@reallysoft.de) in June 2006 # |
---|
7 | # Institute of Microbiology (Technical University Munich) # |
---|
8 | # http://www.arb-home.de/ # |
---|
9 | # # |
---|
10 | # =============================================================== # |
---|
11 | |
---|
12 | package SAI; |
---|
13 | |
---|
14 | use strict; |
---|
15 | use warnings; |
---|
16 | |
---|
17 | use ARB; |
---|
18 | |
---|
19 | my $gb_main; |
---|
20 | |
---|
21 | sub connectDB() { |
---|
22 | print "Connecting to running ARB database\n"; |
---|
23 | $gb_main = ARB::open(":","r"); |
---|
24 | if (! $gb_main ) { |
---|
25 | my $error = ARB::await_error(); |
---|
26 | print $error."\n"; |
---|
27 | exit 0; |
---|
28 | } |
---|
29 | ARB::begin_transaction($gb_main); |
---|
30 | } |
---|
31 | |
---|
32 | sub disconnectDB() { |
---|
33 | ARB::commit_transaction($gb_main); |
---|
34 | ARB::close($gb_main); |
---|
35 | } |
---|
36 | |
---|
37 | sub scanSAIs(\@){ |
---|
38 | my ($array_r) = @_; |
---|
39 | |
---|
40 | for (my $gb_sai = BIO::first_SAI($gb_main); $gb_sai; $gb_sai = BIO::next_SAI($gb_sai)) { |
---|
41 | my $gb_name = ARB::search($gb_sai, 'name', 'NONE'); |
---|
42 | if ($gb_name) { |
---|
43 | my $name = ARB::read_string($gb_name); |
---|
44 | push @$array_r, $name; |
---|
45 | } |
---|
46 | else { |
---|
47 | die "No name found for SAI"; |
---|
48 | } |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | sub findSAI($) { |
---|
53 | my ($name) = @_; |
---|
54 | return BIO::find_SAI($gb_main, $name); |
---|
55 | } |
---|
56 | |
---|
57 | sub getSAIalignments($\@) { |
---|
58 | my ($gb_sai,$array_r) = @_; |
---|
59 | |
---|
60 | for (my $gb=ARB::child($gb_sai); $gb; $gb = ARB::nextChild($gb)) { |
---|
61 | my $key = ARB::read_key($gb); |
---|
62 | if ($key =~ /^ali_/o) { |
---|
63 | push @$array_r, $key; |
---|
64 | } |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | sub readIntegerArray($\@) { |
---|
69 | my ($gb_ints, $array_r) = @_; |
---|
70 | my $count = ARB::read_ints_count($gb_ints); |
---|
71 | if ($count>0) { |
---|
72 | for (my $i=0; $i<$count; $i++) { |
---|
73 | push @$array_r, ARB::read_from_ints($gb_ints, $i); |
---|
74 | } |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | 1; # module initialization ok |
---|
79 | |
---|
80 | |
---|