~ubuntu-branches/ubuntu/saucy/bioperl/saucy-proposed

« back to all changes in this revision

Viewing changes to Bio/AlignIO/fasta.pm

  • Committer: Bazaar Package Importer
  • Author(s): Charles Plessy
  • Date: 2009-03-10 07:19:11 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090310071911-fukqzw54pyb1f0bd
Tags: 1.6.0-2
* Removed patch system (not used):
  - removed instuctions in debian/rules;
  - removed quilt from Build-Depends in debian/control.
* Re-enabled tests:
  - uncommented test command in debian/rules;
  - uncommented previously missing build-dependencies in debian/control.
  - Re-enabled tests and uncommented build-dependencies accordingly.
* Removed libmodule-build-perl and libtest-harness-perl from
  Build-Depends-Indep (provided by perl-modules).
* Better cleaning of empty directories using find -type d -empty -delete
  instead of rmdir in debian/rules (LP: #324001).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# $Id: fasta.pm,v 1.27.4.1 2006/10/02 23:10:12 sendu Exp $
 
1
# $Id: fasta.pm 11603 2007-07-31 15:32:43Z sendu $
2
2
#
3
3
# BioPerl module for Bio::AlignIO::fasta
4
4
#
47
47
# Let the code begin...
48
48
 
49
49
package Bio::AlignIO::fasta;
50
 
use vars qw($WIDTH);
51
50
use strict;
52
51
 
53
 
 
54
52
use base qw(Bio::AlignIO);
55
 
$WIDTH = 60;
 
53
our $WIDTH = 60;
56
54
 
57
55
=head2 next_aln
58
56
 
78
76
        my $aln = Bio::SimpleAlign->new();
79
77
 
80
78
        while (defined ($entry = $self->_readline) ) {
81
 
                chomp $entry;
82
 
                if ( $entry =~ s/^>\s*(\S+)\s*// ) {
83
 
                        $tempname  = $1;
84
 
                        chomp($entry);
85
 
                        $tempdesc = $entry;
86
 
                        if ( defined $name ) {
 
79
            chomp $entry;
 
80
            if ( $entry =~ s/^>\s*(\S+)\s*// ) {
 
81
                $tempname  = $1;
 
82
                chomp($entry);
 
83
                $tempdesc = $entry;
 
84
                if ( defined $name ) {
 
85
                    $seqchar =~ s/\s//g;
87
86
                                # put away last name and sequence
88
 
                                if ( $name =~ /(\S+)\/(\d+)-(\d+)/ ) {
89
 
                                        $seqname = $1;
90
 
                                        $start = $2;
91
 
                                        $end = $3;
92
 
                                } else {
93
 
                                        $seqname = $name;
94
 
                                        $start = 1;
95
 
                                        $end = $self->_get_len($seqchar);
96
 
                                }
97
 
                                $seq = new Bio::LocatableSeq(
 
87
                    if ( $name =~ /(\S+)\/(\d+)-(\d+)/ ) {
 
88
                        $seqname = $1;
 
89
                        $start = $2;
 
90
                        $end = $3;
 
91
                    } else {
 
92
                        $seqname = $name;
 
93
                        $start = 1;
 
94
                        $end = $self->_get_len($seqchar);
 
95
                    }
 
96
                    $seq = Bio::LocatableSeq->new(
98
97
                                                  -seq         => $seqchar,
99
 
                                             -display_id  => $seqname,
100
 
                                             -description => $desc,
101
 
                                             -start       => $start,
102
 
                                             -end         => $end,
103
 
                                             );
104
 
                                $aln->add_seq($seq);
105
 
                                $self->debug("Reading $seqname\n");
106
 
                        }
107
 
                        $desc = $tempdesc;      
108
 
                        $name = $tempname;
109
 
                        $desc = $entry;
110
 
                        $seqchar  = "";
111
 
                        next;
 
98
                                                  -display_id  => $seqname,
 
99
                                                  -description => $desc,
 
100
                                                  -start       => $start,
 
101
                                                  -end         => $end,
 
102
                                                  );
 
103
                    $aln->add_seq($seq);
 
104
                    $self->debug("Reading $seqname\n");
112
105
                }
113
 
                # removed redundant symbol validation
114
 
                # this is already done in Bio::PrimarySeq
115
 
                $seqchar .= $entry;
 
106
                $desc = $tempdesc;      
 
107
                $name = $tempname;
 
108
                $desc = $entry;
 
109
                $seqchar  = "";
 
110
                next;
 
111
            }
 
112
            # removed redundant symbol validation
 
113
            # this is already done in Bio::PrimarySeq
 
114
            $seqchar .= $entry;
116
115
        }
117
116
 
118
117
        #  Next two lines are to silence warnings that
119
118
        #  otherwise occur at EOF when using <$fh>
120
119
        $name = "" if (!defined $name);
121
120
        $seqchar="" if (!defined $seqchar);
 
121
        $seqchar =~ s/\s//g;
122
122
 
123
123
        #  Put away last name and sequence
124
124
        if ( $name =~ /(\S+)\/(\d+)-(\d+)/ ) {
137
137
                undef $aln; 
138
138
                return $aln;
139
139
        }
140
 
 
 
140
        
141
141
        # This logic now also reads empty lines at the 
142
142
        # end of the file. Skip this is seqchar and seqname is null
143
143
        unless ( length($seqchar) == 0 && length($seqname) == 0 ) {
144
 
                $seq = new Bio::LocatableSeq(-seq         => $seqchar,
145
 
                                                                                          -display_id  => $seqname,
146
 
                                                                                          -description => $desc,
147
 
                                                                                          -start       => $start,
148
 
                                                                                          -end         => $end,
149
 
                                                                                         );
150
 
                $aln->add_seq($seq);
151
 
                $self->debug("Reading $seqname\n");
 
144
            $seq = Bio::LocatableSeq->new(-seq         => $seqchar,
 
145
                                          -display_id  => $seqname,
 
146
                                          -description => $desc,
 
147
                                          -start       => $start,
 
148
                                          -end         => $end,
 
149
                                          );
 
150
            $aln->add_seq($seq);
 
151
            $self->debug("Reading $seqname\n");
152
152
        }
153
153
        my $alnlen = $aln->length;
154
154
        foreach my $seq ( $aln->each_seq ) {
155
 
                if ( $seq->length < $alnlen ) {
156
 
                        my ($diff) = ($alnlen - $seq->length);
157
 
                        $seq->seq( $seq->seq() . "-" x $diff);
158
 
                }
 
155
            if ( $seq->length < $alnlen ) {
 
156
                my ($diff) = ($alnlen - $seq->length);
 
157
                $seq->seq( $seq->seq() . "-" x $diff);
 
158
            }
159
159
        }
160
160
        return $aln;
161
161
}
189
189
            $name = $aln->displayname($rseq->get_nse());
190
190
            $seq  = $rseq->seq();
191
191
            $desc = $rseq->description || '';
192
 
            $self->_print (">$name $desc\n") or return ;        
 
192
                $desc = ' '.$desc if $desc;
 
193
            $self->_print (">$name$desc\n") or return;  
193
194
            $count = 0;
194
195
            $length = length($seq);
195
196
            if(defined $seq && $length > 0) {