Esempio n. 1
0
func (s *S) TestReadFastq(c *check.C) {
	var (
		obtainN  []string
		obtainQL [][]alphabet.QLetter
	)

	for _, fq := range fqs {
		r := NewReader(bytes.NewBufferString(fq), nucleic.NewQSeq("", nil, alphabet.DNA, alphabet.Sanger))
		for {
			if s, err := r.Read(); err != nil {
				if err == io.EOF {
					break
				} else {
					c.Fatalf("Failed to read %q: %s", fq, err)
				}
			} else {
				t := s.(*nucleic.QSeq)
				header := *t.Name()
				if desc := *t.Description(); len(desc) > 0 {
					header += " " + desc
				}
				obtainN = append(obtainN, header)
				obtainQL = append(obtainQL, *(t.Raw().(*[]alphabet.QLetter)))
			}
		}
		c.Check(obtainN, check.DeepEquals, expectN)
		obtainN = nil
		c.Check(obtainQL, check.DeepEquals, expectQL)
		obtainQL = nil
	}
}
Esempio n. 2
0
func (s *S) TestWriteFastq(c *check.C) {
	fq := fqs[0]
	names := 0
	for _, n := range expectN {
		names += len(n)
	}
	expectSize := []int{2722, 2722 - names}
	var total int
	for j := 0; j < 2; j++ {
		b := &bytes.Buffer{}
		w := NewWriter(b)
		w.QID = j == 0
		seq := nucleic.NewQSeq("", nil, alphabet.DNA, alphabet.Sanger)

		for i := range expectN {
			seq.ID = expectN[i]
			seq.S = expectQL[i]
			if n, err := w.Write(seq); err != nil {
				c.Fatalf("Failed to write to buffer: %s", err)
			} else {
				total += n
			}
		}

		c.Check(total, check.Equals, expectSize[j])
		total = 0

		if w.QID {
			c.Check(string(b.Bytes()), check.Equals, fq)
		}
	}
}
Esempio n. 3
0
func (self *QSeq) Extract(i int) nucleic.Sequence {
	s := make([]alphabet.QLetter, 0, self.Len())
	for _, c := range self.S {
		s = append(s, c[i])
	}

	return nucleic.NewQSeq(self.SubIDs[i], s, self.alphabet, self.encoding)
}
Esempio n. 4
0
func ExampleSeq_Add() {
	fmt.Printf("%v %v\n", m.Count(), m)
	m.Add(nucleic.NewQSeq("example DNA",
		[]alphabet.QLetter{{'a', 40}, {'c', 39}, {'g', 40}, {'C', 38}, {'t', 35}, {'g', 20}},
		alphabet.DNA, alphabet.Sanger))
	fmt.Printf("%v %v\n", m.Count(), m)
	// Output:
	// 3 acgntgacntggcgcncat
	// 4 acgctgacntggcgcncat
}
Esempio n. 5
0
File: multi.go Progetto: frogs/biogo
func (self *Multi) Consensus(includeMissing bool) (c *nucleic.QSeq) {
	cs := make([]alphabet.QLetter, 0, self.Len())
	for i := self.Start(); i < self.End(); i++ {
		cs = append(cs, self.Consensify(self, i, includeMissing))
	}

	c = nucleic.NewQSeq("Consensus:"+self.ID, cs, self.alphabet, self.encoding)
	c.Offset(self.offset)

	return
}
Esempio n. 6
0
func (self *QSeq) Consensus(_ bool) (qs *nucleic.QSeq) {
	cs := make([]alphabet.QLetter, 0, self.Len())
	for i := range self.S {
		cs = append(cs, self.Consensify(self, i, false))
	}

	qs = nucleic.NewQSeq("Consensus:"+self.ID, cs, self.alphabet, alphabet.Sanger)
	qs.Strand = self.Strand
	qs.Offset(self.offset)
	qs.Circular(self.circular)

	return
}
Esempio n. 7
0
func ExampleMulti_Add() {
	var err error
	fmt.Printf("%v %v\n", m.Count(), m)
	err = m.Add(nucleic.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 %v\n", m.Count(), m)
	err = m.Add(nucleic.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
	// Inconsistent alphabets
}