# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
require 'maasha/base36'
+require 'maasha/seq'
# Error class for all exceptions to do with SFF.
class SFFError < StandardError; end
class SFF
include Enumerable
- @@count = 0
-
# Class method for opening SFF files.
def self.open(*args)
ios = File.open(*args)
@flow_chars = ""
@key_sequence = ""
@eight_byte_padding = 0
+ @count = 0
header_parse
end
# Method to parse a read section of an SFF file.
def read_parse
- return nil if @number_of_reads == @@count
+ return nil if @number_of_reads == @count
template = "nnNnnnn"
fast_forward
- @@count += 1
+ @count += 1
read
end
# Method that converts a Read object's data to a Biopiece record (a hash).
def to_bp
- coordinates_get
+ # Simulated SFF files may not have coordinates.
+ begin
+ coordinates_get
+ rescue
+ end
hash = {}
hash[:CLIP_QUAL_RIGHT] = self.clip_qual_right - 1
hash[:CLIP_ADAPTOR_LEFT] = self.clip_adapter_left - 1
hash[:CLIP_ADAPTOR_RIGHT] = self.clip_adaptor_right - 1
- hash[:SCORES] = self.quality_scores.map { |i| (i += 64).chr }.join ""
+ hash[:SCORES] = self.quality_scores.map { |i| (i += Seq::SCORE_BASE).chr }.join ""
hash[:X_POS] = self.x_pos
hash[:Y_POS] = self.y_pos
hash
end
+ # Method that converts a Read object's data to a Seq object.
+ def to_seq
+ Seq.new(self.name, self.bases, nil, self.quality_scores.map { |i| (i += Seq::SCORE_BASE).chr }.join("") )
+ end
+
# Method that soft masks the sequence (i.e. lowercases sequence) according to
# clip_qual_left and clip_qual_right information.
def mask
right = self.bases[self.clip_qual_right ... self.bases.length].downcase
self.bases = left + middle + right
+
+ self
end
# Method that clips sequence (i.e. trims) according to
def clip
self.bases = self.bases[self.clip_qual_left - 1 ... self.clip_qual_right]
self.quality_scores = self.quality_scores[self.clip_qual_left - 1 ... self.clip_qual_right]
+
+ self
end
private