Exemple #1
0
// WriteStockholm writes the given MSA to the writer in the Stockholm format.
// This does not write any features. It only creates a minimal valid Stockholm
// file with the header (and version) along with the sequences (names and
// residues).
func WriteStockholm(w io.Writer, msa seq.MSA) error {
	var err error
	pf := func(format string, v ...interface{}) {
		if err != nil {
			return
		}
		_, err = fmt.Fprintf(w, format, v...)
	}
	pf("# STOCKHOLM 1.0\n")
	for row := 0; row < len(msa.Entries) && err == nil; row++ {
		s := msa.GetA2M(row)
		pf("%s %s\n", s.Name, s.Residues)
	}
	pf("//\n")
	return err
}
Exemple #2
0
func addToMSA(sequences chan seq.Sequence, msa *seq.MSA) {
	wgSeqFragments.Add(1)
	go func() {
		for s := range sequences {
			// We don't use Add or AddFasta since both are
			// O(#sequences * #frag-length), which gets to be quite slow
			// in the presence of a lot of sequences.
			//
			// The key here is that we know that every sequence has the same
			// length and is in the same format, so we can add entries in a
			// straight forward manner.
			msa.Entries = append(msa.Entries, s)
		}
		wgSeqFragments.Done()
	}()
}
Exemple #3
0
func testEqualAlign(t *testing.T, computed, answer seq.MSA) {
	if computed.Len() != answer.Len() {
		t.Fatalf("Lengths of MSAs differ: %d != %d",
			computed.Len(), answer.Len())
	}

	scomputed := makeStrings(computed.Entries)
	sanswer := makeStrings(answer.Entries)
	if len(scomputed) != len(sanswer) {
		t.Fatalf("\nLengths of entries in MSAs differ: %d != %d",
			len(scomputed), len(sanswer))
	}
	for i := 0; i < len(scomputed); i++ {
		c, a := scomputed[i], sanswer[i]
		if c != a {
			t.Fatalf("\nComputed sequence in MSA is\n\n%s\n\n"+
				"but answer is\n\n%s", c, a)
		}
	}
}
Exemple #4
0
// WriteA3M writes a multiple sequence alignment to the output in
// A3M format. A3M format uses upper case characters to indicate
// matches, lower case characters to indicate insertions, and '-'
// characters to indicate deletions.
//
// A3M format is a more compact way to write an MSA than FASTA or A2M.
func WriteA3M(w io.Writer, msa seq.MSA) error {
	formatter := func(row int) seq.Sequence {
		return msa.GetA3M(row)
	}
	return write(w, msa, formatter)
}