Fix GLM p-value calculation when -case-control-only=true.
authorTom Clegg <tom@curii.com>
Fri, 13 Jan 2023 20:05:27 +0000 (15:05 -0500)
committerTom Clegg <tom@curii.com>
Fri, 13 Jan 2023 20:05:27 +0000 (15:05 -0500)
refs #19566

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

slicenumpy.go

index a22d662b7493608bca97eb3fdc89bb401eea7502..390649259aeb75f6cc5a4adaa1bbaeeecc3199fd 100644 (file)
@@ -192,21 +192,6 @@ func (cmd *sliceNumpy) run(prog string, args []string, stdin io.Reader, stdout,
                if err != nil {
                        return err
                }
-               if len(cmd.samples[0].pcaComponents) > 0 {
-                       cmd.pvalue = glmPvalueFunc(cmd.samples, cmd.pcaComponents)
-                       // Unfortunately, statsmodel/glm lib logs
-                       // stuff to os.Stdout when it panics on an
-                       // unsolvable problem. We recover() from the
-                       // panic in glm.go, but we also need to
-                       // commandeer os.Stdout to avoid producing
-                       // large quantities of logs.
-                       stdoutWas := os.Stdout
-                       defer func() { os.Stdout = stdoutWas }()
-                       os.Stdout, err = os.Open(os.DevNull)
-                       if err != nil {
-                               return err
-                       }
-               }
        } else if *caseControlOnly {
                return fmt.Errorf("-case-control-only does not make sense without -samples")
        }
@@ -316,6 +301,21 @@ func (cmd *sliceNumpy) run(prog string, args []string, stdin io.Reader, stdout,
                cmd.minCoverage = int(math.Ceil(cmd.filter.MinCoverage * float64(len(cmd.cgnames))))
        }
 
+       if len(cmd.samples[0].pcaComponents) > 0 {
+               cmd.pvalue = glmPvalueFunc(cmd.samples, cmd.pcaComponents)
+               // Unfortunately, statsmodel/glm lib logs stuff to
+               // os.Stdout when it panics on an unsolvable
+               // problem. We recover() from the panic in glm.go, but
+               // we also need to commandeer os.Stdout to avoid
+               // producing large quantities of logs.
+               stdoutWas := os.Stdout
+               defer func() { os.Stdout = stdoutWas }()
+               os.Stdout, err = os.Open(os.DevNull)
+               if err != nil {
+                       return err
+               }
+       }
+
        // cgnamemap[name]==true for samples that we are including in
        // output
        cgnamemap := map[string]bool{}