multi

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: 13 Imported by: 11

Documentation

Overview

Package multi handles collections of sequences as alignments or sets.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterJoiner

func RegisterJoiner(p seq.Sequence, f JoinFunc)

Types

type JoinFunc

type JoinFunc func(a, b seq.Sequence, where int) (err error)

type Multi

type Multi struct {
	seq.Annotation
	Seq            []seq.Sequence
	ColumnConsense seq.ConsenseFunc
	Encode         alphabet.Encoding
}

func NewMulti

func NewMulti(id string, n []seq.Sequence, cons seq.ConsenseFunc) (*Multi, error)

Create a new Multi sequence.

Example
m, err := NewMulti("example multi",
	[]seq.Sequence{
		linear.NewSeq("example DNA 1", []alphabet.Letter("ACGCTGACTTGGTGCACGT"), alphabet.DNA),
		linear.NewSeq("example DNA 2", []alphabet.Letter("ACGGTGACCTGGCGCGCAT"), alphabet.DNA),
		linear.NewSeq("example DNA 3", []alphabet.Letter("ACGATGACGTGGCGCTCAT"), alphabet.DNA),
	},
	seq.DefaultConsensus)

if err != nil {
	return
}

fmt.Printf("%- s\n\n%-s\n", m, m.Consensus(false))
Output:

ACGCTGACTTGGTGCACGT
ACGGTGACCTGGCGCGCAT
ACGATGACGTGGCGCTCAT

acgntgacntggcgcncat

func (*Multi) Add

func (m *Multi) Add(n ...seq.Sequence) error

Add adds sequences n to the multiple sequence.

Example
var err error
fmt.Printf("%v %-s\n", m.Rows(), m.Consensus(false))
err = m.Add(linear.NewQSeq("example DNA",
	[]alphabet.QLetter{{'a', 40}, {'c', 39}, {'g', 40}, {'C', 38}, {'t', 35}, {'g', 20}},
	alphabet.DNA, alphabet.Sanger))
if err != nil {
	fmt.Println(err)
	return
}
fmt.Printf("%v %-s\n", m.Rows(), m.Consensus(false))
err = m.Add(linear.NewQSeq("example RNA",
	[]alphabet.QLetter{{'a', 40}, {'c', 39}, {'g', 40}, {'C', 38}, {'t', 35}, {'g', 20}},
	alphabet.RNA, alphabet.Sanger))
if err != nil {
	fmt.Println(err)
	return
}
Output:

3 acgntgacntggcgcncat
4 acgctgacntggcgcncat
multi: inconsistent alphabets

func (*Multi) Append

func (m *Multi) Append(i int, a ...alphabet.QLetter) (err error)

Append appends a to the ith sequence in the receiver.

func (*Multi) AppendColumns

func (m *Multi) AppendColumns(a ...[]alphabet.QLetter) (err error)

Append each byte of each a to the appropriate sequence in the receiver.

func (*Multi) AppendEach

func (m *Multi) AppendEach(a [][]alphabet.QLetter) (err error)

AppendEach appends each []alphabet.QLetter in a to the appropriate sequence in the receiver.

func (*Multi) Clone

func (m *Multi) Clone() seq.Rower

Clone returns a copy of the sequence.

Example
n = m.Clone().(*Multi)
n.Row(2).Set(3, alphabet.QLetter{L: 't'})
fmt.Printf("%- s\n\n%-s\n\n%- s\n\n%-s\n",
	m, m.Consensus(false),
	n, n.Consensus(false),
)
Output:

ACGCTGACTTGGTGCACGT
ACGGTGACCTGGCGCGCAT
ACGATGACGTGGCGCTCAT
acgCtg

acgctgacntggcgcncat

ACGCTGACTTGGTGCACGT
ACGGTGACCTGGCGCGCAT
ACGtTGACGTGGCGCTCAT
acgCtg

acgctgacntggcgcncat

func (*Multi) Column

func (m *Multi) Column(pos int, fill bool) []alphabet.Letter

Column returns a slice of letters reflecting the column at pos.

func (*Multi) ColumnQL

func (m *Multi) ColumnQL(pos int, fill bool) []alphabet.QLetter

ColumnQL returns a slice of quality letters reflecting the column at pos.

func (*Multi) Compose

func (m *Multi) Compose(fs feat.Set) error

Compose produces a composition of the receiver defined by the features in fs. The result is stored in the receiver and all contributing sequences are modified.

func (*Multi) Conformation

func (m *Multi) Conformation() feat.Conformation

Conformation returns the sequence conformation.

func (*Multi) Consensus

func (m *Multi) Consensus(includeMissing bool) *linear.QSeq

