Skip to content

Commit a995ff8

Browse files
committed
add tests
1 parent 65f3f57 commit a995ff8

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

tests/BioFSharp.Stats.Tests/BioFSharp.Stats.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12+
<Compile Include="OntologyEnrichmentTests.fs" />
1213
<Compile Include="RNASeqTests.fs" />
1314
<Compile Include="Program.fs" />
1415
</ItemGroup>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
namespace BioFSharp.Stats.Tests
2+
3+
open Xunit
4+
open BioFSharp
5+
open BioFSharp.Stats
6+
open OntologyEnrichment
7+
8+
module OntologyEnrichmentTests =
9+
10+
let data = [|
11+
createOntologyItem "id01" "PS.lightreaction.LHCII;protein.degradation.ubiquitin" 1 "description01"
12+
createOntologyItem "id02" "PS.lightreaction.LHCII" 0 "description02"
13+
createOntologyItem "id03" "PS.lightreaction.LHCII" 1 "description03"
14+
createOntologyItem "id04" "PS.lightreaction.LHCII" 0 "description04"
15+
createOntologyItem "id05" "PS.lightreaction.LHCII" 0 "description05"
16+
createOntologyItem "id06" "PS.lightreaction.LHCII" 1 "description06"
17+
createOntologyItem "id07" "PS.lightreaction.LHCII" 0 "description07"
18+
createOntologyItem "id08" "PS.lightreaction.LHCII" 1 "description08"
19+
createOntologyItem "id09" "PS.lightreaction.LHCII" 0 "description09"
20+
createOntologyItem "id10" "PS.lightreaction.LHCII" 1 "description10"
21+
createOntologyItem "id11" "PS.lightreaction.LHCII" 0 "description11" //36
22+
createOntologyItem "id12" "PS.lightreaction" 0 "description12"
23+
createOntologyItem "id13" "PS.lightreaction" 0 "description13"
24+
createOntologyItem "id14" "PS.lightreaction" 0 "description14"
25+
createOntologyItem "id15" "PS.lightreaction" 1 "description15" //8
26+
createOntologyItem "id16" "protein.degradation.ubiquitin" 0 "description16"
27+
createOntologyItem "id17" "protein.degradation.ubiquitin" 1 "description17"
28+
createOntologyItem "id18" "protein.degradation.ubiquitin" 0 "description18"
29+
createOntologyItem "id19" "protein.degradation.ubiquitin" 0 "description19"
30+
createOntologyItem "id20" "protein.degradation.ubiquitin" 1 "description20"
31+
createOntologyItem "id21" "protein.degradation.ubiquitin" 0 "description21" //18
32+
createOntologyItem "id22" "protein.degradation.ubiquitin.e1" 0 "description22"
33+
createOntologyItem "id23" "protein.degradation.ubiquitin.e1" 0 "description23"
34+
createOntologyItem "id24" "protein.degradation.ubiquitin.e1" 0 "description24" //12
35+
createOntologyItem "id25" "protein.synthesis.initiation" 1 "description25"
36+
createOntologyItem "id26" "protein.synthesis.initiation" 0 "description26"
37+
createOntologyItem "id27" "protein.synthesis.initiation" 1 "description27"
38+
createOntologyItem "id28" "protein.synthesis.initiation" 1 "description28"
39+
createOntologyItem "id29" "protein.synthesis.initiation" 1 "description29"
40+
createOntologyItem "id30" "protein.synthesis" 0 "description30" //17
41+
createOntologyItem "id31" "singletest" 1 "description31" //1
42+
|]
43+
44+
let dataSplit =
45+
data
46+
|> Seq.collect (splitMultipleAnnotationsBy ';')
47+
48+
let dataExtended =
49+
expandOntologyTree dataSplit
50+
51+
let enrichmentResult =
52+
calcOverEnrichmentIncludeFDR 1 (Some 0) (Some 0) dataExtended
53+
54+
[<Fact>]
55+
let ``splitOntologyItems`` () =
56+
let actual = dataSplit |> Seq.length
57+
let expected = data.Length + 1 //first one is split into 2, all others remain the same
58+
Assert.Equal<int>(expected, actual)
59+
60+
[<Fact>]
61+
let ``expandOntologyTree`` () =
62+
let actual = dataExtended |> Seq.length
63+
let expected = 92 // 36 + 8 + 18 + 12 + 18
64+
Assert.Equal<int>(expected, actual)
65+
66+
[<Fact>]
67+
let ``ontologyEnrichment`` () =
68+
// per bin one result
69+
let numberOfBins_actual = enrichmentResult |> Seq.length
70+
let numberOfBins_expected = 10
71+
Assert.Equal<int>(numberOfBins_expected, numberOfBins_actual)
72+
let bin1 = enrichmentResult |> Seq.find (fun x -> x.OntologyTerm = "PS.lightreaction.LHCII")
73+
Assert.Equal<int>(11, bin1.NumberInBin)
74+
Assert.Equal<int>(5, bin1.NumberOfDEsInBin)
75+
Assert.Equal<int>(39, bin1.TotalNumberOfDE)
76+
Assert.Equal<int>(92, bin1.TotalUniverse)
77+
Assert.Equal<float>(0.5367813329, System.Math.Round(bin1.PValue, 10)) //https://systems.crump.ucla.edu/hypergeometric/index.php
78+
let testbin =
79+
enrichmentResult |> Seq.find (fun x -> x.OntologyTerm = "singletest")
80+
// test for a singleton bin of which valid p values exist
81+
Assert.Equal<float>(0.4239130435, System.Math.Round(testbin.PValue, 10))

0 commit comments

Comments
 (0)