github.com/biogo/biogo@v1.0.4/seq/multi/set.go (about)

     1  // Copyright ©2011-2012 The bíogo Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package multi
     6  
     7  import (
     8  	"github.com/biogo/biogo/alphabet"
     9  	"github.com/biogo/biogo/seq"
    10  	"github.com/biogo/biogo/util"
    11  
    12  	"fmt"
    13  )
    14  
    15  type Set []seq.Sequence
    16  
    17  // Interface guarantees
    18  var (
    19  	_ seq.Rower       = (*Set)(nil)
    20  	_ seq.RowAppender = (*Set)(nil)
    21  )
    22  
    23  // Append each []byte in a to the appropriate sequence in the receiver.
    24  func (s Set) AppendEach(a [][]alphabet.QLetter) (err error) {
    25  	if len(a) != s.Rows() {
    26  		return fmt.Errorf("multi: number of sequences does not match row count: %d != %d.", len(a), s.Rows())
    27  	}
    28  	for i, r := range s {
    29  		r.(seq.Appender).AppendQLetters(a[i]...)
    30  	}
    31  	return nil
    32  }
    33  
    34  func (s Set) Row(i int) seq.Sequence {
    35  	return s[i]
    36  }
    37  
    38  func (s Set) Len() int {
    39  	max := util.MinInt
    40  
    41  	for _, r := range s {
    42  		if l := r.Len(); l > max {
    43  			max = l
    44  		}
    45  	}
    46  
    47  	return max
    48  }
    49  
    50  func (s Set) Rows() (c int) {
    51  	return len(s)
    52  }
    53  
    54  func (s Set) Reverse() {
    55  	for _, r := range s {
    56  		r.Reverse()
    57  	}
    58  }
    59  
    60  func (s Set) RevComp() {
    61  	for _, r := range s {
    62  		r.RevComp()
    63  	}
    64  }