[Bio] / FigKernelPackages / AlignsAndTrees.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/AlignsAndTrees.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Tue Mar 22 15:31:01 2011 UTC revision 1.2, Tue Mar 22 17:19:46 2011 UTC
# Line 17  Line 17 
17    
18  package AlignsAndTrees;  package AlignsAndTrees;
19    
20    use strict;
21    use gjoseqlib    qw( read_fasta );
22    use gjonewicklib qw( read_newick_tree );
23    
24    my $data_dir = $ENV{ ATNG } && -d $ENV{ ATNG } ? $ENV{ ATNG } :
25                   -d '/Home/fangfang/ATNG'        ? '/Home/fangfang/ATNG' :
26                                                     '.';
27    
28    my $align_tree_data = "$data_dir/md5IDs_in_align_and_tree.tab";
29    
30  #===============================================================================  #===============================================================================
31  #  perl functions for loading and accessing Alignments and Trees.  #  perl functions for loading and accessing Alignments and Trees based on md5
32  #  #
33  #  Usage:  use AlignsAndTrees;  #  Usage:  use AlignsAndTrees;
34  #  #
35    #    @alignIDs = all_alignIDs();
36    #   \@alignIDs = all_alignIDs();
37    #
38    #    @alignIDs = aligns_with_md5ID( $md5 );
39    #   \@alignIDs = aligns_with_md5ID( $md5 );
40    #
41    #    @md5IDs   = md5IDs_in_align( $alignID );
42    #   \@md5IDs   = md5IDs_in_align( $alignID );
43    #
44    #    @seqs     = alignment_by_ID( $alignID );
45    #   \@seqs     = alignment_by_ID( $alignID );
46    #
47    #    @treeIDs  = all_treeIDs( );
48    #   \@treeIDs  = all_treeIDs( );
49    #
50    #    @treeIDs  = aligns_with_md5ID( $md5 );
51    #   \@treeIDs  = aligns_with_md5ID( $md5 );
52    #
53    #    @md5IDs   = md5IDs_in_tree( $treeID );
54    #   \@md5IDs   = md5IDs_in_tree( $treeID );
55    #
56    #    $tree     = tree_by_ID( $treeID );
57    #
58  #===============================================================================  #===============================================================================
59    #
60    #    @alignIDs = all_alignIDs();
61    #   \@alignIDs = all_alignIDs();
62    #
63    #-------------------------------------------------------------------------------
64  sub all_alignIDs  sub all_alignIDs
65  {  {
66        -f $align_tree_data
67            or die "all_alignIDs() could not locate alignment and tree data file '$align_tree_data'.\n";
68        my @ids = map { chomp; $_ } `cut -f1 < '$align_tree_data' | sort -u`;
69        wantarray ? @ids : \@ids;
70  }  }
71    
72    #-------------------------------------------------------------------------------
73    #
74    #    @alignIDs = aligns_with_md5ID( $md5 );
75    #   \@alignIDs = aligns_with_md5ID( $md5 );
76    #
77    #-------------------------------------------------------------------------------
78  sub aligns_with_md5ID  sub aligns_with_md5ID
79  {  {
80        my ( $md5 ) = @_;
81        $md5
82            or print STDERR "aligns_with_md5ID() called with invalid md5 '$md5'\n"
83                and return wantarray ? () : [];
84        -f $align_tree_data
85            or die "aligns_with_md5ID() could not locate alignment and tree data file '$align_tree_data'.\n";
86        my @ids = map { chomp; $_ } `grep -w '$md5' < '$align_tree_data' | cut -f1 | sort -u`;
87        wantarray ? @ids : \@ids;
88  }  }
89    
90    #-------------------------------------------------------------------------------
91    #
92    #    @md5IDs = md5IDs_in_align( $alignID );
93    #   \@md5IDs = md5IDs_in_align( $alignID );
94    #
95    #-------------------------------------------------------------------------------
96  sub md5IDs_in_align  sub md5IDs_in_align
97  {  {
98        my ( $alignID ) = @_;
99        $alignID
100            or print STDERR "md5IDs_in_align() called with invalid alignment ID '$alignID'\n"
101                and return wantarray ? () : [];
102        -f $align_tree_data
103            or die "md5IDs_in_align() could not locate alignment and tree data file '$align_tree_data'.\n";
104        my @md5IDs = map { chomp; $_ } `grep -w '^$alignID' < '$align_tree_data' | cut -f2 | sort -u`;
105        wantarray ? @md5IDs : \@md5IDs;
106  }  }
107    
108    #-------------------------------------------------------------------------------
109    #
110    #    @seqs = alignment_by_ID( $alignID );
111    #   \@seqs = alignment_by_ID( $alignID );
112    #
113    #-------------------------------------------------------------------------------
114  sub alignment_by_ID  sub alignment_by_ID
115  {  {
116        my ( $alignID ) = @_;
117        my $file = "$data_dir/ali$alignID.fa";
118        -f $file
119            or print STDERR "Could not locate data for alignment '$alignID':\n$file\n\n"
120                and return wantarray ? () : [];
121        gjoseqlib::read_fasta( $file );
122  }  }
123    
124    
125    
126    #-------------------------------------------------------------------------------
127    #
128    #    @treeIDs = all_treeIDs( );
129    #   \@treeIDs = all_treeIDs( );
130    #
131    #-------------------------------------------------------------------------------
132  sub all_treeIDs  sub all_treeIDs
133  {  {
134        -f $align_tree_data
135            or die "all_treeIDs() could not locate alignment and tree data file '$align_tree_data'.\n";
136        my @ids = map { chomp; $_ } `cut -f1 < '$align_tree_data' | sort -u`;
137        wantarray ? @ids : \@ids;
138  }  }
139    
140    #-------------------------------------------------------------------------------
141    #
142    #    @treeIDs = aligns_with_md5ID( $md5 );
143    #   \@treeIDs = aligns_with_md5ID( $md5 );
144    #
145    #-------------------------------------------------------------------------------
146  sub trees_with_md5ID  sub trees_with_md5ID
147  {  {
148        my ( $md5 ) = @_;
149        $md5
150            or print STDERR "trees_with_md5ID() called without invalid md5 '$md5'\n"
151                and return wantarray ? () : [];
152        -f $align_tree_data
153            or die "trees_with_md5ID() could not locate alignment and tree data file '$align_tree_data'.\n";
154        my @ids = map { chomp; $_ } `grep -w '$md5' < '$align_tree_data' | cut -f1 | sort -u`;
155        wantarray ? @ids : \@ids;
156  }  }
157    
158  sub md5ID_in_tree  #-------------------------------------------------------------------------------
159    #
160    #    @md5IDs = md5IDs_in_tree( $treeID );
161    #   \@md5IDs = md5IDs_in_tree( $treeID );
162    #
163    #-------------------------------------------------------------------------------
164    sub md5IDs_in_tree
165  {  {
166        my ( $treeID ) = @_;
167        $treeID
168            or print STDERR "md5IDs_in_tree() called with invalid tree ID '$treeID'\n"
169                and return wantarray ? () : [];
170        -f $align_tree_data
171            or die "md5IDs_in_tree() could not locate alignment and tree data file '$align_tree_data'.\n";
172        my @md5IDs = map { chomp; $_ } `grep -w '^$treeID' < '$align_tree_data' | cut -f2 | sort -u`;
173        wantarray ? @md5IDs : \@md5IDs;
174  }  }
175    
176    #-------------------------------------------------------------------------------
177    #
178    #    $tree = tree_by_ID( $treeID );
179    #
180    #-------------------------------------------------------------------------------
181  sub tree_by_ID  sub tree_by_ID
182  {  {
183        my ( $treeID ) = @_;
184        my $file = "$data_dir/ali$treeID.fa";
185        -f $file
186            or print STDERR "Could not locate data for alignment '$treeID':\n$file\n\n"
187                and return wantarray ? () : [];
188        gjonewicklib::read_newick_tree( $file );
189  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3