Пример #1
0
func ExampleSeq_Truncate_2() {
	var s *Seq

	s = NewSeq("example DNA", []alphabet.Letter("ACGCTGACTTGGTGCACGT"), alphabet.DNA)
	s.Conform = feat.Circular
	fmt.Printf("%-s Conformation = %v\n", s, s.Conformation())
	if err := sequtils.Truncate(s, s, 12, 5); err == nil {
		fmt.Printf("%-s Conformation = %v\n", s, s.Conformation())
	} else {
		fmt.Println("Error:", err)
	}

	s = NewSeq("example DNA", []alphabet.Letter("ACGCTGACTTGGTGCACGT"), alphabet.DNA)
	fmt.Printf("%-s Conformation = %v\n", s, s.Conformation())
	if err := sequtils.Truncate(s, s, 12, 5); err == nil {
		fmt.Printf("%-s Conformation = %v\n", s, s.Conformation())
	} else {
		fmt.Println("Error:", err)
	}
	// Output:
	// ACGCTGACTTGGTGCACGT Conformation = circular
	// TGCACGTACGCT Conformation = linear
	// ACGCTGACTTGGTGCACGT Conformation = linear
	// Error: sequtils: start position greater than end position for linear sequence
}
Пример #2
0
// Truncate truncates the the receiver from start to end.
func (m *Multi) Truncate(start, end int) error {
	for _, r := range m.Seq {
		err := sequtils.Truncate(r, r, start, end)
		if err != nil {
			return err
		}
	}

	return nil
}
Пример #3
0
func ExampleSeq_Truncate_1() {
	s := NewSeq("example DNA", []alphabet.Letter("ACGCTGACTTGGTGCACGT"), alphabet.DNA)
	fmt.Printf("%-s\n", s)
	if err := sequtils.Truncate(s, s, 5, 12); err == nil {
		fmt.Printf("%-s\n", s)
	}
	// Output:
	// ACGCTGACTTGGTGCACGT
	// GACTTGG
}
Пример #4
0
// Subseq returns a multiple subsequence slice of the receiver.
func (m *Multi) Subseq(start, end int) (*Multi, error) {
	var ns []seq.Sequence

	for _, r := range m.Seq {
		rs := reflect.New(reflect.TypeOf(r)).Interface().(sequtils.Sliceable)
		err := sequtils.Truncate(rs, r, start, end)
		if err != nil {
			return nil, err
		}
		ns = append(ns, rs.(seq.Sequence))
	}

	ss := &Multi{}
	*ss = *m
	ss.Seq = ns

	return ss, nil
}
Пример #5
0
func ExampleSeq_Truncate() {
	fmt.Printf("%-s\n\n%-s\n", m, m.Consensus(false))
	err := sequtils.Truncate(m, m, 4, 12)
	if err == nil {
		fmt.Printf("\n%-s\n\n%-s\n", m, m.Consensus(false))
	}
	// Output:
	// ACGTGCACCAAGTCAGCGT
	// ATGCGCGCCAGGTCACCGT
	// ATGAGCGCCACGTCATCGT
	// -------------caGcgt
	//
	// atgngcgccangtcagcgt
	//
	// GCACCAAG
	// GCGCCAGG
	// GCGCCACG
	// --------
	//
	// gcgccang
}
Пример #6
0
func (m *PWM) Search(s Sequence, start, end int, minScore float64) []feat.Feature {
	if minScore < m.minScore {
		m.table = make(probTable, 0)
		m.genTable(minScore, 0, 0, make([]byte, len(m.matrix)))
		sort.Sort(m.table)
	}

	var (
		index  = s.Alphabet().LetterIndex()
		length = len(m.matrix)

		freqs = make([]float64, 4)
		zeros = make([]float64, 4)

		diff = 1 / float64(length)

		f []feat.Feature
	)

LOOP:
	for pos := start; pos+length < end; pos++ {
		// Determine the score for this position.
		var score = 0.
		for i := 0; i < length; i++ {
			base := index[s.At(pos+i).L]
			if base < 0 || minScore-score > m.lookAhead[i] { // not valid base or will not be able to achieve minScore
				continue LOOP
			} else {
				score += m.matrix[i][base]
			}
		}

		if score < minScore {
			continue
		}

		// Calculate base frequencies for window.
		copy(freqs, zeros)
		for i := pos; i < pos+length; i++ {
			base := index[s.At(i).L]
			if base >= 0 {
				freqs[base] += diff
			} else { // Probability for this pos will be meaningless; if N is tolerated, include N in valid alphabet - make special case?
				continue LOOP
			}
		}

		// Descend probability function summing probabilities.
		var (
			prob = 0.
			sp   = 0.
		)
		for _, e := range m.table {
			sp = 1
			if e.score < score {
				break
			}
			for i, f := range freqs {
				sp *= math.Pow(f, float64(e.freqs[i]))
			}
			sp *= float64(e.occurrence)
			prob += sp
		}

		mot := s.New()
		sequtils.Truncate(mot, s, pos, pos+length)
		f = append(f, &Feature{
			MotifLocation: s,
			MotifStart:    pos,
			MotifEnd:      pos + length,
			MotifScore:    score,
			MotifProb:     prob,
			MotifSeq:      mot,
			MotifOrient:   s.Orientation(),
			Moltype:       s.Moltype(),
		})
	}

	return f
}