Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

maint: remove hard tabs and trailing whitespace

  • Loading branch information...
commit 0e0ddd3b24a2e62c837bad955b2e15484df8496f 1 parent 2cd1789
Carnë Draug authored March 28, 2013
230  Bio/AlignIO/fasta.pm
@@ -12,7 +12,7 @@ Bio::AlignIO::fasta - fasta MSA Sequence input/output stream
12 12
 
13 13
 =head1 SYNOPSIS
14 14
 
15  
-Do not use this module directly.  Use it via the L<Bio::AlignIO> 
  15
+Do not use this module directly.  Use it via the L<Bio::AlignIO>
16 16
 class.
17 17
 
18 18
 =head1 DESCRIPTION
@@ -24,15 +24,15 @@ FastA (FastX, FastN, FastP, tFastA, etc) use the Bio::SearchIO module.
24 24
 
25 25
 =head1 FEEDBACK
26 26
 
27  
-=head2 Support 
  27
+=head2 Support
28 28
 
29 29
 Please direct usage questions or support issues to the mailing list:
30 30
 
31 31
 I<bioperl-l@bioperl.org>
32 32
 
33  
-rather than to the module maintainer directly. Many experienced and 
34  
-reponsive experts will be able look at the problem and quickly 
35  
-address it. Please include a thorough description of the problem 
  33
+rather than to the module maintainer directly. Many experienced and
  34
+reponsive experts will be able look at the problem and quickly
  35
+address it. Please include a thorough description of the problem
36 36
 with code and data examples if at all possible.
37 37
 
38 38
 =head2 Reporting Bugs
@@ -69,7 +69,7 @@ use Bio::LocatableSeq;
69 69
  Usage   : $aln = $stream->next_aln
70 70
  Function: returns the next alignment in the stream.
71 71
  Returns : Bio::Align::AlignI object - returns 0 on end of file
72  
-	        or on error
  72
+            or on error
73 73
  Args    : -width => optional argument to specify the width sequence
74 74
            will be written (60 chars by default)
75 75
 
@@ -78,89 +78,89 @@ See L<Bio::Align::AlignI>
78 78
 =cut
79 79
 
