Beispiel #1
0
func (s *S) TestWriteFastq(c *check.C) {
	for i, t := range fqTests {
		if !t.verbatim {
			continue
		}
		for j := 0; j < 2; j++ {
			var n int
			b := &bytes.Buffer{}
			w := NewWriter(b)
			w.QID = j == 0
			seq := linear.NewQSeq("", nil, alphabet.DNA, alphabet.Sanger)

			for i := range expectedIds {
				seq.ID = t.ids[i]
				seq.Seq = t.seqs[i]
				_n, err := w.Write(seq)
				c.Assert(err, check.Equals, nil, check.Commentf("Failed to write to buffer: %s", err))
				n += _n
			}

			c.Check(n, check.Equals, b.Len())

			if w.QID {
				c.Check(string(b.Bytes()), check.Equals, t.fq, check.Commentf("Write test %d", i))
			}
		}
	}
}
Beispiel #2
0
func (s *S) TestReadFastq(c *check.C) {
	r := fastq.NewReader(strings.NewReader(fq), linear.NewQSeq("", nil, alphabet.DNA, alphabet.Sanger))
	m, _ := multi.NewMulti("", nil, seq.DefaultQConsensus)
	a, err := NewReader(r, m).Read()
	c.Check(err, check.Equals, nil)
	c.Check(a.Rows(), check.Equals, 25)
}
Beispiel #3
0
func (s *S) TestReadFastq(c *check.C) {
	var (
		obtainNfq []string
		obtainQL  [][]alphabet.QLetter
	)

	sc := seqio.NewScanner(
		fastq.NewReader(
			bytes.NewBufferString(fq0),
			linear.NewQSeq("", nil, alphabet.DNA, alphabet.Sanger),
		),
	)
	for sc.Next() {
		t := sc.Seq().(*linear.QSeq)
		header := t.Name()
		if desc := t.Description(); len(desc) > 0 {
			header += " " + desc
		}
		obtainNfq = append(obtainNfq, header)
		obtainQL = append(obtainQL, (t.Slice().(alphabet.QLetters)))
	}
	c.Check(sc.Error(), check.Equals, nil)
	c.Check(obtainNfq, check.DeepEquals, expectNfq)
	c.Check(obtainQL, check.DeepEquals, expectQL)
}
Beispiel #4
0
func (r QRow) Clone() seq.Sequence {
	b := make([]alphabet.QLetter, r.Len())
	for i, c := range r.Align.Seq {
		b[i] = c[r.Row]
	}
	return linear.NewQSeq(r.Name(), b, r.Alphabet(), r.Align.Encoding())
}
Beispiel #5
0
func ExampleSeq_Add() {
	fmt.Printf("%v %-s\n", m.Rows(), m.Consensus(false))
	m.Add(linear.NewQSeq("example DNA",
		[]alphabet.QLetter{{'a', 40}, {'c', 39}, {'g', 40}, {'C', 38}, {'t', 35}, {'g', 20}},
		alphabet.DNA, alphabet.Sanger))
	fmt.Printf("%v %-s\n", m.Rows(), m.Consensus(false))
	// Output:
	// 3 acgntgacntggcgcncat
	// 4 acgctgacntggcgcncat
}
Beispiel #6
0
// Consensus returns a quality sequence reflecting the consensus of the receiver determined by the
// ColumnConsense field.
func (m *Multi) Consensus(includeMissing bool) *linear.QSeq {
	cm := make([]alphabet.QLetter, 0, m.Len())
	alpha := m.Alphabet()
	for i := m.Start(); i < m.End(); i++ {
		cm = append(cm, m.ColumnConsense(m, alpha, i, includeMissing))
	}

	c := linear.NewQSeq("Consensus:"+m.ID, cm, m.Alpha, m.Encode)
	c.SetOffset(m.Offset)

	return c
}
Beispiel #7
0
// Consensus returns a quality sequence reflecting the consensus of the receiver determined by the
// ColumnConsense field.
func (s *Seq) Consensus(_ bool) *linear.QSeq {
	cs := make([]alphabet.QLetter, 0, s.Len())
	alpha := s.Alphabet()
	for i := range s.Seq {
		cs = append(cs, s.ColumnConsense(s, alpha, i, false))
	}

	qs := linear.NewQSeq("Consensus:"+s.ID, cs, s.Alpha, alphabet.Sanger)
	qs.Strand = s.Strand
	qs.SetOffset(s.Offset)
	qs.Conform = s.Conform

	return qs
}
Beispiel #8
0
func ExampleMulti_Add() {
	var err error
	fmt.Printf("%v %-s\n", m.Rows(), m.Consensus(false))
	err = m.Add(linear.NewQSeq("example DNA",
		[]alphabet.QLetter{{'a', 40}, {'c', 39}, {'g', 40}, {'C', 38}, {'t', 35}, {'g', 20}},
		alphabet.DNA, alphabet.Sanger))
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Printf("%v %-s\n", m.Rows(), m.Consensus(false))
	err = m.Add(linear.NewQSeq("example RNA",
		[]alphabet.QLetter{{'a', 40}, {'c', 39}, {'g', 40}, {'C', 38}, {'t', 35}, {'g', 20}},
		alphabet.RNA, alphabet.Sanger))
	if err != nil {
		fmt.Println(err)
		return
	}
	// Output:
	// 3 acgntgacntggcgcncat
	// 4 acgctgacntggcgcncat
	// multi: inconsistent alphabets
}
Beispiel #9
0
func (s *S) TestReadFastq(c *check.C) {
	for _, t := range fqTests {
		r := NewReader(bytes.NewBufferString(t.fq), linear.NewQSeq("", nil, alphabet.DNA, alphabet.Sanger))
		var n int
		for n = 0; ; n++ {
			if s, err := r.Read(); err != nil {
				if err == io.EOF {
					break
				} else {
					c.Fatalf("Failed to read %s in %q: %s", expectedIds[n], t.fq, err)
				}
			} else {
				l := s.(*linear.QSeq)
				header := l.Name()
				if desc := l.Description(); len(desc) > 0 {
					header += " " + desc
				}
				c.Check(header, check.Equals, t.ids[n])
				c.Check(l.Slice(), check.DeepEquals, t.seqs[n])
			}
		}
		c.Check(n, check.Equals, len(t.ids))
	}
}