Fix log message.
[lightning.git] / slice_test.go
index 0dd93d1f729bbac6233a2a598a3cad97f1b2de1a..47c43e1cee8b8a8f9d20663333fb8a18a65df933 100644 (file)
@@ -81,6 +81,24 @@ func (s *sliceSuite) TestImportAndSlice(c *check.C) {
        out, _ := exec.Command("find", slicedir, "-ls").CombinedOutput()
        c.Logf("%s", out)
 
+       c.Log("=== dump ===")
+       {
+               dumpdir := c.MkDir()
+               exited = (&dump{}).RunCommand("dump", []string{
+                       "-local=true",
+                       "-tags=4,6,7",
+                       "-input-dir=" + slicedir,
+                       "-output-dir=" + dumpdir,
+               }, nil, os.Stderr, os.Stderr)
+               c.Check(exited, check.Equals, 0)
+               out, _ := exec.Command("find", dumpdir, "-ls").CombinedOutput()
+               c.Logf("%s", out)
+               dumped, err := ioutil.ReadFile(dumpdir + "/variants.csv")
+               c.Assert(err, check.IsNil)
+               c.Logf("%s", dumped)
+               c.Check(string(dumped), check.Matches, `(?ms).*\n6,1,1,chr2,349,AAAACTG.*`)
+       }
+
        c.Log("=== slice-numpy ===")
        {
                npydir := c.MkDir()
@@ -196,7 +214,9 @@ func (s *sliceSuite) TestImportAndSlice(c *check.C) {
                c.Assert(err, check.IsNil)
                c.Check(npy.Shape, check.DeepEquals, []int{4, 4})
                variants, err := npy.GetInt16()
-               c.Check(variants, check.DeepEquals, []int16{2, 1, 3, 1, -1, -1, 4, 2, 2, 1, 3, 1, -1, -1, 4, 2})
+               if c.Check(err, check.IsNil) {
+                       c.Check(variants, check.DeepEquals, []int16{2, 1, 3, 1, -1, -1, 4, 2, 2, 1, 3, 1, -1, -1, 4, 2})
+               }
 
                annotations, err := ioutil.ReadFile(npydir + "/matrix.annotations.csv")
                c.Assert(err, check.IsNil)
@@ -212,14 +232,20 @@ func (s *sliceSuite) TestImportAndSlice(c *check.C) {
 
        c.Log("=== slice-numpy + chunked hgvs matrix ===")
        {
-               err = ioutil.WriteFile(tmpdir+"/cases.txt", []byte("pipeline1/input1\npipeline1dup/input1\n"), 0600)
+               err = ioutil.WriteFile(tmpdir+"/casecontrol.tsv", []byte(`SampleID      CC
+pipeline1/input1       1
+pipeline1/input2       0
+pipeline1dup/input1    1
+pipeline1dup/input2    0
+`), 0600)
                c.Assert(err, check.IsNil)
                npydir := c.MkDir()
                exited := (&sliceNumpy{}).RunCommand("slice-numpy", []string{
                        "-local=true",
                        "-chunked-hgvs-matrix=true",
-                       "-chi2-cases-file=" + tmpdir + "/cases.txt",
-                       "-chi2-p-value=0.05",
+                       "-chi2-case-control-file=" + tmpdir + "/casecontrol.tsv",
+                       "-chi2-case-control-column=CC",
+                       "-chi2-p-value=0.5",
                        "-min-coverage=0.75",
                        "-input-dir=" + slicedir,
                        "-output-dir=" + npydir,
@@ -235,4 +261,90 @@ func (s *sliceSuite) TestImportAndSlice(c *check.C) {
 2,chr2:g.472G>A
 `)
        }
+
+       c.Log("=== slice-numpy + onehotChunked ===")
+       {
+               err = ioutil.WriteFile(tmpdir+"/casecontrol.tsv", []byte(`SampleID      CC
+pipeline1/input1       1
+pipeline1/input2       0
+pipeline1dup/input1    1
+pipeline1dup/input2    0
+`), 0600)
+               c.Assert(err, check.IsNil)
+               npydir := c.MkDir()
+               exited := (&sliceNumpy{}).RunCommand("slice-numpy", []string{
+                       "-local=true",
+                       "-chunked-onehot=true",
+                       "-chi2-case-control-file=" + tmpdir + "/casecontrol.tsv",
+                       "-chi2-case-control-column=CC",
+                       "-chi2-p-value=0.5",
+                       "-min-coverage=0.75",
+                       "-input-dir=" + slicedir,
+                       "-output-dir=" + npydir,
+               }, nil, os.Stderr, os.Stderr)
+               c.Check(exited, check.Equals, 0)
+               out, _ := exec.Command("find", npydir, "-ls").CombinedOutput()
+               c.Logf("%s", out)
+
+               f, err := os.Open(npydir + "/onehot.0002.npy")
+               c.Assert(err, check.IsNil)
+               defer f.Close()
+               npy, err := gonpy.NewReader(f)
+               c.Assert(err, check.IsNil)
+               c.Check(npy.Shape, check.DeepEquals, []int{4, 6})
+               onehot, err := npy.GetInt8()
+               if c.Check(err, check.IsNil) {
+                       for r := 0; r < npy.Shape[0]; r++ {
+                               c.Logf("%v", onehot[r*npy.Shape[1]:(r+1)*npy.Shape[1]])
+                       }
+                       c.Check(onehot, check.DeepEquals, []int8{
+                               0, 0, 0, 1, 0, 0, // input1
+                               0, 1, 0, 0, 0, 1, // input2
+                               0, 0, 0, 1, 0, 0, // dup/input1
+                               0, 1, 0, 0, 0, 1, // dup/input2
+                       })
+               }
+       }
+
+       c.Log("=== slice-numpy + onehotSingle ===")
+       {
+               err = ioutil.WriteFile(tmpdir+"/casecontrol.tsv", []byte(`SampleID      CC
+pipeline1/input1       1
+pipeline1/input2       0
+pipeline1dup/input1    1
+pipeline1dup/input2    0
+`), 0600)
+               c.Assert(err, check.IsNil)
+               npydir := c.MkDir()
+               exited := (&sliceNumpy{}).RunCommand("slice-numpy", []string{
+                       "-local=true",
+                       "-single-onehot=true",
+                       "-chi2-case-control-file=" + tmpdir + "/casecontrol.tsv",
+                       "-chi2-case-control-column=CC",
+                       "-chi2-p-value=0.5",
+                       "-min-coverage=0.75",
+                       "-input-dir=" + slicedir,
+                       "-output-dir=" + npydir,
+               }, nil, os.Stderr, os.Stderr)
+               c.Check(exited, check.Equals, 0)
+               out, _ := exec.Command("find", npydir, "-ls").CombinedOutput()
+               c.Logf("%s", out)
+
+               f, err := os.Open(npydir + "/onehot.npy")
+               c.Assert(err, check.IsNil)
+               defer f.Close()
+               npy, err := gonpy.NewReader(f)
+               c.Assert(err, check.IsNil)
+               c.Check(npy.Shape, check.DeepEquals, []int{2, 16})
+               onehot, err := npy.GetUint32()
+               if c.Check(err, check.IsNil) {
+                       for r := 0; r < npy.Shape[0]; r++ {
+                               c.Logf("%v", onehot[r*npy.Shape[1]:(r+1)*npy.Shape[1]])
+                       }
+                       c.Check(onehot, check.DeepEquals, []uint32{
+                               0, 2, 1, 3, 0, 2, 1, 3, 0, 2, 1, 3, 0, 2, 0, 2,
+                               1, 1, 2, 2, 5, 5, 7, 7, 9, 9, 11, 11, 13, 13, 15, 15,
+                       })
+               }
+       }
 }