本文整理匯總了Golang中code/google/com/p/biogo/bio.NewError函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewError函數的具體用法?Golang NewError怎麽用?Golang NewError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewError函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Join
// Join p to the sequence at the end specified by where.
func (self *Seq) Join(p *Seq, where int) (err error) {
if self.circular {
return bio.NewError("Cannot join circular sequence: receiver.", 0, self)
} else if p.circular {
return bio.NewError("Cannot join circular sequence: parameter.", 0, p)
}
switch where {
case seq.Start:
p = p.Copy().(*Seq)
p.S.Align(seq.End)
self.S.Align(seq.Start)
self.S.LeftPad = p.S.LeftPad
case seq.End:
p = p.Copy().(*Seq)
p.S.Align(seq.Start)
self.S.Align(seq.End)
self.S.RightPad = p.S.RightPad
default:
return bio.NewError("Undefined location.", 0, where)
}
tt, offset := sequtils.Join(self.S.Letters, p.S.Letters, where)
self.offset = offset
self.S.Letters = tt.([]alphabet.Pack)
return
}
示例2: Read
// Read a single sequence and return it or an error.
// TODO: Does not read multi-line fastq.
func (self *Reader) Read() (s seq.Sequence, err error) {
var (
buff, line, label []byte
isPrefix bool
seqBuff []alphabet.QLetter
t seqio.SequenceAppender
)
inQual := false
for {
if buff, isPrefix, err = self.r.ReadLine(); err == nil {
if isPrefix {
line = append(line, buff...)
continue
} else {
line = buff
}
line = bytes.TrimSpace(line)
if len(line) == 0 {
continue
}
switch {
case !inQual && line[0] == '@':
t = self.readHeader(line)
label, line = line, nil
case !inQual && line[0] == '+':
if len(label) == 0 {
return nil, bio.NewError("fastq: no header line parsed before +line in fastq format", 0)
}
if len(line) > 1 && bytes.Compare(label[1:], line[1:]) != 0 {
return nil, bio.NewError("fastq: quality header does not match sequence header", 0)
}
inQual = true
case !inQual:
line = bytes.Join(bytes.Fields(line), nil)
seqBuff = make([]alphabet.QLetter, len(line))
for i := range line {
seqBuff[i].L = alphabet.Letter(line[i])
}
case inQual:
line = bytes.Join(bytes.Fields(line), nil)
if len(line) != len(seqBuff) {
return nil, bio.NewError("fastq: sequence/quality length mismatch", 0)
}
for i := range line {
seqBuff[i].Q = alphabet.DecodeToQphred(line[i], self.enc)
}
t.AppendQLetters(seqBuff...)
return t, nil
}
} else {
return
}
}
panic("cannot reach")
}
示例3: Write
// Write a single sequence and return the number of bytes written and any error.
func (self *Writer) Write(s *seq.Seq) (n int, err error) {
if s.Quality == nil {
return 0, bio.NewError("No quality associated with sequence", 0, s)
}
if s.Len() == s.Quality.Len() {
self.template[1] = []byte(s.ID)
self.template[3] = s.Seq
if self.QID {
self.template[4] = append(append([]byte("\n+"), []byte(s.ID)...), '\n')
} else {
self.template[4] = []byte("\n+\n")
}
self.template[5] = self.encodeQuality(s.Quality.Qual)
var tn int
for _, t := range self.template {
tn, err = self.w.Write(t)
n += tn
if err != nil {
return
}
}
} else {
return 0, bio.NewError("Sequence length and quality length do not match", 0, s)
}
return
}
示例4: fulfill
func (p *Promise) fulfill(value interface{}) (err error) {
r, set := p.messageState()
if r.Err != nil {
err = bio.NewError("Tried to fulfill a failed promise", 0, r.Err)
} else {
if !set || p.mutable {
r.Value = value
err = nil
} else {
err = bio.NewError("Tried to fulfill an already set immutable promise", 0)
}
}
if err != nil && p.relay {
if r.Err != nil {
err = bio.NewError("Promise already failed - cannot relay", 0, r.Err)
} else {
r.Err = err
}
}
p.message <- r
return
}
示例5: Join
func (self *Seq) Join(s *Seq, where int) (j *Seq, err error) {
var (
ts []byte
ID string
)
if self.Circular {
return nil, bio.NewError("Cannot join circular molecule.", 0, self)
}
if !self.Inplace && self.Quality != nil && self.Quality.Inplace {
return nil, bio.NewError("Inplace operation on Quality with non-Inplace operation on parent Seq.", 0, self)
}
switch where {
case Prepend:
ID = s.ID + "+" + self.ID
ts = make([]byte, len(s.Seq), len(s.Seq)+len(self.Seq))
copy(ts, s.Seq)
ts = append(ts, self.Seq...)
case Append:
ID = self.ID + "+" + s.ID
if self.Inplace {
ts = append(self.Seq, s.Seq...)
} else {
ts = make([]byte, len(self.Seq), len(s.Seq)+len(self.Seq))
copy(ts, self.Seq)
ts = append(ts, s.Seq...)
}
}
var q *Quality
if self.Quality != nil && s.Quality != nil {
q, err = self.Quality.Join(s.Quality, where)
if err != nil {
return
}
}
if self.Inplace {
j = self
j.ID = ID
j.Seq = ts
j.Quality = q // self.Quality will become nil if either sequence lacks Quality
} else {
j = &Seq{
ID: ID,
Seq: ts,
Strand: self.Strand,
Moltype: self.Moltype,
Quality: q,
}
}
if where == Prepend {
j.Offset -= s.Len()
}
return
}
示例6: Trunc
func (self *Seq) Trunc(start, end int) (s *Seq, err error) {
var ts []byte
if !self.Inplace && self.Quality != nil && self.Quality.Inplace {
return nil, bio.NewError("Inplace operation on Quality with non-Inplace operation on parent Seq.", 0, self)
}
if start < self.Offset || end < self.Offset ||
start > len(self.Seq)+self.Offset || end > len(self.Seq)+self.Offset {
return nil, bio.NewError("Start or end position out of range.", 0, self)
}
if start <= end {
if self.Inplace {
ts = self.Seq[start-self.Offset : end-self.Offset]
} else {
ts = append([]byte(nil), self.Seq[start-self.Offset:end-self.Offset]...)
}
} else if self.Circular {
if self.Inplace {
ts = append(self.Seq[start-self.Offset:], self.Seq[:end-self.Offset]...) // not quite inplace for this op
} else {
ts = make([]byte, len(self.Seq)-start-self.Offset, len(self.Seq)+end-start)
copy(ts, self.Seq[start-self.Offset:])
ts = append(ts, self.Seq[:end-self.Offset]...)
}
} else {
return nil, bio.NewError("Start position greater than end position for non-circular molecule.", 0, self)
}
var q *Quality
if self.Quality != nil {
q, err = self.Quality.Trunc(start, end)
if err != nil {
err = bio.NewError("Quality.Trunc() returned error", 0, err)
return
}
}
if self.Inplace {
s = self
s.Seq = ts
s.Circular = false
s.Quality = q
} else {
s = &Seq{
ID: self.ID,
Seq: ts,
Offset: start,
Strand: self.Strand,
Circular: false,
Moltype: self.Moltype,
Quality: q,
}
}
return
}
示例7: Pack
// Pack a QLetter into a QPack. a.Len() == 4.
func (self QLetter) Pack(a Nucleic) (QPack, error) {
if a.Len() != 4 {
return 0, bio.NewError("Invalid alphabet", 0, self)
}
if !a.IsValid(self.L) {
return QPack(byte(self.Q) << 2), bio.NewError("Invalid letter", 0, self)
}
return QPack(byte(self.Q)<<2 | byte(a.IndexOf(self.L)&0x3)), nil
}
示例8: featureOf
// Convert coordinates in a packed sequence into a feat.Feature.
func featureOf(contigs *seq.Seq, from, to int, comp bool) (feature *feat.Feature, err error) {
if comp {
from, to = contigs.Len()-to, contigs.Len()-from
}
if from >= to {
return nil, bio.NewError(fmt.Sprintf("%s: from > to", contigs.ID), 0, nil)
}
// DPHit coordinates sometimes over/underflow.
// This is a lazy hack to work around it, should really figure
// out what is going on.
if from < 0 {
from = 0
}
if to > contigs.Len() {
to = contigs.Len()
}
// Take midpoint of segment -- lazy hack again, endpoints
// sometimes under / overflow
bin := (from + to) / (2 * binSize)
binCount := (contigs.Len() + binSize - 1) / binSize
if bin < 0 || bin >= binCount {
return nil, bio.NewError(fmt.Sprintf("%s: bin %d out of range 0..%d", contigs.ID, bin, binCount-1), 0, nil)
}
contigIndex := contigs.Meta.(seqMap).binMap[bin]
if contigIndex < 0 || contigIndex >= len(contigs.Meta.(seqMap).contigs) {
return nil, bio.NewError(fmt.Sprintf("%s: contig index %d out of range 0..%d", contigs.ID, contigIndex, len(contigs.Meta.(seqMap).contigs)), 0, nil)
}
length := to - from
if length < 0 {
return nil, bio.NewError(fmt.Sprintf("%s: length < 0", contigs.ID), 0, nil)
}
contig := contigs.Meta.(seqMap).contigs[contigIndex]
contigFrom := from - contig.from
contigTo := contigFrom + length
if contigFrom < 0 {
contigFrom = 0
}
if contigTo > contig.seq.Len() {
contigTo = contig.seq.Len()
}
return &feat.Feature{
ID: contig.seq.ID,
Start: contigFrom,
End: contigTo,
}, nil
}
示例9: Join
// Join p to the sequence at the end specified by where.
func (self *Seq) Join(p *Seq, where int) (err error) {
if self.circular {
return bio.NewError("Cannot join circular sequence: receiver.", 1, self)
} else if p.circular {
return bio.NewError("Cannot join circular sequence: parameter.", 1, p)
}
tt, offset := sequtils.Join(self.S, p.S, where)
self.offset = offset
self.S = tt.([]alphabet.Letter)
return
}
示例10: Read
// Read a single sequence and return it or an error.
// TODO: Does not read interleaved fastq.
func (self *Reader) Read() (sequence *seq.Seq, err error) {
var line, label, seqBody, qualBody []byte
sequence = &seq.Seq{}
inQual := false
READ:
for {
line, err = self.r.ReadBytes('\n')
if err == nil {
if len(line) > 0 && line[len(line)-1] == '\r' {
line = line[:len(line)-1]
}
line = bytes.TrimSpace(line)
if len(line) == 0 {
continue
}
switch {
case !inQual && line[0] == '@':
label = line[1:]
case !inQual && line[0] == '+':
if len(label) == 0 {
return nil, bio.NewError("No ID line parsed at +line in fastq format", 0)
}
if len(line) > 1 && bytes.Compare(label, line[1:]) != 0 {
return nil, bio.NewError("Quality ID does not match sequence ID", 0)
}
inQual = true
case !inQual:
line = bytes.Join(bytes.Fields(line), nil)
seqBody = append(seqBody, line...)
case inQual:
line = bytes.Join(bytes.Fields(line), nil)
qualBody = append(qualBody, line...)
if len(qualBody) >= len(seqBody) {
break READ
}
}
} else {
return
}
}
if len(seqBody) != len(qualBody) {
return nil, bio.NewError("Quality length does not match sequence length", 0)
}
labelString := string(label)
sequence = seq.New(labelString, seqBody, seq.NewQuality(labelString, self.decodeQuality(qualBody)))
return
}
示例11: Join
// Join p to the sequence at the end specified by where.
func (self *QSeq) Join(p *QSeq, where int) (err error) {
if self.circular {
return bio.NewError("Cannot join circular sequence: receiver.", 1, self)
} else if p.circular {
return bio.NewError("Cannot join circular sequence: parameter.", 1, p)
}
var tt interface{}
tt, self.offset = sequtils.Join(self.S, p.S, where)
self.S = tt.([]alphabet.QPack)
return
}
示例12: KmerOf
// Convert a string of bases into a Kmer, returns an error if string length does not match word length
func (self *Index) KmerOf(kmertext string) (kmer Kmer, err error) {
if len(kmertext) != self.k {
return 0, bio.NewError("Sequence length does not match Kmer length", 0, self.k, kmertext)
}
for _, v := range kmertext {
x := lookUp.ValueToCode[v]
if x < 0 {
return 0, bio.NewError("Kmer contains illegal character", 0, kmertext)
}
kmer = (kmer << 2) | Kmer(x)
}
return
}
示例13: checkPackedAlpha
func checkPackedAlpha(alpha alphabet.Nucleic) error {
if alpha.Len() != 4 {
return bio.NewError("Cannot create packed sequence with alphabet length != 4", 0, alpha)
}
for _, v := range alphabet.BytesToLetters([]byte(alpha.String())) {
if c, ok := alpha.Complement(v); ok && alpha.IndexOf(v) != alpha.IndexOf(c)^0x3 {
// TODO: Resolution to the following problem:
// Normal nucleotide alphabets (ACGT/ACGU) are safe with this in either case sensitive or
// insensitive. Other alphabets may not be, in this case specify case sensitive.
return bio.NewError("alphabet order not consistent with bit operations for packed.", 0, alpha)
}
}
return nil
}
示例14: GetPositionsString
// Return an array of positions for the Kmer string kmertext
func (self *Index) GetPositionsString(kmertext string) (positions []int, err error) {
switch {
case len(kmertext) != self.k:
return nil, bio.NewError("Sequence length does not match Kmer length", 0, self.k, kmertext)
case !self.indexed:
return nil, bio.NewError("Index not built: call Build()", 0, self)
}
var kmer Kmer
if kmer, err = self.KmerOf(kmertext); err != nil {
return nil, err
}
return self.GetPositionsKmer(kmer)
}
示例15: NewSeq
func NewSeq(id string, subids []string, b [][]alphabet.Letter, alpha alphabet.Peptide, cons protein.Consensifyer) (*Seq, error) {
switch lids, lseq := len(subids), len(b); {
case lids == 0 && len(b) == 0:
case lseq != 0 && lids == len(b[0]):
if lids == 0 {
subids = make([]string, len(b[0]))
for i := range subids {
subids[i] = fmt.Sprintf("%s:%d", id, i)
}
}
default:
return nil, bio.NewError("alignment: id/seq number mismatch", 0)
}
return &Seq{
ID: id,
SubIDs: append([]string(nil), subids...),
S: append([][]alphabet.Letter(nil), b...),
alphabet: alpha,
Consensify: cons,
Stringify: func(s seq.Polymer) string {
t := s.(*Seq).Consensus(false)
return t.String()
},
}, nil
}