Ejemplo n.º 1
0
// Truncate the sequence from start to end, wrapping if the sequence is circular.
func (self *Seq) Truncate(start int, end int) (err error) {
	var tt interface{}

	sl, sr := (self.Len()-start-self.offset+int(self.S.RightPad)+3)/4, (end-self.offset+int(self.S.LeftPad)+3)/4

	if s, e := (start-self.offset+int(self.S.LeftPad))/4, (end-self.offset+int(self.S.LeftPad)+3)/4; s != 0 || e != len(self.S.Letters) {
		tt, err = sequtils.Truncate(self.S.Letters, s, e, self.circular)
		if err == nil {
			self.S.Letters = tt.([]alphabet.Pack)
		} else {
			return
		}
	}

	if self.circular && start > end {
		if sl+sr != len(self.S.Letters) {
			panic(fmt.Sprintf("packed: internal inconsistency %d + %d != %d", (sl+3)/4, (sr+3)/4, len(self.S.Letters)))
		}
		self.S.shiftRight(self.S.Letters[:sl], self.S.RightPad)
		self.S.shiftLeft(self.S.Letters[len(self.S.Letters)-sr:], self.S.LeftPad)

		self.S.LeftPad, self.S.RightPad = int8(4-start-self.offset+int(self.S.RightPad))&3, int8(4-end-self.offset+int(self.S.LeftPad))&3
		self.offset = 0
	} else {
		self.S.LeftPad, self.S.RightPad = int8(start-self.offset+int(self.S.LeftPad))&3, int8(4-end-self.offset+int(self.S.LeftPad))&3
		self.offset = start
	}
	self.circular = false

	return
}
Ejemplo n.º 2
0
Archivo: qseq.go Proyecto: frogs/biogo
// Truncate the sequenc from start to end, wrapping if the sequence is circular.
func (self *QSeq) Truncate(start int, end int) (err error) {
	tt, err := sequtils.Truncate(self.S, start-self.offset, end-self.offset, self.circular)
	if err == nil {
		self.S = tt.([]alphabet.QLetter)
		self.offset = start
		self.circular = false
	}

	return
}
Ejemplo n.º 3
0
// Return a subsequence from start to end, wrapping if the sequence is circular.
func (self *Solexa) Subseq(start int, end int) (q *Solexa, err error) {
	tt, err := sequtils.Truncate(self.S, start-self.offset, end-self.offset, self.circular)
	if err == nil {
		q = &Solexa{}
		*q = *self
		q.S = tt.([]alphabet.Qsolexa)
		q.S = nil
		q.Meta = nil
		q.offset = start
		q.circular = false
	}

	return
}
Ejemplo n.º 4
0
Archivo: qseq.go Proyecto: frogs/biogo
// Return a subsequence from start to end, wrapping if the sequence is circular.
func (self *QSeq) Subseq(start int, end int) (sub seq.Sequence, err error) {
	var s *QSeq

	tt, err := sequtils.Truncate(self.S, start-self.offset, end-self.offset, self.circular)
	if err == nil {
		s = &QSeq{}
		*s = *self
		s.S = tt.([]alphabet.QLetter)
		s.S = nil
		s.Meta = nil
		s.offset = start
		s.circular = false
	}

	return s, nil
}
Ejemplo n.º 5
0
Archivo: phred.go Proyecto: frogs/biogo
// Return a subsequence from start to end, wrapping if the sequence is circular.
func (self *Phred) Subseq(start int, end int) (sub seq.Quality, err error) {
	var q *Phred

	tt, err := sequtils.Truncate(self.S, start-self.offset, end-self.offset, self.circular)
	if err == nil {
		q = &Phred{}
		*q = *self
		q.S = tt.([]alphabet.Qphred)
		q.S = nil
		q.Meta = nil
		q.offset = start
		q.circular = false
	}

	return q, nil
}
Ejemplo n.º 6
0
// Return a subsequence from start to end, wrapping if the sequence is circular.
func (self *Seq) Subseq(start int, end int) (sub seq.Sequence, err error) {
	var (
		ps *Seq
		tt interface{}
	)

	sl, sr := (self.Len()-start-self.offset+int(self.S.RightPad)+3)/4, (end-self.offset+int(self.S.LeftPad)+3)/4

	if s, e := (start-self.offset+int(self.S.LeftPad))/4, (end-self.offset+int(self.S.LeftPad)+3)/4; s != 0 || e != len(self.S.Letters) {
		tt, err = sequtils.Truncate(self.S.Letters, s, e, self.circular)
		if err == nil {
			ps = &Seq{}
			*ps = *self
			ps.S = &Packing{}
			*ps.S = *self.S
			ps.S.Letters = tt.([]alphabet.Pack)
			ps.Meta = nil
		} else {
			return
		}
	}

	if ps.circular && start > end {
		if sl+sr != len(ps.S.Letters) {
			panic(fmt.Sprintf("internal inconsistency %d + %d != %d", (sl+3)/4, (sr+3)/4, len(ps.S.Letters)))
		}
		ps.S.shiftRight(ps.S.Letters[:sl], ps.S.RightPad)
		ps.S.shiftLeft(ps.S.Letters[len(ps.S.Letters)-sr:], ps.S.LeftPad)

		ps.S.LeftPad, ps.S.RightPad = int8(4-start-ps.offset+int(ps.S.RightPad))&3, int8(4-end-ps.offset+int(ps.S.LeftPad))&3
		ps.offset = 0
	} else {
		ps.S.LeftPad, ps.S.RightPad = int8(start-ps.offset+int(ps.S.LeftPad))&3, int8(4-end-ps.offset+int(ps.S.LeftPad))&3
		ps.offset = start
	}
	ps.circular = false

	return ps, err
}