# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
require 'maasha/base36'
+require 'maasha/seq'
# Error class for all exceptions to do with SFF.
class SFFError < StandardError; 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(
+ seq_name: self.name,
+ seq: self.bases,
+ qual: 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