Debian Codegraph @

io/seqio/fasta/fasta_example_test.go

raw
1 // Copyright ©2020 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 fasta_test
6
7 import (
8 "fmt"
9 "log"
10 "strings"
11
12 "github.com/biogo/biogo/alphabet"
13 "github.com/biogo/biogo/io/seqio"
14 "github.com/biogo/biogo/io/seqio/fasta"
15 "github.com/biogo/biogo/seq/linear"
16 )
17
18 func ExampleReader() {
19 const multiFasta = `
20 >SequenceA dam methylation site
21 GATC
22 >SequenceB ori motif
23 CTAG
24 >SequenceC CTCF binding motif
25 CCGCGNGGNGGCAG`
26
27 data := strings.NewReader(multiFasta)
28
29 // fasta.Reader requires a known type template to fill
30 // with FASTA data. Here we use *linear.Seq.
31 template := linear.NewSeq("", nil, alphabet.DNAredundant)
32 r := fasta.NewReader(data, template)
33
34 // Make a seqio.Scanner to simplify iterating over a
35 // stream of data.
36 sc := seqio.NewScanner(r)
37
38 // Iterate through each sequence in a multifasta and examine the
39 // ID, description and sequence data.
40 for sc.Next() {
41 // Get the current sequence and type assert to *linear.Seq.
42 // While this is unnecessary here, it can be useful to have
43 // the concrete type.
44 s := sc.Seq().(*linear.Seq)
45
46 // Print the sequence ID, description and sequence data.
47 fmt.Printf("%q %q %s\n", s.ID, s.Desc, s.Seq)
48 }
49 if err := sc.Error(); err != nil {
50 log.Fatal(err)
51 }
52
53 // Output:
54 // "SequenceA" "dam methylation site" GATC
55 // "SequenceB" "ori motif" CTAG
56 // "SequenceC" "CTCF binding motif" CCGCGNGGNGGCAG
57 }