Exemple #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())...)
		}
	}
}
Exemple #2
0
// String returns a string representation of the sequence data only.
func (s *QSeq) String() string {
	cs := make([]alphabet.Letter, 0, len(s.Seq))
	for _, ql := range s.Seq {
		cs = append(cs, s.QFilter(s.Alpha, s.Threshold, ql))
	}

	return alphabet.Letters(cs).String()
}
Exemple #3
0
// NewSeq creates a new Seq with the given id, letter sequence and alphabet.
func NewSeq(id string, b []alphabet.Letter, alpha alphabet.Alphabet) *Seq {
	return &Seq{
		Annotation: seq.Annotation{
			ID:     id,
			Alpha:  alpha,
			Strand: seq.Plus,
		},
		Seq: append(alphabet.Letters(nil), b...),
	}
}
Exemple #4
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
}
Exemple #5
0
// String returns a string representation of the sequence data only.
func (s *Seq) String() string { return alphabet.Letters(s.Seq).String() }