Exemplo n.º 1
0
// Return an unpacked sequence.
func (self *Seq) Unpack() (n *nucleic.Seq) {
	n = nucleic.NewSeq(self.ID, alphabet.BytesToLetters([]byte(self.String())), self.alphabet)
	n.Circular(self.circular)
	n.Offset(self.offset)

	return
}
Exemplo n.º 2
0
Arquivo: fasta.go Projeto: frogs/biogo
// Read a single sequence and return it or an error.
func (self *Reader) Read() (s seq.Sequence, err error) {
	var (
		buff, line []byte
		isPrefix   bool
	)

	for {
		if buff, isPrefix, err = self.r.ReadLine(); err == nil {
			if isPrefix {
				line = append(line, buff...)
				continue
			} else {
				line = buff
			}

			line = bytes.TrimSpace(line)
			if len(line) == 0 {
				continue
			}

			if bytes.HasPrefix(line, self.IDPrefix) {
				if self.working == nil {
					self.working = self.header(line)
					line = nil
				} else {
					s = self.working
					self.working = self.header(line)
					line = nil
					break // entering a new sequence so exit read loop
				}
			} else if bytes.HasPrefix(line, self.SeqPrefix) {
				line = bytes.Join(bytes.Fields(line[len(self.SeqPrefix):]), nil)
				self.working.AppendLetters(alphabet.BytesToLetters(line)...)
				line = nil
			} else {
				return nil, bio.NewError("fasta: badly formed line", 0, line)
			}
		} else {
			if err == io.EOF {
				if self.working != nil {
					s = self.working
					self.working = nil
					err = nil
				}
				break
			}
			return nil, err
		}
	}

	return
}
Exemplo n.º 3
0
// Return an unpacked sequence and quality.
func (self *QSeq) Unpack() (n *nucleic.Seq, q *quality.Phred) {
	n = nucleic.NewSeq(self.ID, alphabet.BytesToLetters([]byte(self.String())), self.alphabet)
	n.Circular(self.circular)
	n.Offset(self.offset)
	qb := make([]alphabet.Qphred, self.Len())
	for i, v := range self.S {
		qb[i] = alphabet.Qphred(v >> 2)
	}
	q = quality.NewPhred(self.ID, qb, self.encoding)
	q.Circular(self.circular)
	q.Offset(self.offset)

	return
}
Exemplo n.º 4
0
func checkPackedAlpha(alpha alphabet.Nucleic) error {
	if alpha.Len() != 4 {
		return bio.NewError("Cannot create packed sequence with alphabet length != 4", 0, alpha)
	}
	for _, v := range alphabet.BytesToLetters([]byte(alpha.String())) {
		if c, ok := alpha.Complement(v); ok && alpha.IndexOf(v) != alpha.IndexOf(c)^0x3 {
			// TODO: Resolution to the following problem:
			// Normal nucleotide alphabets (ACGT/ACGU) are safe with this in either case sensitive or
			// insensitive. Other alphabets may not be, in this case specify case sensitive.
			return bio.NewError("alphabet order not consistent with bit operations for packed.", 0, alpha)
		}
	}

	return nil
}