7 "github.com/kshedden/gonpy"
11 type exportSuite struct{}
13 var _ = check.Suite(&exportSuite{})
15 func (s *exportSuite) TestFastaToNumpy(c *check.C) {
16 var buffer bytes.Buffer
17 exited := (&importer{}).RunCommand("import", []string{"-local=true", "-tag-library", "testdata/tags", "-ref", "testdata/ref", "testdata/a.1.fasta"}, &bytes.Buffer{}, &buffer, os.Stderr)
18 c.Assert(exited, check.Equals, 0)
19 var output bytes.Buffer
20 exited = (&exportNumpy{}).RunCommand("export-numpy", []string{"-local=true"}, &buffer, &output, os.Stderr)
21 c.Check(exited, check.Equals, 0)
22 npy, err := gonpy.NewReader(&output)
23 c.Assert(err, check.IsNil)
24 variants, err := npy.GetUint16()
25 c.Assert(err, check.IsNil)
26 for i := 0; i < 4; i += 2 {
28 c.Check(variants[i+1], check.Equals, uint16(2), check.Commentf("i=%d, v=%v", i, variants))
30 c.Check(variants[i], check.Equals, uint16(2), check.Commentf("i=%d, v=%v", i, variants))
33 for i := 4; i < 9; i += 2 {
34 c.Check(variants[i], check.Equals, uint16(1), check.Commentf("i=%d, v=%v", i, variants))
38 func sortUints(variants []uint16) {
39 for i := 0; i < len(variants); i += 2 {
40 if variants[i] > variants[i+1] {
41 for j := 0; j < len(variants); j++ {
42 variants[j], variants[j+1] = variants[j+1], variants[j]
49 func (s *exportSuite) TestOnehot(c *check.C) {
50 for _, trial := range []struct {
56 {2, []uint16{1, 1, 1, 1}, 2, []uint16{1, 1, 1, 1}},
57 {2, []uint16{1, 1, 1, 2}, 3, []uint16{1, 1, 0, 1, 0, 1}},
59 // 2nd column => 3 one-hot columns
60 // 4th column => 0 one-hot columns
72 out, outcols := recodeOnehot(trial.in, trial.incols)
73 c.Check(out, check.DeepEquals, trial.out)
74 c.Check(outcols, check.Equals, trial.outcols)