Exemplo n.º 1
0
func ExampleQSeq_RevComp() {
	q := []alphabet.Qphred{
		2, 13, 19, 22, 19, 18, 20, 23, 23, 20, 16, 21, 24, 22, 22, 18, 17, 18, 22, 23, 22, 24, 22, 24, 20, 15,
		18, 18, 19, 19, 20, 12, 18, 17, 20, 20, 20, 18, 15, 18, 24, 21, 13, 8, 15, 20, 20, 19, 20, 20, 20, 18,
		16, 16, 16, 10, 15, 18, 18, 18, 11, 2, 11, 20, 19, 18, 18, 16, 10, 12, 22, 0, 0, 0, 0}
	l := []alphabet.Letter("NTTTCTTCTATATCCTTTTCATCTTTTAATCCATTCACCATTTTTTTCCCTCCACCTACCTNTCCTTCTCTTTCT")
	if s, err := NewQSeq("example DNA", nil, alphabet.DNA, alphabet.Sanger); err == nil {
		s.Stringify = func(p seq.Polymer) string {
			s := p.(*QSeq)
			lb, qb, b := []alphabet.Letter{}, []byte{}, []byte{}
			for i, qp := range s.S {
				ql := qp.Unpack(s.Alphabet().(alphabet.Nucleic))
				if ql.Q > 2 {
					ql.L &^= 0x20
				} else {
					ql.L = 'n'
				}
				lb = append(lb, ql.L)
				qb = append(qb, s.QEncode(seq.Position{Pos: i}))
			}
			b = append(b, alphabet.LettersToBytes(lb)...)
			b = append(b, '\n')
			b = append(b, qb...)
			return string(b)
		}

		for i := range l {
			s.AppendQLetters(alphabet.QLetter{L: l[i], Q: q[i]})
		}
		fmt.Println("Forward:")
		fmt.Println(s)
		s.RevComp()
		fmt.Println("Reverse:")
		fmt.Println(s)
	}
	// Output:
	// Forward:
	// nTTTCTTCTATATCCTTTTCATCTTTTAATCCATTCACCATTTTTTTCCCTCCACCTACCTnTCCTTCTCTnnnn
	// #.47435885169773237879795033445-3255530396.)05545553111+0333,#,54331+-7!!!!
	// Reverse:
	// nnnnAGAGAAGGAnAGGTAGGTGGAGGGAAAAAAATGGTGAATGGATTAAAAGATGAAAAGGATATAGAAGAAAn
	// !!!!7-+13345,#,3330+11135554550).6930355523-54433059797873237796158853474.#
}
Exemplo n.º 2
0
func ExampleQSeq_Append() {
	q := []alphabet.Qphred{
		2, 13, 19, 22, 19, 18, 20, 23, 23, 20, 16, 21, 24, 22, 22, 18, 17, 18, 22, 23, 22, 24, 22, 24, 20, 15,
		18, 18, 19, 19, 20, 12, 18, 17, 20, 20, 20, 18, 15, 18, 24, 21, 13, 8, 15, 20, 20, 19, 20, 20, 20, 18,
		16, 16, 16, 10, 15, 18, 18, 18, 11, 2, 11, 20, 19, 18, 18, 16, 10, 12, 22, 0, 0, 0, 0}
	l := []alphabet.Letter("NTTTCTTCTATATCCTTTTCATCTTTTAATCCATTCACCATTTTTTTCCCTCCACCTACCTNTCCTTCTCTTTCT")
	s := NewQSeq("example Protein", nil, alphabet.Protein, alphabet.Sanger)
	s.Stringify = func(p seq.Polymer) string {
		s := p.(*QSeq)
		lb, qb, b := []alphabet.Letter{}, []byte{}, []byte{}
		for i, ql := range s.S {
			lb = append(lb, ql.L)
			qb = append(qb, s.QEncode(seq.Position{Pos: i}))
		}
		b = append(b, alphabet.LettersToBytes(lb)...)
		b = append(b, '\n')
		b = append(b, qb...)
		return string(b)
	}

	for i := range l {
		s.AppendQLetters(alphabet.QLetter{L: l[i], Q: q[i]})
	}
	fmt.Println("Forward:")
	fmt.Println(s)
	s.Reverse()
	fmt.Println("Reverse:")
	fmt.Println(s)
	// Output:
	// Forward:
	// NTTTCTTCTATATCCTTTTCATCTTTTAATCCATTCACCATTTTTTTCCCTCCACCTACCTNTCCTTCTCTTTCT
	// #.47435885169773237879795033445-3255530396.)05545553111+0333,#,54331+-7!!!!
	// Reverse:
	// TCTTTCTCTTCCTNTCCATCCACCTCCCTTTTTTTACCACTTACCTAATTTTCTACTTTTCCTATATCTTCTTTN
	// !!!!7-+13345,#,3330+11135554550).6930355523-54433059797873237796158853474.#
}