fastq

package
v0.0.0-...-d966d87 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2020 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package fastq provides code for working with FASTQ format data. https://en.wikipedia.org/wiki/FASTQ_format.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrShort is returned when a truncated FASTQ file is encountered.
	ErrShort = errors.New("short FASTQ file")
	// ErrInvalid is returned when an invalid FASTQ file is encountered.
	ErrInvalid = errors.New("invalid FASTQ file")
	// ErrDiscordant is returned when two underlying FASTQ files are discordant.
	ErrDiscordant = errors.New("discordant FASTQ pairs")
)

Functions

func Downsample

func Downsample(ctx context.Context, rate float64, r1Path, r2Path string, r1Out, r2Out io.Writer) error

Downsample writes read pairs from the two files to r1Out and r2Out. Read pairs will be randomly selected for inclusion in the output at the given sampling rate.

func DownsampleToCount

func DownsampleToCount(ctx context.Context, count int64, r1Path, r2Path string, r1Out, r2Out io.Writer) (err error)

DownsampleToCount writes read pairs from the two files to r1Out and r2Out. Read pairs will be randomly selected for inclusion in the output to downsample to the given count, approximately.

Types

type Field

type Field uint

Field enumerates FASTQ fields. It is used to specify fields to read in NewScanner.

const (
	// ID causes the Read.ID field to be filled
	ID Field = 1 << iota
	// Seq causes the Read.Seq field to be filled
	Seq
	// Unk causes the Read.Unk field to be filled
	Unk
	// Qual causes the Read.Unk field to be filled
	Qual
	// All equals ID|Seq|Unk|Qual.
	All = ID | Seq | Unk | Qual
)

type PairScanner

type PairScanner struct {
	// contains filtered or unexported fields
}

PairScanner composes a pair of scanners to scan a pair of FASTQ streams.

func NewPairScanner

func NewPairScanner(r1, r2 io.Reader, fields Field) *PairScanner

NewPairScanner creates a new FASTQ pair scanner from the provided R1 and R2 readers.

func (*PairScanner) Err

func (p *PairScanner) Err() error

Err returns the scanning error, if any. It should be checked after Scan returns false.

func (*PairScanner) Scan

func (p *PairScanner) Scan(r1, r2 *Read) bool

Scan scans the next read pair into r1, r2. Scan returns a boolean indicating whether the scan succeeded. Once Scan returns false, it never returns true again. Upon completion, the user should check the Err method to determine whether scanning stopped because of an error or because the end of the stream was reached.

type Read

type Read struct {
	ID, Seq, Unk, Qual string
}

A Read is a FASTQ read, comprising an ID, sequence, line 3 ("unknown"), and a quality string.

func (*Read) Trim

func (r *Read) Trim(n int)

Trim cuts the read and quality lengths to at most n.

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

Scanner provides a convenient interface for reading FASTQ read data. The Scan method returns the next read, returning a boolean indicating whether the read succeeded. Scanners are not threadsafe.

Scanner performs some validation: it requires ID lines to begin with "@" and that line 3 begins with "+", but does not perform further validation (e.g., seq/qual being of equal length, containing only data in range, etc.)

func NewScanner

func NewScanner(r io.Reader, fields Field) *Scanner

NewScanner constructs a new Scanner that reads raw FASTQ data from the provided reader. Fields is a bitset of the fields to read. A typical value would be All or ID|Seq|Qual.

func (*Scanner) Err

func (f *Scanner) Err() error

Err returns the scanning error, if any.

func (*Scanner) Scan

func (f *Scanner) Scan(read *Read) bool

Scan the next read into the provided read. Scan returns a boolean indicating whether the scan succeeded. Once Scan returns false, it never returns true again. Upon completion, the user should check the Err method to determine whether scanning stopped because of an error or because the end of the stream was reached.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer is a FASTQ file writer.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter constructs a new FASTQ writer that writes reads to the underlying writer w.

func (*Writer) Write

func (w *Writer) Write(r *Read) error

Write writes the read r in FASTQ format. An error is returned if the write failed.

Jump to

Keyboard shortcuts

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