Consensus returns a quality sequence reflecting the consensus of the receiver determined by the ColumnConsense field.

func (*Multi) Delete

func (m *Multi) Delete(i int)

Delete removes the sequence represented at row i of the alignment. It panics if i is out of range.

func (*Multi) Encoding

func (m *Multi) Encoding() alphabet.Encoding

Encoding returns the quality encoding scheme.

func (*Multi) End

func (m *Multi) End() int

End returns the end position of the sequence in coordinates relative to the sequence location.

func (*Multi) Flush

func (m *Multi) Flush(where int, fill alphabet.Letter)

Flush fills ragged sequences with the receiver's gap letter so that all sequences are flush.

func (*Multi) Format

func (m *Multi) Format(fs fmt.State, c rune)

Format is a support routine for fmt.Formatter. It accepts the formats 'v' and 's' (string), 'a' (fasta) and 'q' (fastq). String, fasta and fastq formats support truncated output via the verb's precision. Fasta format supports sequence line specification via the verb's width field. Fastq format supports optional inclusion of the '+' line descriptor line with the '+' flag. The 'v' verb supports the '#' flag for Go syntax output. The 's' and 'v' formats support the '-' flag for omission of the sequence name and in conjunction with this, the ' ' flag for alignment justification.

func (*Multi) IsFlush

func (m *Multi) IsFlush(where int) bool

IsFlush returns a boolean indicating whether the end specified by where is flush - that is all the contributing sequences start at the same offset.

Example
m.Row(3).SetOffset(13)
fmt.Printf("%- s\n\n%-s\n", m, m.Consensus(false))
fmt.Printf("\nFlush at left: %v\nFlush at right: %v\n", m.IsFlush(seq.Start), m.IsFlush(seq.End))
m.Flush(seq.Start, '-')
fmt.Printf("\n%- s\n\n%-s\n", m, m.Consensus(false))
fmt.Printf("\nFlush at left: %v\nFlush at right: %v\n", m.IsFlush(seq.Start), m.IsFlush(seq.End))
Output:

ACGCTGACTTGGTGCACGT
ACGGTGACCTGGCGCGCAT
ACGATGACGTGGCGCTCAT
             acgCtg

acgntgacntggcgcgcat

Flush at left: false
Flush at right: true

ACGCTGACTTGGTGCACGT
ACGGTGACCTGGCGCGCAT
ACGATGACGTGGCGCTCAT
-------------acgCtg

acgntgacntggcgcgcat

Flush at left: true
Flush at right: true

func (*Multi) Join

func (m *Multi) Join(a *Multi, where int) error

Join joins a to the receiver at the end specied by where.

Example
fmt.Printf("%- s\n\n%-s\n", n, n.Consensus(false))
n.Join(m, seq.End)
fmt.Printf("\n%- s\n\n%-s\n", n, n.Consensus(false))
Output:

ACGCTGACTTGGTGCACGT
ACGGTGACCTGGCGCGCAT
ACGtTGACGTGGCGCTCAT
acgCtg

acgctgacntggcgcncat

ACGCTGACTTGGTGCACGTACGCTGACTTGGTGCACGT
ACGGTGACCTGGCGCGCATACGGTGACCTGGCGCGCAT
ACGtTGACGTGGCGCTCATACGATGACGTGGCGCTCAT
acgCtg--------------------------acgCtg

acgctgacntggcgcncatacgntgacntggcgcgcat

func (*Multi) Len

func (m *Multi) Len() int

Len returns the length of the alignment.

Example
fmt.Println(m.Len())
Output:

19

func (*Multi) RevComp

func (m *Multi) RevComp()

RevComp reverse complements the sequence.

Example
fmt.Printf("%- s\n\n%-s\n\n", m, m.Consensus(false))
m.RevComp()
fmt.Printf("%- s\n\n%-s\n", m, m.Consensus(false))
Output:

ACGCTGACTTGGTGCACGT
ACGGTGACCTGGCGCGCAT
ACGATGACGTGGCGCTCAT
-------------acgCtg

acgntgacntggcgcgcat

ACGTGCACCAAGTCAGCGT
ATGCGCGCCAGGTCACCGT
ATGAGCGCCACGTCATCGT
caGcgt-------------

atgcgcgccangtcancgt

func (*Multi) Reverse

func (m *Multi) Reverse()

Reverse reverses the order of letters in the the sequence without complementing them.

func (*Multi) Row

func (m *Multi) Row(i int) seq.Sequence

Row returns the sequence represented at row i of the alignment. It panics is i is out of range.

func (*Multi) Rows

func (m *Multi) Rows() int

