fasta

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2021 License: BSD-3-Clause Imports: 7 Imported by: 51

Documentation

Overview

Package fasta provides types to read and write FASTA format files.

Index

Examples

Constants

View Source
const (
	DefaultIDPrefix  = ">"
	DefaultSeqPrefix = ""
)

Default delimiters.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	IDPrefix  []byte
	SeqPrefix []byte
	// contains filtered or unexported fields
}

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

func (r *Reader) Read() (seq.Sequence, error)

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.

type Writer

type Writer struct {
	IDPrefix  []byte
	SeqPrefix []byte
	Width     int
	// contains filtered or unexported fields
}

Fasta sequence format writer type.

func NewWriter

func NewWriter(w io.Writer, width int) *Writer

Returns a new fasta format writer using f.

func (*Writer) Write

func (w *Writer) Write(s seq.Sequence) (n int, err error)

Write a single sequence and return the number of bytes written and any error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL