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

Diff of /FigKernelPackages/SeedUtils.pm

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

revision 1.12, Tue Oct 20 21:08:43 2009 UTC revision 1.13, Thu Nov 5 17:24:19 2009 UTC
# Line 24  Line 24 
24      use strict;      use strict;
25      no warnings qw(once);      no warnings qw(once);
26      use base qw(Exporter);      use base qw(Exporter);
27      our @EXPORT = qw(hypo parse_fasta_record create_fasta_record rev_comp genome_of min max sims verify_dir);      our @EXPORT = qw(hypo boundaries_of parse_fasta_record create_fasta_record rev_comp genome_of min max sims verify_dir);
28    
29  =head1 SEED Utility Methods  =head1 SEED Utility Methods
30    
# Line 35  Line 35 
35    
36  =head2 Public Methods  =head2 Public Methods
37    
38    =head3 boundaries_of
39    
40        my ($contig, $min, $max) = boundaries_of($locs);
41    
42    Return the boundaries of a set of locations. The contig, the leftmost
43    location, and the rightmost location will be returned to the caller. If
44    more than one contig is represented, the method will return an undefined
45    value for the contig (indicating failure).
46    
47    =over 4
48    
49    =item locs
50    
51    Reference to a list of location strings. A location string contains a contig ID,
52    and underscore (C<_>), a starting offset, a strand identifier (C<+> or C<->), and
53    a length (e.g. C<360108.3:NC_10023P_1000+2000> begins at offset 1000 of contig
54    B<360108.3:NC_10023P> and covers 2000 base pairs on the C<+> strand).
55    
56    =item RETURN
57    
58    Returns a 3-element list. The first element is the contig ID from all the locations,
59    the second is the offset of leftmost base pair represented in the locations, and the
60    third is the offset of the rightmost base pair represented in the locations.
61    
62    =back
63    
64    =cut
65    
66    sub boundaries_of {
67        # Get the parameters.
68        my ($locs) = @_;
69        # Declare the return variables.
70        my ($contig, $min, $max);
71        # We'll put all the starting and ending offsets found in here.
72        my @offsets;
73        # This will count the number of errors found.
74        my $error = 0;
75        # Loop through the locations.
76        for my $loc (@$locs) {
77            # Parse this location.
78            if ($loc =~ /^(.+)_(\d+)(\+|\-)(\d+)$/) {
79                my ($newContig, $begin, $dir, $len) = ($1, $2, $3, $4);
80                # Is this contig valid?
81                if ($contig && $newContig ne $contig) {
82                    # No, skip this location.
83                    $error++;
84                } else {
85                    # Save the contig.
86                    $contig = $newContig;
87                    # Compute the ending offset.
88                    my $end = ($dir eq '+' ? $begin + $len - 1 : $begin - $len + 1);
89                    # Save both offsets.
90                    push @offsets, $begin, $end;
91                }
92            } else {
93                # The location is invalid, so it's an error,
94                $error++;
95            }
96        }
97        # If there's an error, clear the contig ID.
98        if ($error) {
99            $contig = undef;
100        }
101        # Compute the min and max from the offsets collected.
102        $min = min(@offsets);
103        $max = max(@offsets);
104        # Return the results.
105        return ($contig, $min, $max);
106    }
107    
108  =head3 max  =head3 max
109    
110      my $max = max(@nums);      my $max = max(@nums);

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3