[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.2, Tue Mar 22 17:19:46 2011 UTC revision 1.4, Tue Mar 22 23:17:33 2011 UTC
# Line 17  Line 17 
17    
18  package AlignsAndTrees;  package AlignsAndTrees;
19    
 use strict;  
 use gjoseqlib    qw( read_fasta );  
 use gjonewicklib qw( read_newick_tree );  
   
 my $data_dir = $ENV{ ATNG } && -d $ENV{ ATNG } ? $ENV{ ATNG } :  
                -d '/Home/fangfang/ATNG'        ? '/Home/fangfang/ATNG' :  
                                                  '.';  
   
 my $align_tree_data = "$data_dir/md5IDs_in_align_and_tree.tab";  
   
20  #===============================================================================  #===============================================================================
21  #  perl functions for loading and accessing Alignments and Trees based on md5  #  perl functions for loading and accessing Alignments and Trees based on md5
22  #  #
# Line 41  Line 31 
31  #    @md5IDs   = md5IDs_in_align( $alignID );  #    @md5IDs   = md5IDs_in_align( $alignID );
32  #   \@md5IDs   = md5IDs_in_align( $alignID );  #   \@md5IDs   = md5IDs_in_align( $alignID );
33  #  #
34  #    @seqs     = alignment_by_ID( $alignID );  #   \@seqs               = md5_alignment_by_ID( $alignID );
35  #   \@seqs     = alignment_by_ID( $alignID );  # ( \@seqs, \%metadata ) = md5_alignment_by_ID( $alignID );
36    #   \%metadata           = md5_alignment_metadata( $alignID );
37    #
38    #       $metadata{ $md5 } = [ $peg_length, $trim_beg, $trim_end, $location_string ]
39  #  #
40  #    @treeIDs  = all_treeIDs( );  #    @treeIDs  = all_treeIDs( );
41  #   \@treeIDs  = all_treeIDs( );  #   \@treeIDs  = all_treeIDs( );
42  #  #
43  #    @treeIDs  = aligns_with_md5ID( $md5 );  #    @treeIDs  = trees_with_md5ID( $md5 );
44  #   \@treeIDs  = aligns_with_md5ID( $md5 );  #   \@treeIDs  = trees_with_md5ID( $md5 );
45  #  #
46  #    @md5IDs   = md5IDs_in_tree( $treeID );  #    @md5IDs   = md5IDs_in_tree( $treeID );
47  #   \@md5IDs   = md5IDs_in_tree( $treeID );  #   \@md5IDs   = md5IDs_in_tree( $treeID );
48  #  #
49  #    $tree     = tree_by_ID( $treeID );  #    $tree     = md5_tree_by_ID( $treeID );
50  #  #
51  #===============================================================================  #===============================================================================
52    
53    use strict;
54    use gjoseqlib    qw( read_fasta );
55    use gjonewicklib qw( read_newick_tree );
56    
57    my $data_dir = $ENV{ ATNG } && -d $ENV{ ATNG } ? $ENV{ ATNG } :
58                   -d '/home/fangfang/ATNG'        ? '/home/fangfang/ATNG' :
59                                                     '.';
60    
61    my $align_tree_data = "$data_dir/md5IDs_in_align_and_tree.tab";
62    
63    #-------------------------------------------------------------------------------
64  #  #
65  #    @alignIDs = all_alignIDs();  #    @alignIDs = all_alignIDs();
66  #   \@alignIDs = all_alignIDs();  #   \@alignIDs = all_alignIDs();
# Line 107  Line 112 
112    
113  #-------------------------------------------------------------------------------  #-------------------------------------------------------------------------------
114  #  #
115  #    @seqs = alignment_by_ID( $alignID );  #   \@seqs               = md5_alignment_by_ID( $alignID );
116  #   \@seqs = alignment_by_ID( $alignID );  # ( \@seqs, \%metadata ) = md5_alignment_by_ID( $alignID );
117    #           \%metadata   = md5_alignment_metadata( $alignID );
118    #
119    #       $metadata{ $md5 } = [ $peg_length, $trim_beg, $trim_end, $location_string ]
120  #  #
121  #-------------------------------------------------------------------------------  #-------------------------------------------------------------------------------
122  sub alignment_by_ID  sub md5_alignment_by_ID
123  {  {
124      my ( $alignID ) = @_;      my ( $alignID ) = @_;
125      my $file = "$data_dir/ali$alignID.fa";      my $file = "$data_dir/ali$alignID.fa";
126      -f $file      -f $file
127          or print STDERR "Could not locate data for alignment '$alignID':\n$file\n\n"          or print STDERR "Could not locate data for alignment '$alignID':\n$file\n\n"
128              and return wantarray ? () : [];              and return wantarray ? () : undef;
129      gjoseqlib::read_fasta( $file );  
130        my @align = map { $_->[1] = ''; $_ } gjoseqlib::read_fasta( $file );
131    
132        wantarray ? ( \@align, md5_alignment_metadata( $alignID ) ) : \@align;
133  }  }
134    
135    sub md5_alignment_metadata
136    {
137        my ( $alignID ) = @_;
138        $alignID
139            or print STDERR "md5_alignment_metadata() called with invalid alignment ID '$alignID'\n"
140                and return {};
141        -f $align_tree_data
142            or die "md5IDs_in_align() could not locate alignment and tree data file '$align_tree_data'.\n";
143        my %metadata = map { chomp;
144                             my ( undef, $md5, @data ) = split /\t/;
145                             ( $md5 => \@data );
146                           }
147                      `grep -w '^$alignID' < '$align_tree_data'`;
148        \%metadata;
149    }
150    
151    
152  #-------------------------------------------------------------------------------  #-------------------------------------------------------------------------------
# Line 139  Line 165 
165    
166  #-------------------------------------------------------------------------------  #-------------------------------------------------------------------------------
167  #  #
168  #    @treeIDs = aligns_with_md5ID( $md5 );  #    @treeIDs = trees_with_md5ID( $md5 );
169  #   \@treeIDs = aligns_with_md5ID( $md5 );  #   \@treeIDs = trees_with_md5ID( $md5 );
170  #  #
171  #-------------------------------------------------------------------------------  #-------------------------------------------------------------------------------
172  sub trees_with_md5ID  sub trees_with_md5ID
173  {  {
174      my ( $md5 ) = @_;      my ( $md5 ) = @_;
175      $md5      return wantarray ? () : [] if ! $md5;
         or print STDERR "trees_with_md5ID() called without invalid md5 '$md5'\n"  
             and return wantarray ? () : [];  
176      -f $align_tree_data      -f $align_tree_data
177          or die "trees_with_md5ID() could not locate alignment and tree data file '$align_tree_data'.\n";          or die "trees_with_md5ID() could not locate alignment and tree data file '$align_tree_data'.\n";
178      my @ids = map { chomp; $_ } `grep -w '$md5' < '$align_tree_data' | cut -f1 | sort -u`;      my @ids = map { chomp; $_ } `grep -w '$md5' < '$align_tree_data' | cut -f1 | sort -u`;
# Line 175  Line 199 
199    
200  #-------------------------------------------------------------------------------  #-------------------------------------------------------------------------------
201  #  #
202  #    $tree = tree_by_ID( $treeID );  #    $tree = md5_tree_by_ID( $treeID );
203  #  #
204  #-------------------------------------------------------------------------------  #-------------------------------------------------------------------------------
205  sub tree_by_ID  sub md5_tree_by_ID
206  {  {
207      my ( $treeID ) = @_;      my ( $treeID ) = @_;
208      my $file = "$data_dir/ali$treeID.fa";      my $file = "$data_dir/tree$treeID.nwk";
209      -f $file      -f $file
210          or print STDERR "Could not locate data for alignment '$treeID':\n$file\n\n"          or print STDERR "Could not locate data for alignment '$treeID':\n$file\n\n"
211              and return wantarray ? () : [];              and return wantarray ? () : [];
212      gjonewicklib::read_newick_tree( $file );      gjonewicklib::read_newick_tree( $file );
213  }  }
214    
215    1;

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3