# Index method for Seq objects.
def [](*args)
entry = Seq.new
- entry.seq_name = self.seq_name
+ entry.seq_name = self.seq_name.dup if self.seq_name
entry.seq = self.seq[*args]
entry.type = self.type
entry.qual = self.qual[*args] unless self.qual.nil?
self
end
- # Method that returns a subsequence of from a given start position
- # and of a given length.
- def subseq(start, length = self.length - start)
- raise SeqError, "subsequence start: #{start} < 0" if start < 0
- raise SeqError, "subsequence length: #{length} < 0" if length < 0
- raise SeqError, "subsequence start + length > Seq.length: #{start} + #{length} > #{self.length}" if start + length > self.length
-
- if length == 0
- seq = ""
- qual = "" unless self.qual.nil?
- else
- stop = start + length - 1
-
- seq = self.seq[start .. stop]
- qual = self.qual[start .. stop] unless self.qual.nil?
- end
-
- seq_name = self.seq_name.nil? ? nil : self.seq_name.dup
-
- Seq.new(seq_name: seq_name, seq: seq, type: self.type, qual: qual)
- end
-
- # Method that replaces a sequence with a subsequence from a given start position
- # and of a given length.
- def subseq!(start, length = self.length - start)
- s = subseq(start, length)
-
- self.seq_name = s.seq_name
- self.seq = s.seq
- self.type = s.type
- self.qual = s.qual
-
- self
- end
-
# Method that returns a subsequence of a given length
# beginning at a random position.
def subseq_rand(length)
start = rand(self.length - length + 1)
end
- self.subseq(start, length)
+ self[start .. start + length]
end
# Method that returns the residue compositions of a sequence in
if (length % 3) == 0
if size_min <= length and length <= size_max
- subseq = self.subseq(pos_beg, length)
+ subseq = self[pos_beg ... pos_beg + length]
orfs << [subseq, pos_beg, pos_end + 3]
end