Documentation ¶
Overview ¶
Package fasta provides types to read and write FASTA format files.
Index ¶
Examples ¶
Constants ¶
const ( DefaultIDPrefix = ">" DefaultSeqPrefix = "" )
Default delimiters.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
Fasta sequence format reader type.
Example ¶
package main import ( "fmt" "log" "strings" "github.com/biogo/biogo/alphabet" "github.com/biogo/biogo/io/seqio" "github.com/biogo/biogo/io/seqio/fasta" "github.com/biogo/biogo/seq/linear" ) func main() { const multiFasta = ` >SequenceA dam methylation site GATC >SequenceB ori motif CTAG >SequenceC CTCF binding motif CCGCGNGGNGGCAG` data := strings.NewReader(multiFasta) // fasta.Reader requires a known type template to fill // with FASTA data. Here we use *linear.Seq. template := linear.NewSeq("", nil, alphabet.DNAredundant) r := fasta.NewReader(data, template) // Make a seqio.Scanner to simplify iterating over a // stream of data. sc := seqio.NewScanner(r) // Iterate through each sequence in a multifasta and examine the // ID, description and sequence data. for sc.Next() { // Get the current sequence and type assert to *linear.Seq. // While this is unnecessary here, it can be useful to have // the concrete type. s := sc.Seq().(*linear.Seq) // Print the sequence ID, description and sequence data. fmt.Printf("%q %q %s\n", s.ID, s.Desc, s.Seq) } if err := sc.Error(); err != nil { log.Fatal(err) } }
Output: "SequenceA" "dam methylation site" GATC "SequenceB" "ori motif" CTAG "SequenceC" "CTCF binding motif" CCGCGNGGNGGCAG
func NewReader ¶
func NewReader(f io.Reader, template seqio.SequenceAppender) *Reader
Returns a new fasta format reader using f. Sequences returned by the Reader are copied from the provided template.
func (*Reader) Read ¶
Read a single sequence and return it and potentially an error. Note that a non-nil returned error may be associated with a valid sequence, so it is the responsibility of the caller to examine the error to determine whether the read was successful. Note that if the Reader's template type returns different non-nil error values from calls to SetName and SetDescription, a new error string will be returned on each call to Read. So to allow direct error comparison these methods should return the same error.