From 4a911410399650f2bf9582cf457fa2760846d034 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Fri, 29 Apr 2022 14:57:44 -0400 Subject: [PATCH] Add -log10(pvalue) row to onehot-columns.npy output from slicenumpy. closes #19014 Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- slice_test.go | 20 ++++++++++++++++++++ slicenumpy.go | 5 +++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/slice_test.go b/slice_test.go index 74e0e34519..8af51614ae 100644 --- a/slice_test.go +++ b/slice_test.go @@ -352,6 +352,26 @@ pipeline1dup/input2 0 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, }) } + + f, err = os.Open(npydir + "/onehot-columns.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{8, 5}) + onehotcols, err := npy.GetInt32() + if c.Check(err, check.IsNil) { + for r := 0; r < npy.Shape[0]; r++ { + c.Logf("%v", onehotcols[r*npy.Shape[1]:(r+1)*npy.Shape[1]]) + } + c.Check(onehotcols, check.DeepEquals, []int32{ + 0, 0, 1, 4, 4, 4, 6, 6, + 2, 3, 2, 2, 3, 4, 2, 3, + 0, 1, 0, 0, 0, 0, 0, 0, + 157299, 157299, 157299, 157299, 157299, 157299, 157299, 157299, + 803273, 803273, 803273, 803273, 803273, 803273, 803273, 803273, + }) + } } } diff --git a/slicenumpy.go b/slicenumpy.go index a2e03f4944..db4b0d367b 100644 --- a/slicenumpy.go +++ b/slicenumpy.go @@ -1001,7 +1001,7 @@ func (cmd *sliceNumpy) RunCommand(prog string, args []string, stdin io.Reader, s return 1 } fnm = fmt.Sprintf("%s/onehot-columns.npy", *outputDir) - err = writeNumpyInt32(fnm, onehotXref2int32(xrefs), 4, len(xrefs)) + err = writeNumpyInt32(fnm, onehotXref2int32(xrefs), 5, len(xrefs)) if err != nil { return 1 } @@ -1355,7 +1355,7 @@ func bool2int8(in []bool) []int8 { // P-value row contains 1000000x actual p-value. func onehotXref2int32(xrefs []onehotXref) []int32 { xcols := len(xrefs) - xdata := make([]int32, 4*xcols) + xdata := make([]int32, 5*xcols) for i, xref := range xrefs { xdata[i] = int32(xref.tag) xdata[xcols+i] = int32(xref.variant) @@ -1363,6 +1363,7 @@ func onehotXref2int32(xrefs []onehotXref) []int32 { xdata[xcols*2+i] = 1 } xdata[xcols*3+i] = int32(xref.pvalue * 1000000) + xdata[xcols*4+i] = int32(-math.Log10(xref.pvalue) * 1000000) } return xdata } -- 2.30.2