80 80
 sub next_aln {
81  
-	my $self = shift;
82  
-	my ($width) = $self->_rearrange([qw(WIDTH)],@_);
83  
-	$self->width($width || $WIDTH);
84  
-
85  
-	my ($start, $end, $name, $seqname, $seq, $seqchar, $entry, 
86  
-		 $tempname, $tempdesc, %align, $desc, $maxlen);
87  
-	my $aln = Bio::SimpleAlign->new();
88  
-
89  
-	while (defined ($entry = $self->_readline) ) {
90  
-	    chomp $entry;
91  
-	    if ( $entry =~ s/^>\s*(\S+)\s*// ) {
92  
-		$tempname  = $1;
93  
-		chomp($entry);
94  
-		$tempdesc = $entry;
95  
-		if ( defined $name ) {
96  
-		    $seqchar =~ s/\s//g;
97  
-			$seqname = $name;
98  
-			$start = 1;
99  
-			$end = $self->_get_len($seqchar);
100  
-		    $seq = Bio::LocatableSeq->new
101  
-			( 
102  
-			  -seq         => $seqchar,
103  
-			  -display_id  => $seqname,
104  
-			  -description => $desc,
105  
-			  -start       => $start,
106  
-			  -end         => $end,
107  
-			  -alphabet    => $self->alphabet,
108  
-			  );
109  
-		    $aln->add_seq($seq);
110  
-		    $self->debug("Reading $seqname\n");
111  
-		}
112  
-		$desc = $tempdesc;	
113  
-		$name = $tempname;
114  
-		$desc = $entry;
115  
-		$seqchar  = "";
116  
-		next;
117  
-	    }
118  
-	    # removed redundant symbol validation
119  
-	    # this is already done in Bio::PrimarySeq
120  
-	    $seqchar .= $entry;
121  
-	}
122  
-
123  
-	#  Next two lines are to silence warnings that
124  
-	#  otherwise occur at EOF when using <$fh>
125  
-	$name = "" if (!defined $name);
126  
-	$seqchar="" if (!defined $seqchar);
127  
-        $seqchar =~ s/\s//g;
128  
-
129  
-	#  Put away last name and sequence
130  
-	if ( $name =~ /(\S+)\/(\d+)-(\d+)/ ) {
131  
-		$seqname = $1;
132  
-		$start = $2;
133  
-		$end = $3;
134  
-	} else {
135  
-		$seqname = $name;
136  
-		$start = 1;
137  
-		$end = $self->_get_len($seqchar);
138  
-	}
139  
-	
140  
-	# This logic now also reads empty lines at the 
141  
-	# end of the file. Skip this is seqchar and seqname is null
142  
-	unless ( length($seqchar) == 0 && length($seqname) == 0 ) {
143  
-	    $seq = Bio::LocatableSeq->new
144  
-		(-seq         => $seqchar,
145  
-		 -display_id  => $seqname,
146  
-		 -description => $desc,
147  
-		 -start       => $start,
148  
-		 -end         => $end,
149  
-		 -alphabet    => $self->alphabet,
150  
-		 );
151  
-	    $aln->add_seq($seq);
152  
-	    $self->debug("Reading $seqname\n");
153  
-	}
154  
-	my $alnlen = $aln->length;
155  
-	foreach my $seq ( $aln->each_seq ) {
156  
-	    if ( $seq->length < $alnlen ) {
157  
-		my ($diff) = ($alnlen - $seq->length);
158  
-		$seq->seq( $seq->seq() . "-" x $diff);
159  
-	    }
160  
-	}
  81
+    my $self = shift;
  82
+    my ($width) = $self->_rearrange([qw(WIDTH)],@_);
  83
+    $self->width($width || $WIDTH);
  84
+
  85
+    my ($start, $end, $name, $seqname, $seq, $seqchar, $entry,
  86
+         $tempname, $tempdesc, %align, $desc, $maxlen);
  87
+    my $aln = Bio::SimpleAlign->new();
  88
+
  89
+    while (defined ($entry = $self->_readline) ) {
  90
+        chomp $entry;
  91
+        if ( $entry =~ s/^>\s*(\S+)\s*// ) {
  92
+        $tempname  = $1;
  93
+        chomp($entry);
  94
+        $tempdesc = $entry;
  95
+            if ( defined $name ) {
  96
+                $seqchar =~ s/\s//g;
  97
+                $seqname = $name;
  98
+                $start = 1;
  99
+                $end = $self->_get_len($seqchar);
  100
+                $seq = Bio::LocatableSeq->new
  101
+                (
  102
+                  -seq         => $seqchar,
  103
+                  -display_id  => $seqname,
  104
+                  -description => $desc,
  105
+                  -start       => $start,
  106
+                  -end         => $end,
  107
+                  -alphabet    => $self->alphabet,
  108
+                  );
  109
+                $aln->add_seq($seq);
  110
+                $self->debug("Reading $seqname\n");
  111
+            }
  112
+        $desc = $tempdesc;
  113
+        $name = $tempname;
  114
+        $desc = $entry;
  115
+        $seqchar = "";
  116
+        next;
  117
+        }
  118
+        # removed redundant symbol validation
  119
+        # this is already done in Bio::PrimarySeq
  120
+        $seqchar .= $entry;
  121
+    }
  122
+
  123
+    #  Next two lines are to silence warnings that
  124
+    #  otherwise occur at EOF when using <$fh>
  125
+    $name = "" if (!defined $name);
  126
+    $seqchar="" if (!defined $seqchar);
  127
+    $seqchar =~ s/\s//g;
  128
+
  129
+    #  Put away last name and sequence
  130
+    if ( $name =~ /(\S+)\/(\d+)-(\d+)/ ) {
  131
+        $seqname = $1;
  132
+        $start = $2;
  133
+        $end = $3;
  134
+    } else {
  135
+        $seqname = $name;
  136
+        $start = 1;
  137
+        $end = $self->_get_len($seqchar);
  138
+    }
  139
+
  140
+    # This logic now also reads empty lines at the
  141
+    # end of the file. Skip this is seqchar and seqname is null
  142
+    unless ( length($seqchar) == 0 && length($seqname) == 0 ) {
  143
+        $seq = Bio::LocatableSeq->new
  144
+        (-seq         => $seqchar,
  145
+         -display_id  => $seqname,
  146
+         -description => $desc,
  147
+         -start       => $start,
  148
+         -end         => $end,
  149
+         -alphabet    => $self->alphabet,
  150
+         );
  151
+        $aln->add_seq($seq);
  152
+        $self->debug("Reading $seqname\n");
  153
+    }
  154
+    my $alnlen = $aln->length;
  155
+    foreach my $seq ( $aln->each_seq ) {
  156
+        if ( $seq->length < $alnlen ) {
  157
+            my ($diff) = ($alnlen - $seq->length);
  158
+            $seq->seq( $seq->seq() . "-" x $diff);
  159
+        }
  160
+    }
161 161
 
162 162
     # no sequences means empty alignment (possible EOF)
163  
-	return $aln if $aln->num_sequences;
  163
+    return $aln if $aln->num_sequences;
164 164
 }
