From 3bee3a9473f64b1620a863bae8c3e0f5923b077b Mon Sep 17 00:00:00 2001 From: Chad Laing Date: Fri, 16 Dec 2016 16:04:23 -0700 Subject: [PATCH] Updated tests. --- app/Main.hs | 16 +++-- feht.cabal | 7 +- src/Table.hs | 1 - stack.yaml | 3 +- test/FETSpec.hs | 172 ------------------------------------------------ test/Spec.hs | 86 +++++++++++++++++++++++- 6 files changed, 100 insertions(+), 185 deletions(-) delete mode 100644 test/FETSpec.hs diff --git a/app/Main.hs b/app/Main.hs index 2c1500f..bcd89b0 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -14,7 +14,7 @@ import Data.List import Data.Maybe import Data.String import Prelude (error) -import System.Console.CmdArgs +import System.Console.CmdArgs.Implicit import System.IO import Table import Text.Show @@ -35,8 +35,8 @@ data UserInput = UserInput --note, to use a tab character, one needs to enter a literal tab on the command --line. Eg. delimiter=" " --do this via Ctrl-V -userInput :: Mode (CmdArgs UserInput) -userInput = cmdArgsMode UserInput +feht :: UserInput +feht = UserInput {info = def &= help "File of genome metadata information" ,one = "allbut" &= help "Name and list of meta values for group one" ,two = "allbut" &= help "Name and list of meta values for group two" @@ -44,12 +44,17 @@ userInput = cmdArgsMode UserInput ,mode = def &= help "mode of program, either 'binary', or 'snp' " ,delimiter = "\t" &= help "Delimiter used for info and data files" ,mtc = "Bonferroni" &= help "Multiple testing correction, 'bonferroni', 'none'" - } + } &= + program "feht" &= + summary "Predictive marker discovery for groups: binary data, genomic data (single nucleotide variants), and arbitrary character data." &= + details ["feht takes a table of character data, and a file of metadata, and produces markers that are predictive of groups", "", " ./feht --info=data/metadata.txt --datafile=data/data.tab --mode='snp' > output.txt"] + main :: IO () main = do - userArgs <- cmdArgsRun userInput + userArgs <- cmdArgs feht + userArgs <- cmdArgs feht let onexs = words $ one userArgs let twoxs = words $ two userArgs let groupOneCategory = MetaCategory $ BS.pack $ head onexs @@ -90,7 +95,6 @@ main = do let geneVectorMap = getGeneVectorMap delim finalGenomeData let cl = getComparisonList metadataTable (groupOneCategory, groupOneValues) (groupTwoCategory, groupTwoValues) - --print cl let compList = fmap (calculateFetFromComparison geneVectorMap) cl diff --git a/feht.cabal b/feht.cabal index c29201e..aa8bbb8 100644 --- a/feht.cabal +++ b/feht.cabal @@ -16,20 +16,20 @@ cabal-version: >=1.10 library hs-source-dirs: src exposed-modules: FET, Comparison, Table, StorableByteString - build-depends: base >= 4.7 && < 5 + build-depends: base , bytestring , hashable , unordered-containers , vector , statistics - , time , safe + , QuickCheck default-language: Haskell2010 executable feht hs-source-dirs: app main-is: Main.hs - ghc-options: -threaded -rtsopts -with-rtsopts=-N -O2 -static -optl-static -optl-pthread + ghc-options: -threaded -optl-pthread -optl-static -fPIC -optc-Os build-depends: base , bytestring , cmdargs @@ -46,6 +46,7 @@ test-suite feht-test , QuickCheck , feht , bytestring + , ieee754 ghc-options: -threaded -rtsopts -with-rtsopts=-N default-language: Haskell2010 diff --git a/src/Table.hs b/src/Table.hs index 9f092d0..5ea14be 100644 --- a/src/Table.hs +++ b/src/Table.hs @@ -18,7 +18,6 @@ import Data.List (zip, (++)) import Data.Maybe import Data.Ord import Data.String -import qualified Data.Time.Calendar as C import qualified Data.Vector.Unboxed as V import GHC.Generics (Generic) import Prelude (Integer, error, undefined, (+)) diff --git a/stack.yaml b/stack.yaml index 60f223b..5499101 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,11 +1,10 @@ # For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md # Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) -resolver: lts-6.5 +resolver: lts-7.13 # Local packages, usually specified by relative directory name packages: -- '.' # Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) extra-deps: [] diff --git a/test/FETSpec.hs b/test/FETSpec.hs deleted file mode 100644 index f1c93ce..0000000 --- a/test/FETSpec.hs +++ /dev/null @@ -1,172 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module FETSpec where - -import Test.Hspec -import Test.QuickCheck -import Control.Exception (evaluate) -import FET -import qualified Data.ByteString.Lazy.Char8 as BS - - -main :: IO () -main = hspec $ do - describe "FET of two by two matrix" $ do - it "Two tail value of matrix of 2, 7 | 5, 3" $ - fet (FETName "two-tail test 1") - (GroupOneA 2) - (GroupOneB 7) - (GroupTwoA 5) - (GroupTwoB 3) - TwoTail - `shouldBe` - FETResult{groupOneA = 2 - ,groupOneB = 7 - ,groupTwoA = 5 - ,groupTwoB = 3 - ,pvalue = 0.153434800493624 - ,fetName = "two-tail test 1"} - - - - it "One tail value of matrix of 2, 7 | 5, 3" $ - fet (FETName "two-tail test 1") - (GroupOneA 2) - (GroupOneB 7) - (GroupTwoA 5) - (GroupTwoB 3) - OneTail - `shouldBe` - FETResult{groupOneA = 2 - ,groupOneB = 7 - ,groupTwoA = 5 - ,groupTwoB = 3 - ,pvalue = 0.11703002879473468 - ,fetName = "two-tail test 1"} - - - it "Two tail value of matrix of 12, 17 | 15, 13" $ - fet (FETName "two-tail test 1") - (GroupOneA 12) - (GroupOneB 17) - (GroupTwoA 15) - (GroupTwoB 13) - TwoTail - `shouldBe` - FETResult{groupOneA = 12 - ,groupOneB = 17 - ,groupTwoA = 15 - ,groupTwoB = 13 - ,pvalue = 0.4308539609661818 - ,fetName = "two-tail test 1"} - - - - it "One tail value of matrix of 12, 17 | 15, 13" $ - fet (FETName "two-tail test 1") - (GroupOneA 12) - (GroupOneB 17) - (GroupTwoA 15) - (GroupTwoB 13) - OneTail - `shouldBe` - FETResult{groupOneA = 12 - ,groupOneB = 17 - ,groupTwoA = 15 - ,groupTwoB = 13 - ,pvalue = 0.25601654909757166 - ,fetName = "two-tail test 1"} - - it "Two tail value of matrix of 129, 173 | 152, 138" $ - fet (FETName "two-tail test 1") - (GroupOneA 129) - (GroupOneB 173) - (GroupTwoA 152) - (GroupTwoB 138) - TwoTail - `shouldBe` - FETResult{groupOneA = 129 - ,groupOneB = 173 - ,groupTwoA = 152 - ,groupTwoB = 138 - ,pvalue = 2.1126884355092402e-2 - ,fetName = "two-tail test 1"} - - - - it "One tail value of matrix of 129, 173 | 152, 138" $ - fet (FETName "two-tail test 1") - (GroupOneA 129) - (GroupOneB 173) - (GroupTwoA 152) - (GroupTwoB 138) - OneTail - `shouldBe` - FETResult{groupOneA = 129 - ,groupOneB = 173 - ,groupTwoA = 152 - ,groupTwoB = 138 - ,pvalue = 1.1267280239712145e-2 - ,fetName = "two-tail test 1"} - - - it "Two tail ChiSquare of matrix of 222, 211 | 444, 555" $ - fet (FETName "two-tail test 1") - (GroupOneA 222) - (GroupOneB 211) - (GroupTwoA 444) - (GroupTwoB 555) - TwoTail - `shouldBe` - FETResult{groupOneA = 222 - ,groupOneB = 211 - ,groupTwoA = 444 - ,groupTwoB = 555 - ,pvalue = 1.7384585693541843e-2 - ,fetName = "two-tail test 1"} - - it "One tail ChiSquare of matrix of 222, 211 | 444, 555" $ - fet (FETName "two-tail test 1") - (GroupOneA 222) - (GroupOneB 211) - (GroupTwoA 444) - (GroupTwoB 555) - OneTail - `shouldBe` - FETResult{groupOneA = 222 - ,groupOneB = 211 - ,groupTwoA = 444 - ,groupTwoB = 555 - ,pvalue = 8.692292846770922e-3 - ,fetName = "two-tail test 1"} - - - it "Two tail ChiSquare of matrix of 99222, 98211 | 77444, 74555" $ - fet (FETName "two-tail test 1") - (GroupOneA 99222) - (GroupOneB 98211) - (GroupTwoA 77444) - (GroupTwoB 74555) - TwoTail - `shouldBe` - FETResult{groupOneA = 99222 - ,groupOneB = 98211 - ,groupTwoA = 77444 - ,groupTwoB = 74555 - ,pvalue = 4.7092508444146475e-5 - ,fetName = "two-tail test 1"} - - it "One tail ChiSquare of matrix of 100998, 100555 | 501, 555" $ - fet (FETName "two-tail test 1") - (GroupOneA 100998) - (GroupOneB 100555) - (GroupTwoA 501) - (GroupTwoB 555) - OneTail - `shouldBe` - FETResult{groupOneA = 100998 - ,groupOneB = 100555 - ,groupTwoA = 501 - ,groupTwoB = 555 - ,pvalue = 4.193675848378964e-2 - ,fetName = "two-tail test 1"} \ No newline at end of file diff --git a/test/Spec.hs b/test/Spec.hs index 7ba3918..a1d4952 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -1,7 +1,91 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Main where + import Test.Hspec import Test.QuickCheck import Control.Exception (evaluate) -import FETSpec +import FET +import qualified Data.ByteString.Lazy.Char8 as BS +import Data.AEq +import Numeric.IEEE + + +main :: IO () +main = hspec $ + describe "Verify p-values of FET tests" $ do + it "matrix of 2 7 5 3 two tail" $ do + let fr = fet (FETName "two tail test") + (GroupOneA 2) + (GroupOneB 7) + (GroupTwoA 5) + (GroupTwoB 3) + TwoTail + let aeq = pvalue fr ~== (0.153434800493624::Double) + aeq `shouldBe` True + it "matrix of 2 7 5 3 one tail" $ do + let fr = fet (FETName "one tail test") + (GroupOneA 2) + (GroupOneB 7) + (GroupTwoA 5) + (GroupTwoB 3) + OneTail + let aeq = pvalue fr ~== (0.11703002879473468::Double) + aeq `shouldBe` True + it "matrix of 129 173 152 138 two tail" $ do + let fr = fet (FETName "two tail") + (GroupOneA 129) + (GroupOneB 173) + (GroupTwoA 152) + (GroupTwoB 138) + TwoTail + let aeq = pvalue fr ~== (2.1126884355092402e-2::Double) + aeq `shouldBe` True + it "matrix of 129 173 152 138 one tail" $ do + let fr = fet (FETName "one tail") + (GroupOneA 129) + (GroupOneB 173) + (GroupTwoA 152) + (GroupTwoB 138) + OneTail + let aeq = pvalue fr ~== (1.1267280239712145e-2::Double) + aeq `shouldBe` True + it "matrix of 222 211 444 555 two tail (ChiSquared)" $ do + let fr = fet (FETName "two tail Chi Squared") + (GroupOneA 222) + (GroupOneB 211) + (GroupTwoA 444) + (GroupTwoB 555) + TwoTail + let aeq = pvalue fr ~== (1.7384585693541843e-2::Double) + aeq `shouldBe` True + it "matrix of 222 211 444 555 one tail (ChiSquared)" $ do + let fr = fet (FETName "one tail ChiSquared") + (GroupOneA 222) + (GroupOneB 211) + (GroupTwoA 444) + (GroupTwoB 555) + OneTail + let aeq = pvalue fr ~== (8.692292846770922e-3::Double) + aeq `shouldBe` True + it "matrix of 99222 98211 77444 74555 two tail (ChiSquared)" $ do + let fr = fet (FETName "two tail Chi-Squared") + (GroupOneA 99222) + (GroupOneB 98211) + (GroupTwoA 77444) + (GroupTwoB 74555) + TwoTail + let aeq = pvalue fr ~== (4.7092508444146475e-5::Double) + aeq `shouldBe` True + it "matrix of 100998 100555 501 555 one tail (ChiSquared)" $ do + let fr = fet (FETName "one tail Chi-Squared") + (GroupOneA 100998) + (GroupOneB 100555) + (GroupTwoA 501) + (GroupTwoB 555) + OneTail + let aeq = pvalue fr ~== (4.193675848378964e-2::Double) + aeq `shouldBe` True