Exemplo n.º 1
0
func init() {
	var err error
	m, err = NewMulti("example multi",
		[]protein.Sequence{
			protein.NewSeq("example protein 1", []alphabet.Letter("ACGCTGACTTGGTGCACGT"), alphabet.Protein),
			protein.NewSeq("example protein 2", []alphabet.Letter("ACGGTGACCTGGCGCGCAT"), alphabet.Protein),
			protein.NewSeq("example protein 3", []alphabet.Letter("ACGATGACGTGGCGCTCAT"), alphabet.Protein),
		},
		protein.Consensify)

	if err != nil {
		panic(err)
	}
}
Exemplo n.º 2
0
func (s *S) TestReadFasta(c *check.C) {
	var (
		obtainN []string
		obtainS [][]alphabet.Letter
	)

	for _, fa := range fas {
		r := NewReader(bytes.NewBufferString(fa), protein.NewSeq("", nil, alphabet.Protein))
		for {
			if s, err := r.Read(); err != nil {
				if err == io.EOF {
					break
				} else {
					c.Fatalf("Failed to read %q: %s", fa, err)
				}
			} else {
				t := s.(*protein.Seq)
				header := *t.Name()
				if desc := *t.Description(); len(desc) > 0 {
					header += " " + desc
				}
				obtainN = append(obtainN, header)
				obtainS = append(obtainS, *(t.Raw().(*[]alphabet.Letter)))
			}
		}
		c.Check(obtainN, check.DeepEquals, expectN)
		obtainN = nil
		for i := range obtainS {
			c.Check(len(obtainS[i]), check.Equals, len(expectS[i]))
			c.Check(obtainS[i], check.DeepEquals, expectS[i])
		}
		obtainS = nil
	}
}
Exemplo n.º 3
0
func ExampleSet_AppendEach() {
	ss := [][]alphabet.Letter{
		[]alphabet.Letter("ACGCTGACTTGGTGCACGT"),
		[]alphabet.Letter("ACGACTGGGACGT"),
		[]alphabet.Letter("ACGCTGACTGGCCGT"),
		[]alphabet.Letter("GCCTTTGCACGT"),
	}
	set = make(Set, 4)
	for i := range set {
		set[i] = protein.NewSeq(fmt.Sprintf("example DNA %d", i), ss[i], alphabet.Protein)
	}
	as := [][]alphabet.QLetter{
		alphabet.QLetter{L: 'A'}.Repeat(2),
		alphabet.QLetter{L: 'C'}.Repeat(2),
		alphabet.QLetter{L: 'G'}.Repeat(2),
		alphabet.QLetter{L: 'T'}.Repeat(2),
	}

	set.AppendEach(as)

	for _, s := range set {
		fmt.Println(s)
	}
	// Output:
	// ACGCTGACTTGGTGCACGTAA
	// ACGACTGGGACGTCC
	// ACGCTGACTGGCCGTGG
	// GCCTTTGCACGTTT
}
Exemplo n.º 4
0
func (self *Seq) Extract(i int) protein.Sequence {
	s := make([]alphabet.Letter, 0, self.Len())
	for _, c := range self.S {
		s = append(s, c[i])
	}

	return protein.NewSeq(self.SubIDs[i], s, self.alphabet)
}
Exemplo n.º 5
0
func ExampleNewMulti() {
	m, err := NewMulti("example multi",
		[]protein.Sequence{
			protein.NewSeq("example protein 1", []alphabet.Letter("ACGCTGACTTGGTGCACGT"), alphabet.Protein),
			protein.NewSeq("example protein 2", []alphabet.Letter("ACGGTGACCTGGCGCGCAT"), alphabet.Protein),
			protein.NewSeq("example protein 3", []alphabet.Letter("ACGATGACGTGGCGCTCAT"), alphabet.Protein),
		},
		protein.Consensify)

	if err != nil {
		return
	}

	aligned(m)
	// Output:
	// ACGCTGACTTGGTGCACGT
	// ACGGTGACCTGGCGCGCAT
	// ACGATGACGTGGCGCTCAT
	//
	// acgxtgacxtggcgcxcat
}
Exemplo n.º 6
0
func (s *S) TestWriteFasta(c *check.C) {
	fa := fas[0]
	expectSize := 4649
	var total int
	b := &bytes.Buffer{}
	w := NewWriter(b, 60)

	seq := protein.NewSeq("", nil, alphabet.Protein)

	for i := range expectN {
		seq.ID = expectN[i]
		seq.S = expectS[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)
	c.Check(string(b.Bytes()), check.Equals, fa)
}