165 165
 
166 166
 =head2 write_aln
@@ -181,28 +181,28 @@ sub write_aln {
181 181
     my ($seq,$desc,$rseq,$name,$count,$length,$seqsub);
182 182
 
183 183
     foreach my $aln (@aln) {
184  
-	if( ! $aln || ! $aln->isa('Bio::Align::AlignI')  ) { 
185  
-	    $self->warn("Must provide a Bio::Align::AlignI object when calling write_aln");
186  
-	    next;
187  
-	}
188  
-	if( $self->force_displayname_flat ) {
189  
-	    $aln->set_displayname_flat(1);
190  
-	}
191  
-	foreach $rseq ( $aln->each_seq() ) {
192  
-	    $name = $aln->displayname($rseq->get_nse());
193  
-	    $seq  = $rseq->seq();
194  
-	    $desc = $rseq->description || '';
195  
-		$desc = ' '.$desc if $desc;
196  
-	    $self->_print (">$name$desc\n") or return;	
197  
-	    $count = 0;
198  
-	    $length = length($seq);
199  
-	    if(defined $seq && $length > 0) {
200  
-		$seq =~ s/(.{1,$width})/$1\n/g;
201  
-	    } else {
202  
-		$seq = "\n";
203  
-	    }
204  
-	    $self->_print($seq);
205  
-	}
  184
+        if( ! $aln || ! $aln->isa('Bio::Align::AlignI')  ) {
  185
+            $self->warn("Must provide a Bio::Align::AlignI object when calling write_aln");
  186
+            next;
  187
+        }
  188
+        if( $self->force_displayname_flat ) {
  189
+            $aln->set_displayname_flat(1);
  190
+        }
  191
+        foreach $rseq ( $aln->each_seq() ) {
  192
+            $name = $aln->displayname($rseq->get_nse());
  193
+            $seq  = $rseq->seq();
  194
+            $desc = $rseq->description || '';
  195
+            $desc = ' '.$desc if $desc;
  196
+            $self->_print (">$name$desc\n") or return;
  197
+            $count = 0;
  198
+            $length = length($seq);
  199
+            if(defined $seq && $length > 0) {
  200
+                $seq =~ s/(.{1,$width})/$1\n/g;
  201
+            } else {
  202
+                $seq = "\n";
  203
+            }
  204
+            $self->_print($seq);
  205
+        }
206 206
     }
207 207
     $self->flush if $self->_flush_on_write && defined $self->_fh;
208 208
     return 1;
@@ -211,7 +211,7 @@ sub write_aln {
211 211
 =head2 _get_len
212 212
 
213 213
  Title   : _get_len
214  
- Usage   : 
  214
+ Usage   :
215 215
  Function: determine number of alphabetic chars
216 216
  Returns : integer
217 217
  Args    : sequence string
@@ -219,10 +219,10 @@ sub write_aln {
219 219
 =cut
220 220
 
221 221
 sub _get_len {
222  
-	my ($self,$seq) = @_;
223  
-	my $chars = $Bio::LocatableSeq::GAP_SYMBOLS.$Bio::LocatableSeq::FRAMESHIFT_SYMBOLS;
224  
-	$seq =~ s{[$chars]+}{}gi;
225  
-	return CORE::length($seq);
  222
+    my ($self,$seq) = @_;
  223
+    my $chars = $Bio::LocatableSeq::GAP_SYMBOLS.$Bio::LocatableSeq::FRAMESHIFT_SYMBOLS;
  224
+    $seq =~ s{[$chars]+}{}gi;
  225
+    return CORE::length($seq);
226 226
 }
227 227
 
228 228
 =head2 width
@@ -231,7 +231,7 @@ sub _get_len {
231 231
  Usage   : $obj->width($newwidth)
232 232
            $width = $obj->width;
233 233
  Function: Get/set width of alignment
234  
- Returns : integer value of width 
  234
+ Returns : integer value of width
235 235
  Args    : on set, new value (a scalar or undef, optional)
236 236
 
237 237
 
106  Bio/AlignIO/largemultifasta.pm
@@ -36,15 +36,15 @@ temporary files instead of keeping the whole sequences in memory.
36 36
 
37 37
 =head1 FEEDBACK
38 38
 
39  
-=head2 Support 
  39
+=head2 Support
40 40
 
41 41
 Please direct usage questions or support issues to the mailing list:
42 42
 
43 43
 I<bioperl-l@bioperl.org>
44 44
 
45  
-rather than to the module maintainer directly. Many experienced and 
46  
-reponsive experts will be able look at the problem and quickly 
47  
-address it. Please include a thorough description of the problem 
  45
+rather than to the module maintainer directly. Many experienced and
  46
+reponsive experts will be able look at the problem and quickly
  47
+address it. Please include a thorough description of the problem
48 48
 with code and data examples if at all possible.
49 49
 
50 50
 =head2 Reporting Bugs
@@ -79,13 +79,14 @@ use base qw(Bio::AlignIO Bio::SeqIO Bio::SimpleAlign);
79 79
 
80 80
 
81 81
 sub _initialize {
82  
-  my($self,@args) = @_;
83  
-  $self->SUPER::_initialize(@args);
84  
-  if( ! defined $self->sequence_factory ) {
85  
-      $self->sequence_factory(Bio::Seq::SeqFactory->new
86  
-			      (-verbose => $self->verbose(),
87  
-			       -type => 'Bio::Seq::LargeLocatableSeq'));
88  
-  }
  82
+    my($self,@args) = @_;
  83
+    $self->SUPER::_initialize(@args);
  84
+    if( ! defined $self->sequence_factory ) {
  85
+        $self->sequence_factory(Bio::Seq::SeqFactory->new(
  86
+            -verbose => $self->verbose(),
  87
+            -type => 'Bio::Seq::LargeLocatableSeq'
  88
+        ));
  89
+    }
89 90
 }
90 91
 
91 92
 =head2 next_seq
@@ -106,23 +107,24 @@ sub next_seq {
106 107
     my $count = 0;
107 108
     my $seen = 0;
108 109
     while( defined ($entry = $self->_readline) ) {
109  
-	if( $seen == 1 && $entry =~ /^\s*>/ ) {
110  
-	    $self->_pushback($entry);
111  
-	    return $largeseq;
112  
-	}
113  
-	if ( ($entry eq '>')  ) { $seen = 1; next; }
114  
-	elsif( $entry =~ /\s*>(.+?)$/ ) {
115  
-	    $seen = 1;
116  
-	    ($id,$fulldesc) = ($1 =~ /^\s*(\S+)\s*(.*)$/)
117  
-		or $self->warn("Can't parse fasta header");
118  
-	    $largeseq->display_id($id);
119  
-	    $largeseq->primary_id($id);
120  
-	    $largeseq->desc($fulldesc);
121  
-	} else {
122  
-	    $entry =~ s/\s+//g;
123  
-	    $largeseq->add_sequence_as_string($entry);
124  
-	}
125  
-	(++$count % 1000 == 0 && $self->verbose() > 0) && print "line $count\n";
  110
+        if( $seen == 1 && $entry =~ /^\s*>/ ) {
  111
+            $self->_pushback($entry);
  112
+            return $largeseq;
  113
+        }
  114
+        if ( $entry eq '>' ) {
  115
+            $seen = 1; next;
  116
+        } elsif( $entry =~ /\s*>(.+?)$/ ) {
  117
+            $seen = 1;
  118
+            ($id,$fulldesc) = ($1 =~ /^\s*(\S+)\s*(.*)$/)
  119
+            or $self->warn("Can't parse fasta header");
  120
+            $largeseq->display_id($id);
  121
+            $largeseq->primary_id($id);
  122
+            $largeseq->desc($fulldesc);
  123
+        } else {
  124
+            $entry =~ s/\s+//g;
  125
+            $largeseq->add_sequence_as_string($entry);
  126
+        }
  127
+        (++$count % 1000 == 0 && $self->verbose() > 0) && print "line $count\n";
126 128
     }
127 129
     if( ! $seen ) { return; }
128 130
     return $largeseq;
@@ -135,7 +137,7 @@ sub next_seq {
135 137
  Usage   : $aln = $stream->next_aln()
136 138
  Function: returns the next alignment in the stream.
137 139
  Returns : L<Bio::Align::AlignI> object - returns 0 on end of file
138  
-	    or on error
  140
+        or on error
139 141
  Args    : NONE
140 142
 
141 143
 =cut
@@ -143,7 +145,7 @@ sub next_seq {
143 145
 sub next_aln {
144 146
     my $self = shift;
145 147
     my $largeseq;
146  
-    my $aln =  Bio::SimpleAlign->new();
  148
+    my $aln = Bio::SimpleAlign->new();
147 149
     while (defined ($largeseq = $self->next_seq) ) {
148 150
         $aln->add_seq($largeseq);
149 151
         $self->debug("sequence readed\n");
@@ -151,14 +153,14 @@ sub next_aln {
151 153
 
152 154
     my $alnlen = $aln->length;
153 155
     foreach my $largeseq ( $aln->each_seq ) {
154  
-	if( $largeseq->length < $alnlen ) {
155  
-	    my ($diff) = ($alnlen - $largeseq->length);
156  
-	    $largeseq->seq("-" x $diff);
157  
-	}
  156
+        if( $largeseq->length < $alnlen ) {
  157
+            my ($diff) = ($alnlen - $largeseq->length);
  158
+            $largeseq->seq("-" x $diff);
  159
+        }
158 160
     }
159 161
 
160 162
     return $aln if $aln->num_sequences;
161  
-	return;
  163
+    return;
162 164
 
163 165
 }
164 166
 
@@ -178,23 +180,23 @@ sub write_aln {
178 180
     my ($seq,$desc,$rseq,$name,$count,$length,$seqsub);
179 181
 
180 182
     foreach my $aln (@aln) {
181  
-	if( ! $aln || ! $aln->isa('Bio::Align::AlignI')  ) {
182  
-	    $self->warn("Must provide a Bio::Align::AlignI object when calling write_aln");
183  
-	    next;
184  
-	}
185  
-	foreach $rseq ( $aln->each_seq() ) {
186  
-	    $name = $aln->displayname($rseq->get_nse());
187  
-	    $seq  = $rseq->seq();
188  
-	    $desc = $rseq->description || '';
189  
-	    $self->_print (">$name $desc\n") or return ;
190  
-	    $count =0;
191  
-	    $length = length($seq);
192  
-	    while( ($count * 60 ) < $length ) {
193  
-		$seqsub = substr($seq,$count*60,60);
194  
-		$self->_print ("$seqsub\n") or return ;
195  
-		$count++;
196  
-	    }
197  
-	}
  183
+        if( ! $aln || ! $aln->isa('Bio::Align::AlignI')  ) {
  184
+            $self->warn("Must provide a Bio::Align::AlignI object when calling write_aln");
  185
+            next;
  186
+        }
  187
+        foreach $rseq ( $aln->each_seq() ) {
  188
+            $name = $aln->displayname($rseq->get_nse());
  189
+            $seq  = $rseq->seq();
  190
+            $desc = $rseq->description || '';
  191
+            $self->_print (">$name $desc\n") or return ;
  192
+            $count =0;
  193
+            $length = length($seq);
  194
+            while( ($count * 60 ) < $length ) {
  195
+                $seqsub = substr($seq,$count*60,60);
  196
+                $self->_print ("$seqsub\n") or return ;
  197
+                $count++;
  198
+            }
  199
+        }
198 200
     }
199 201
     $self->flush if $self->_flush_on_write && defined $self->_fh;
200 202
     return 1;

0 notes on commit 0e0ddd3

Please sign in to comment.
Something went wrong with that request. Please try again.