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*$/) {
52 # The start position of the sequences is the same
53 # as the offset of the asterix from the start of
55 my $start = index $_, '*', 0;
57 croak "Iteration not greater than 0 in BLC file $fn" unless $iter > 0;
61 last if /^\s{$start}\*\s*$/;
62 my $line = substr $_, $start, @seqs;
65 # Not just $iter, as we need to
66 # leave room for the title
68 $seqs[$_]->[SEQ + $iter - 1] .= substr($line, $_, 1);
74 croak "No sequences found in BLC file $fn" unless @seqs;
77 my ($id, $title, @seqs) = @{$_};
78 $title = '' unless defined $title;
79 $id = '' unless defined $id;
80 $self->set_sequence($id, $title, @seqs);
84 =head2 $blc->set_sequence($id, $title, @seq)
86 Add a BLC file to the object of $id, $title and @sequence, one sequence per iteration.
92 my ($id, $title, @data) = @_;
93 push @{$self->{_seqs}}, [ $id, $title, @data ];
96 =head2 $blc->get_sequence($number)
98 Returns a list of the ($id, $title, @sequences) where each member of @sequences is from the itterations, from first to final. Defaults to the first sequences.
103 my ($self, $number) = @_;
104 if (defined $number and $number > $self->get_num_seqs) {
105 croak "You're trying to retrive a sequence past than the end of the BLC file in get_sequence($number)";
107 elsif (defined $number and $self->get_num_seqs + $number < 0) {
108 croak "You're trying to retrive a sequence before the begining of the BLC file in get_sequence($number)";
110 $number = 0 unless defined $number;
112 return @{${$self->{_seqs}}[$number]};
115 =head2 $blc->get_num_seqs()
117 Returns the number of sequences in the BLC file.
123 return $#{$self->{_seqs}};
126 =head2 $blc->get_sequences($iteration)
128 Returns all of the sequences in a block file for a particular itteration, in the same order as they occured in the block file. If left undefined, it will return the sequences from the first itteration.
133 my ($self, $iteration) = @_;
134 $iteration = 0 unless $iteration and $iteration > 0;
135 return map { $_->[SEQ + $iteration] } @{$self->{_seqs}};
138 =head2 $blc->get_seq_ids($number)
140 Returns the ID for the $number sequence to occur in the file, if left undefined it'll return all of the IDs.
145 my ($self, $number) = @_;
146 if (defined $number) {
147 return ${$self->{_seqs}[$number]}[ID];
150 return map { $_->[ID] } @{$self->{_seqs}};
154 =head2 $blc->get_seq_titles($number)
156 Returns the titles for the number sequence to occur in the file, if left undefined it'll return all of the titles.
161 my ($self, $number) = @_;
162 if (defined $number) {
163 return ${$self->{_seqs}[$number]}[TITLE];
166 return map { $_->[TITLE] } @{$self->{_seqs}};
170 =head2 $blc->print_blc($fh);
172 This will print the BLC file object to the filehandle if given, otherwise to STDOUT.
177 my ($self, $fh) = @_;
179 if ($fh) { *OUT = $fh }
180 else { *OUT = *STDOUT }
183 print OUT ">$_\n" foreach $self->get_seq_ids;
186 #my @sequences = $self->get_sequences
189 my @sequences = $self->get_sequences($i);
190 last unless defined $sequences[0];
191 print OUT "* iteration ".($i + 1)."\n";
192 foreach my $j (0..length($sequences[0]) -1) {
193 foreach (@sequences) {
194 print OUT substr $_, $j, 1;
203 =head2 $blc->print_fasta($fh)
205 Prints the BLC file out in FASTA format, each sequence is 72 characters wide.
210 my ($self, $fh) = @_;
212 if ($fh) { *OUT = $fh }
213 else { *OUT = *STDOUT }
215 my @ids = $self->get_seq_ids;
216 my @sequences = $self->get_sequences;
218 croak "Different number of sequences and IDs\n" unless @ids == @sequences;
220 print OUT ">$ids[$_]\n";
221 $sequences[$_] =~ s/(.{72})/$1\n/g;
222 print OUT "$sequences[$_]\n";
226 =head2 $blc->next_itteration;
230 sub next_itteration {
232 $self->itteration($self->itteration + 1);
235 =head2 $blc->next_itteration;
241 return $self->{_max_itteration};
244 =head2 $blc->itteration($number)
246 If $number is defined, sets the itteration to $number, otherwise returns the number of itterations.
251 my ($self, $itteration) = @_;
252 if (defined $itteration) {
253 if ($itteration < 1) {
256 #if ($itteration > $self->{_max_itteration};
257 #$self->{_itteration} = $itteration;
260 return $self->{_itteration};