Example #1
0
// Flush fills ragged sequences with the receiver's gap letter so that all sequences are flush.
func (m *Multi) Flush(where int, fill alphabet.Letter) {
	if m.IsFlush(where) {
		return
	}

	if where&seq.Start != 0 {
		start := m.Start()
		for _, r := range m.Seq {
			if r.Start()-start < 1 {
				continue
			}
			switch sl := r.Slice().(type) {
			case alphabet.Letters:
				r.SetSlice(alphabet.Letters(append(fill.Repeat(r.Start()-start), sl...)))
			case alphabet.QLetters:
				r.SetSlice(alphabet.QLetters(append(alphabet.QLetter{L: fill}.Repeat(r.Start()-start), sl...)))
			}
			r.SetOffset(start)
		}
	}
	if where&seq.End != 0 {
		end := m.End()
		for _, r := range m.Seq {
			if end-r.End() < 1 {
				continue
			}
			r.(seq.Appender).AppendQLetters(alphabet.QLetter{L: fill}.Repeat(end - r.End())...)
		}
	}
}
Example #2
0
File: qseq.go Project: gordon/biogo
// NewQSeq create a new QSeq with the given id, letter sequence, alphabet and quality encoding.
func NewQSeq(id string, ql []alphabet.QLetter, alpha alphabet.Alphabet, enc alphabet.Encoding) *QSeq {
	return &QSeq{
		Annotation: seq.Annotation{
			ID:     id,
			Alpha:  alpha,
			Strand: seq.Plus,
		},
		Seq:       append(alphabet.QLetters(nil), ql...),
		Encode:    enc,
		Threshold: 3,
		QFilter:   seq.AmbigFilter,
	}
}
Example #3
0
// Format returns a [2]alphabet.Slice representing the formatted alignment of a and b described by the
// list of feature pairs in f, with gap used to fill gaps in the alignment.
func Format(a, b seq.Slicer, f []feat.Pair, gap alphabet.Letter) [2]alphabet.Slice {
	var as, aln [2]alphabet.Slice
	for i, s := range [2]seq.Slicer{a, b} {
		as[i] = s.Slice()
		aln[i] = as[i].Make(0, 0)
	}
	for _, fs := range f {
		fc := fs.Features()
		for i := range aln {
			if fc[i].Len() == 0 {
				switch aln[i].(type) {
				case alphabet.Letters:
					aln[i] = aln[i].Append(alphabet.Letters(gap.Repeat(fc[1-i].Len())))
				case alphabet.QLetters:
					aln[i] = aln[i].Append(alphabet.QLetters(alphabet.QLetter{L: gap}.Repeat(fc[1-i].Len())))
				}
			} else {
				aln[i] = aln[i].Append(as[i].Slice(fc[i].Start(), fc[i].End()))
			}
		}
	}
	return aln
}