예제 #1
0
파일: packed.go 프로젝트: frogs/biogo
// 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
}
예제 #2
0
파일: qseq.go 프로젝트: 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
}
예제 #3
0
파일: solexa.go 프로젝트: frogs/biogo
// 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
}
예제 #4
0
파일: qseq.go 프로젝트: 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
}
예제 #5
0
파일: phred.go 프로젝트: 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
}
예제 #6
0
파일: packed.go 프로젝트: frogs/biogo
// 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
}