| 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_testscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/io/seqio/fasta_test`/ |
| 6 | |
| 7 | import ( |
| 8 | "fmtscip-go gomod github.com/golang/go/src go1.14 fmt/" |
| 9 | "logscip-go gomod github.com/golang/go/src go1.14 log/" |
| 10 | "stringsscip-go gomod github.com/golang/go/src go1.14 strings/" |
| 11 | |
| 12 | "github.com/biogo/biogo/alphabetscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/" |
| 13 | "github.com/biogo/biogo/io/seqioscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/io/seqio`/" |
| 14 | "github.com/biogo/biogo/io/seqio/fastascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/io/seqio/fasta`/" |
| 15 | "github.com/biogo/biogo/seq/linearscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/seq/linear`/" |
| 16 | ) |
| 17 | |
| 18 | func ExampleReaderscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/io/seqio/fasta_test`/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 := stringsscip-go gomod github.com/golang/go/src go1.14 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.14 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 := linearscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/seq/linear`/.NewSeqscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/seq/linear`/NewSeq().("", nil, alphabetscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/.DNAredundantscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/DNAredundant.) |
| 32 | r := fastascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/io/seqio/fasta`/.NewReaderscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/io/seqio/fasta`/NewReader().(data, template) |
| 33 | |
| 34 | // Make a seqio.Scanner to simplify iterating over a |
| 35 | // stream of data. |
| 36 | sc := seqioscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/io/seqio`/.NewScannerscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/io/seqio`/NewScanner().(r) |
| 37 | |
| 38 | // Iterate through each sequence in a multifasta and examine the |
| 39 | // ID, description and sequence data. |
| 40 | for sc.Nextscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/io/seqio`/Scanner#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.Seqscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/io/seqio`/Scanner#Seq().().(*linearscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/seq/linear`/.Seqscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/seq/linear`/Seq#) |
| 45 | |
| 46 | // Print the sequence ID, description and sequence data. |
| 47 | fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Printfscip-go gomod github.com/golang/go/src go1.14 fmt/Printf().("%q %q %s\n", s.IDscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/seq`/Annotation#ID., s.Descscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/seq`/Annotation#Desc., s.Seqscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/seq/linear`/Seq#Seq.) |
| 48 | } |
| 49 | if err := sc.Errorscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/io/seqio`/Scanner#Error().(); err != nil { |
| 50 | logscip-go gomod github.com/golang/go/src go1.14 log/.Fatalscip-go gomod github.com/golang/go/src go1.14 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 | } |