13 =head2 my $blc = new BLC;
19 my $class = ref($proto) || $proto;
24 return bless $self, $class;
27 =head2 my $blc->read_file($file)
38 open BLC, $fn or croak "$fn: $!\n";
44 my ( $id, $title ) = split /\s+/, $_, 2;
45 $title = '' unless $title;
46 push @seqs, [ $id, $title ];
49 # This regex copes with odd variations in the start of
50 # the iterations line that marks the start of sequences
51 if (/^\s*\*\s*[Ii]teration:?\s*(\d+)\s*$/) {
53 # The start position of the sequences is the same
54 # as the offset of the asterix from the start of
56 my $start = index $_, '*', 0;
58 croak "Iteration not greater than 0 in BLC file $fn" unless $iter > 0;
62 last if /^\s{$start}\*\s*$/;
63 my $line = substr $_, $start, @seqs;
65 foreach ( 0 .. $#seqs ) {
67 # Not just $iter, as we need to
68 # leave room for the title
70 $seqs[$_]->[ SEQ + $iter - 1 ] .= substr( $line, $_, 1 );
76 croak "No sequences found in BLC file $fn" unless @seqs;
79 my ( $id, $title, @seqs ) = @{$_};
80 $title = '' unless defined $title;
81 $id = '' unless defined $id;
82 $self->set_sequence( $id, $title, @seqs );
86 =head2 $blc->set_sequence($id, $title, @seq)
88 Add a BLC file to the object of $id, $title and @sequence, one sequence per iteration.
94 my ( $id, $title, @data ) = @_;
95 push @{ $self->{_seqs} }, [ $id, $title, @data ];
98 =head2 $blc->get_sequence($number)
100 Returns a list of the ($id, $title, @sequences) where each member of @sequences
101 is from the itterations, from first to final. Defaults to the first sequences.
106 my ( $self, $number ) = @_;
107 if ( defined $number and $number > $self->get_num_seqs ) {
108 croak "You're trying to retrive a sequence past than the end of the BLC file in get_sequence($number)";
109 } elsif ( defined $number and $self->get_num_seqs + $number < 0 ) {
110 croak "You're trying to retrive a sequence before the begining of the BLC file in get_sequence($number)";
112 $number = 0 unless defined $number;
114 return @{ ${ $self->{_seqs} }[$number] };
117 =head2 $blc->get_num_seqs()
119 Returns the number of sequences in the BLC file.
125 return $#{ $self->{_seqs} };
128 =head2 $blc->get_sequences($iteration)
130 Returns all of the sequences in a block file for a particular itteration,
131 in the same order as they occured in the block file. If left undefined,
132 it will return the sequences from the first itteration.
137 my ( $self, $iteration ) = @_;
138 $iteration = 0 unless $iteration and $iteration > 0;
139 return map { $_->[ SEQ + $iteration ] } @{ $self->{_seqs} };
142 =head2 $blc->get_seq_ids($number)
144 Returns the ID for the $number sequence to occur in the file, if left undefined it'll return all of the IDs.
149 my ( $self, $number ) = @_;
150 if ( defined $number ) {
151 return ${ $self->{_seqs}[$number] }[ID];
153 return map { $_->[ID] } @{ $self->{_seqs} };
157 =head2 $blc->get_seq_titles($number)
159 Returns the titles for the number sequence to occur in the file, if left undefined it'll return all of the titles.
164 my ( $self, $number ) = @_;
165 if ( defined $number ) {
166 return ${ $self->{_seqs}[$number] }[TITLE];
168 return map { $_->[TITLE] } @{ $self->{_seqs} };
172 =head2 $blc->print_blc($fh);
174 This will print the BLC file object to the filehandle if given, otherwise to STDOUT.
179 my ( $self, $fh ) = @_;
181 if ($fh) { *OUT = $fh }
182 else { *OUT = *STDOUT }
185 print OUT ">$_\n" foreach $self->get_seq_ids;
188 #my @sequences = $self->get_sequences
191 my @sequences = $self->get_sequences($i);
192 last unless defined $sequences[0];
193 print OUT "* iteration " . ( $i + 1 ) . "\n";
194 foreach my $j ( 0 .. length( $sequences[0] ) - 1 ) {
195 foreach (@sequences) {
196 print OUT substr $_, $j, 1;
205 =head2 $blc->print_fasta($fh)
207 Prints the BLC file out in FASTA format, each sequence is 72 characters wide.
212 my ( $self, $fh ) = @_;
214 if ($fh) { *OUT = $fh }
215 else { *OUT = *STDOUT }
217 my @ids = $self->get_seq_ids;
218 my @sequences = $self->get_sequences;
220 croak "Different number of sequences and IDs\n" unless @ids == @sequences;
221 foreach ( 0 .. $#ids ) {
222 print OUT ">$ids[$_]\n";
223 $sequences[$_] =~ s/(.{72})/$1\n/g;
224 print OUT "$sequences[$_]\n";
228 =head2 $blc->next_itteration;
232 sub next_itteration {
234 $self->itteration( $self->itteration + 1 );
237 =head2 $blc->next_itteration;
243 return $self->{_max_itteration};
246 =head2 $blc->itteration($number)
248 If $number is defined, sets the itteration to $number, otherwise returns the number of itterations.
253 my ( $self, $itteration ) = @_;
254 if ( defined $itteration ) {
255 if ( $itteration < 1 ) {
259 return $self->{_itteration};