Skip to content

Commit

Permalink
#5: Add function to create significance matrices from TMEAResults
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Jun 21, 2021
1 parent 0e90e7e commit e6df788
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/TMEA.Dash/TMEA.Dash.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</ItemGroup>

<ItemGroup>
<Content Include="TestFiles\OntologyMap.txt" />
<EmbeddedResource Remove="TestFiles\**" />
</ItemGroup>

<ItemGroup>
Expand Down
73 changes: 62 additions & 11 deletions src/TMEA/Frames.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module Frames =

open Deedle

let private optDefFloat (f:float opt)=
let internal optDefFloat (f:float opt)=
if f.HasValue then f.Value else -1.

let private optDefInt (f:int opt)=
let internal optDefInt (f:int opt)=
if f.HasValue then f.Value else 0

let createTMEACharacterizationTable minBinSize (termNameTransformation: string -> string) (tmeaCharacterizations:TMEACharacterization []) : Frame<(string*(string*int)),string> =
let internal createTMEACharacterizationTable minBinSize (termNameTransformation: string -> string) (tmeaCharacterizations:TMEACharacterization []) : Frame<(string*(string*int)),string> =
tmeaCharacterizations
|> Array.mapi (fun i desc ->
let negFrame: Frame<string,string> =
Expand Down Expand Up @@ -105,16 +105,67 @@ module Frames =

type TMEAResult with

static member toTMEACharacterizationFrame(tmeaRes:TMEAResult) =
tmeaRes.Characterizations |> createTMEACharacterizationTable 0 id

static member toTMEACharacterizationFrame(minBinSize:int,tmeaRes:TMEAResult) =
tmeaRes.Characterizations |> createTMEACharacterizationTable minBinSize id
static member toTMEACharacterizationFrame(?MinBinSize:int, ?TermNameTransformation:string->string) =

let minBinSize = defaultArg MinBinSize 0
let termNameTransformation = defaultArg TermNameTransformation id

fun (tmeaRes: TMEAResult) ->
tmeaRes.Characterizations |> createTMEACharacterizationTable minBinSize termNameTransformation

static member toTMEACharacterizationFrame (minBinSize:int,termNameTransformation:string->string,tmeaRes:TMEAResult) =
tmeaRes.Characterizations |> createTMEACharacterizationTable minBinSize termNameTransformation

static member toSignificanceMatrixFrame : unit = raise (System.NotImplementedException())
static member toSignificanceMatrixFrame (?UseBenjaminiHochberg:bool, ?Threshold:float, ?TermNameTransformation:string->string) =

let useBenjaminiHochberg = defaultArg UseBenjaminiHochberg false
let threshold = defaultArg Threshold 0.05
let termNameTransformation = defaultArg TermNameTransformation id

fun (tmeaRes:TMEAResult) ->
tmeaRes.Characterizations
|> Array.mapi (fun cI c ->
let pos =
c.PositiveDescriptor
|> Array.map (fun d ->
d.OntologyTerm => d.PValue
)

let neg =
c.PositiveDescriptor
|> Array.map (fun d ->
d.OntologyTerm => d.PValue
)

let keys, pos' =
if useBenjaminiHochberg then
neg
|> FSharp.Stats.Testing.MultipleTesting.benjaminiHochbergFDRBy id
|> Array.ofList
|> Array.unzip
else
neg
|> Array.unzip

let keys, neg' =
if useBenjaminiHochberg then
neg
|> FSharp.Stats.Testing.MultipleTesting.benjaminiHochbergFDRBy id
|> Array.ofList
|> Array.unzip
else
neg
|> Array.unzip


$"C_{cI}" => (
Array.map2 (fun p n -> if p < n then p else n) pos' neg'
|> Array.map (fun lowestPValue -> if lowestPValue < threshold then 1 else 0)
|> Array.zip keys
|> series
)
)
|> frame
|> Frame.fillMissingWith 0
|> Frame.mapRowKeys (fun (name) -> (termNameTransformation name) => name)

static member toConstraintsFrame : unit = raise (System.NotImplementedException())

Expand Down
10 changes: 8 additions & 2 deletions src/TMEA/Playground.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ open Plotly.NET

let characterizationFrame =
testTmeaRes
|> TMEAResult.toTMEACharacterizationFrame
|> TMEAResult.toTMEACharacterizationFrame()

characterizationFrame.Print()

Expand All @@ -79,7 +79,7 @@ testTmeaRes
|> TMEAResult.plotConstraintPotentialTimecourses(OmitBaselineState=true,InvertConstraints=[|1;2;3|], ConstraintCutoff=3)

testTmeaRes
|> TMEAResult.plotPotentialHeatmap(ConstraintCutoff=3,InvertConstraints=[|2|])
|> TMEAResult.plotConstraintPotentialHeatmap(ConstraintCutoff=3,InvertConstraints=[|2|])

testTmeaRes
|> TMEAResult.plotFreeEnergyLandscape()
Expand All @@ -94,6 +94,12 @@ testTmeaRes
|> TMEAResult.plotFASWeightDistribution("signalling.light",[1;2;3],true,0.05)



testTmeaRes
|> TMEAResult.toSignificanceMatrixFrame()
|> fun f -> f.Print()


//readDataFrame
// "TranscriptIdentifier"
// "\t"
Expand Down

0 comments on commit e6df788

Please sign in to comment.