Rows returns the number of rows in the alignment.

Example
fmt.Println(m.Rows())
Output:

4

func (*Multi) SetConformation

func (m *Multi) SetConformation(c feat.Conformation)

SetConformation sets the sequence conformation.

func (*Multi) SetEncoding

func (m *Multi) SetEncoding(e alphabet.Encoding)

SetEncoding sets the quality encoding scheme to e.

func (*Multi) SetOffset

func (m *Multi) SetOffset(o int) error

SetOffset sets the location-relative offset of the sequence to o.

func (*Multi) Start

func (m *Multi) Start() int

Start returns the start position of the sequence in coordinates relative to the sequence location.

func (*Multi) Stitch

func (m *Multi) Stitch(fs feat.Set) error

Stitch produces a subsequence of the receiver defined by fs. The result is stored in the receiver and all contributing sequences are modified.

Example
f := fs{
	&fe{s: -1, e: 4},
	&fe{s: 30, e: 38},
}
fmt.Printf("%- s\n\n%-s\n\n", n, n.Consensus(false))
if err := n.Stitch(f); err == nil {
	fmt.Printf("%- s\n\n%-s\n", n, n.Consensus(false))
} else {
	fmt.Println(err)
}
Output:

ACGCTGACTTGGTGCACGTACGCTGACTTGGTGCACGT
ACGGTGACCTGGCGCGCATACGGTGACCTGGCGCGCAT
ACGtTGACGTGGCGCTCATACGATGACGTGGCGCTCAT
acgCtg--------------------------acgCtg

acgctgacntggcgcncatacgntgacntggcgcgcat

ACGCGTGCACGT
ACGGGCGCGCAT
ACGtGCGCTCAT
acgC--acgCtg

acgcgcgcgcat

func (*Multi) String

func (m *Multi) String() string

func (*Multi) Subseq

func (m *Multi) Subseq(start, end int) (*Multi, error)

Subseq returns a multiple subsequence slice of the receiver.

func (*Multi) Truncate

func (m *Multi) Truncate(start, end int) error

Truncate truncates the the receiver from start to end.

Example
fmt.Printf("%- s\n\n%-s\n\n", m, m.Consensus(false))
m.Truncate(4, 12)
fmt.Printf("%- s\n\n%-s\n", m, m.Consensus(false))
Output:

ACGTGCACCAAGTCAGCGT
ATGCGCGCCAGGTCACCGT
ATGAGCGCCACGTCATCGT
caGcgt-------------

atgcgcgccangtcancgt

GCACCAAG
GCGCCAGG
GCGCCACG
gt------

gcgccang

type Set

type Set []seq.Sequence

func (Set) AppendEach

func (s Set) AppendEach(a [][]alphabet.QLetter) (err error)

Append each []byte in a to the appropriate sequence in the receiver.

Example
ss := [][]alphabet.Letter{
	[]alphabet.Letter("ACGCTGACTTGGTGCACGT"),
	[]alphabet.Letter("ACGACTGGGACGT"),
	[]alphabet.Letter("ACGCTGACTGGCCGT"),
	[]alphabet.Letter("GCCTTTGCACGT"),
}
set = make(Set, 4)
for i := range set {
	set[i] = linear.NewSeq(fmt.Sprintf("example DNA %d", i), ss[i], alphabet.DNA)
}
as := [][]alphabet.QLetter{
	alphabet.QLetter{L: 'A'}.Repeat(2),
	alphabet.QLetter{L: 'C'}.Repeat(2),
	alphabet.QLetter{L: 'G'}.Repeat(2),
	alphabet.QLetter{L: 'T'}.Repeat(2),
}

set.AppendEach(as)

for _, s := range set {
	fmt.Printf("%-s\n", s)
}
Output:

ACGCTGACTTGGTGCACGTAA
ACGACTGGGACGTCC
ACGCTGACTGGCCGTGG
GCCTTTGCACGTTT

func (Set) Len

func (s Set) Len() int
Example
fmt.Println(set.Len())
Output:

21

func (Set) RevComp

func (s Set) RevComp()
Example
set.RevComp()
for _, s := range set {
	fmt.Println(s)
}
Output:

func (Set) Reverse

func (s Set) Reverse()
Example
set.RevComp()
for _, s := range set {
	fmt.Println(s)
}
Output:

func (Set) Row

func (s Set) Row(i int) seq.Sequence
Example
fmt.Printf("%-s\n", set.Row(2))
Output:

ACGCTGACTGGCCGTGG

func (Set) Rows

func (s Set) Rows() (c int)
Example
fmt.Println(set.Rows())
Output:

4

Jump to

Keyboard shortcuts

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