| 1 |
// Copyright ©2011-2012 The bíogo Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package linear |
| 6 |
|
| 7 |
import ( |
| 8 |
"fmt" |
| 9 |
"strings" |
| 10 |
|
| 11 |
"github.com/biogo/biogo/alphabet" |
| 12 |
"github.com/biogo/biogo/feat" |
| 13 |
"github.com/biogo/biogo/seq" |
| 14 |
"github.com/biogo/biogo/seq/sequtils" |
| 15 |
) |
| 16 |
|
| 17 |
func ExampleNewSeq() { |
| 18 |
d := NewSeq("example DNA", []alphabet.Letter("ACGCTGACTTGGTGCACGT"), alphabet.DNA) |
| 19 |
fmt.Printf("%-s %v\n", d, d.Moltype()) |
| 20 |
// Output: |
| 21 |
// ACGCTGACTTGGTGCACGT DNA |
| 22 |
} |
| 23 |
|
| 24 |
func ExampleSeq_Validate() { |
| 25 |
r := NewSeq("example RNA", []alphabet.Letter("ACGCTGACTTGGTGCACGT"), alphabet.RNA) |
| 26 |
fmt.Printf("%-s %v\n", r, r.Moltype()) |
| 27 |
if ok, pos := r.Validate(); ok { |
| 28 |
fmt.Println("valid RNA") |
| 29 |
} else { |
| 30 |
fmt.Println(strings.Repeat(" ", pos-1), "^ first invalid RNA position") |
| 31 |
} |
| 32 |
// Output: |
| 33 |
// ACGCTGACTTGGTGCACGT RNA |
| 34 |
// ^ first invalid RNA position |
| 35 |
} |
| 36 |
|
| 37 |
func ExampleSeq_truncate_a() { |
| 38 |
s := NewSeq("example DNA", []alphabet.Letter("ACGCTGACTTGGTGCACGT"), alphabet.DNA) |
| 39 |
fmt.Printf("%-s\n", s) |
| 40 |
if err := sequtils.Truncate(s, s, 5, 12); err == nil { |
| 41 |
fmt.Printf("%-s\n", s) |
| 42 |
} |
| 43 |
// Output: |
| 44 |
// ACGCTGACTTGGTGCACGT |
| 45 |
// GACTTGG |
| 46 |
} |
| 47 |
|
| 48 |
func ExampleSeq_truncate_b() { |
| 49 |
var s *Seq |
| 50 |
|
| 51 |
s = NewSeq("example DNA", []alphabet.Letter("ACGCTGACTTGGTGCACGT"), alphabet.DNA) |
| 52 |
s.Conform = feat.Circular |
| 53 |
fmt.Printf("%-s Conformation = %v\n", s, s.Conformation()) |
| 54 |
if err := sequtils.Truncate(s, s, 12, 5); err == nil { |
| 55 |
fmt.Printf("%-s Conformation = %v\n", s, s.Conformation()) |
| 56 |
} else { |
| 57 |
fmt.Println("Error:", err) |
| 58 |
} |
| 59 |
|
| 60 |
s = NewSeq("example DNA", []alphabet.Letter("ACGCTGACTTGGTGCACGT"), alphabet.DNA) |
| 61 |
fmt.Printf("%-s Conformation = %v\n", s, s.Conformation()) |
| 62 |
if err := sequtils.Truncate(s, s, 12, 5); err == nil { |
| 63 |
fmt.Printf("%-s Conformation = %v\n", s, s.Conformation()) |
| 64 |
} else { |
| 65 |
fmt.Println("Error:", err) |
| 66 |
} |
| 67 |
// Output: |
| 68 |
// ACGCTGACTTGGTGCACGT Conformation = circular |
| 69 |
// TGCACGTACGCT Conformation = linear |
| 70 |
// ACGCTGACTTGGTGCACGT Conformation = linear |
| 71 |
// Error: sequtils: start position greater than end position for linear sequence |
| 72 |
} |
| 73 |
|
| 74 |
func ExampleSeq_RevComp() { |
| 75 |
s := NewSeq("example DNA", []alphabet.Letter("ATGCtGACTTGGTGCACGT"), alphabet.DNA) |
| 76 |
fmt.Printf("%-s\n", s) |
| 77 |
s.RevComp() |
| 78 |
fmt.Printf("%-s\n", s) |
| 79 |
// Output: |
| 80 |
// ATGCtGACTTGGTGCACGT |
| 81 |
// ACGTGCACCAAGTCaGCAT |
| 82 |
} |
| 83 |
|
| 84 |
func ExampleSeq_join() { |
| 85 |
var s1, s2 *Seq |
| 86 |
|
| 87 |
s1 = NewSeq("a", []alphabet.Letter("agctgtgctga"), alphabet.DNA) |
| 88 |
s2 = NewSeq("b", []alphabet.Letter("CGTGCAGTCATGAGTGA"), alphabet.DNA) |
| 89 |
fmt.Printf("%-s %-s\n", s1, s2) |
| 90 |
if err := sequtils.Join(s1, s2, seq.Start); err == nil { |
| 91 |
fmt.Printf("%-s\n", s1) |
| 92 |
} |
| 93 |
|
| 94 |
s1 = NewSeq("a", []alphabet.Letter("agctgtgctga"), alphabet.DNA) |
| 95 |
s2 = NewSeq("b", []alphabet.Letter("CGTGCAGTCATGAGTGA"), alphabet.DNA) |
| 96 |
if err := sequtils.Join(s1, s2, seq.End); err == nil { |
| 97 |
fmt.Printf("%-s\n", s1) |
| 98 |
} |
| 99 |
// Output: |
| 100 |
// agctgtgctga CGTGCAGTCATGAGTGA |
| 101 |
// CGTGCAGTCATGAGTGAagctgtgctga |
| 102 |
// agctgtgctgaCGTGCAGTCATGAGTGA |
| 103 |
} |
| 104 |
|
| 105 |
type fe struct { |
| 106 |
s, e int |
| 107 |
st seq.Strand |
| 108 |
feat.Feature |
| 109 |
} |
| 110 |
|
| 111 |
func (f fe) Start() int { return f.s } |
| 112 |
func (f fe) End() int { return f.e } |
| 113 |
func (f fe) Len() int { return f.e - f.s } |
| 114 |
func (f fe) Orientation() feat.Orientation { return feat.Orientation(f.st) } |
| 115 |
|
| 116 |
type fs []feat.Feature |
| 117 |
|
| 118 |
func (f fs) Features() []feat.Feature { return []feat.Feature(f) } |
| 119 |
|
| 120 |
func ExampleSeq_stitch() { |
| 121 |
s := NewSeq("example DNA", []alphabet.Letter("aAGTATAAgtcagtgcagtgtctggcagTGCTCGTGCgtagtgaagtagGGTTAGTTTa"), alphabet.DNA) |
| 122 |
f := fs{ |
| 123 |
fe{s: 1, e: 8}, |
| 124 |
fe{s: 28, e: 37}, |
| 125 |
fe{s: 49, e: s.Len() - 1}, |
| 126 |
} |
| 127 |
fmt.Printf("%-s\n", s) |
| 128 |
if err := sequtils.Stitch(s, s, f); err == nil { |
| 129 |
fmt.Printf("%-s\n", s) |
| 130 |
} |
| 131 |
// Output: |
| 132 |
// aAGTATAAgtcagtgcagtgtctggcagTGCTCGTGCgtagtgaagtagGGTTAGTTTa |
| 133 |
// AGTATAATGCTCGTGCGGTTAGTTT |
| 134 |
} |
| 135 |
|
| 136 |
func ExampleSeq_compose() { |
| 137 |
s := NewSeq("example DNA", []alphabet.Letter("aAGTATAAgtcagtgcagtgtctggcag<TS>gtagtgaagtagggttagttta"), alphabet.DNA) |
| 138 |
f := fs{ |
| 139 |
fe{s: 0, e: 32}, |
| 140 |
fe{s: 1, e: 8, st: -1}, |
| 141 |
fe{s: 28, e: s.Len() - 1}, |
| 142 |
} |
| 143 |
fmt.Printf("%-s\n", s) |
| 144 |
if err := sequtils.Compose(s, s, f); err == nil { |
| 145 |
fmt.Printf("%-s\n", s) |
| 146 |
} |
| 147 |
// Output: |
| 148 |
// aAGTATAAgtcagtgcagtgtctggcag<TS>gtagtgaagtagggttagttta |
| 149 |
// aAGTATAAgtcagtgcagtgtctggcag<TS>TTATACT<TS>gtagtgaagtagggttagttt |
| 150 |
} |