Skip to content
Snippets Groups Projects
Commit 8aaa8665 authored by Dominik Brilhaus's avatar Dominik Brilhaus
Browse files

try fix fsharp isa read

parent 8a4c41b4
No related branches found
No related tags found
1 merge request!4fix docker
// Pull out the full ISA process sequence (incl. all metadata) leading to the first Raw Data Node // Pull out the full ISA process sequence (incl. all metadata) leading to the first Raw Data Node
// Dependencies // Dependencies
#r "nuget: ARCtrl.NET, 2.0.2" #r "nuget: ARCtrl.NET"
#r "nuget: ARCtrl.QueryModel, 2.0.2" #r "nuget: ARCtrl.QueryModel"
open System.IO open System.IO
open ARCtrl.NET open ARCtrl.NET
open ARCtrl open ARCtrl
open ARCtrl.QueryModel open ARCtrl.QueryModel
open ARCtrl.Helper
// input parameters open FsSpreadsheet
open FsSpreadsheet.Net
let args : string array = fsi.CommandLineArgs |> Array.tail
let arcPath = args.[0] // input parameters
let assayName = args.[1]
let startingNodeNum = args.[2] |> int // let args : string array = fsi.CommandLineArgs |> Array.tail
let outName = args.[3] // let arcPath = args.[0]
// let assayName = args.[1]
// let startingNodeNum = args.[2] |> int
// test parameters // let outName = args.[3]
let source = __SOURCE_DIRECTORY__
let arcPath = Path.Combine(source, "../../")
let assayName = "Talinum_RNASeq_minimal" type ArcTables with
let startingNodeNum = 1
let outName = "rnaseq-samples" member this.IgnoreShitty() : ArcTables =
this.Tables
|> ResizeArray.filter (fun t ->
// Load ARC t.TryGetInputColumn().IsSome && t.TryGetOutputColumn().IsSome
)
let arc = ARC.load(arcPath) |> ArcTables
let inv = arc.ISA.Value
// test parameters
// Load first data node let source = __SOURCE_DIRECTORY__
let arcPath = Path.Combine(source, "../../")
let firstData = inv.GetAssay(assayName).FirstData let assayName = "Talinum_RNASeq_minimal"
let startingNodeNum = 1
// Create headers for output table let outName = "rnaseq-samples"
let headers = [
CompositeHeader.Input IOType.Sample // Load ARC
for v in inv.ArcTables.ValuesOf firstData.[0] do
if v.IsCharacteristicValue then let clean (a : ARC) =
CompositeHeader.Characteristic v.Category a.ISA.Value.Assays |> Seq.iter (fun a ->
elif v.IsParameterValue then a.Tables
CompositeHeader.Parameter v.Category |> Seq.toArray
elif v.IsFactorValue then |> Seq.iter (fun t ->
CompositeHeader.Factor v.Category if not (t.TryGetInputColumn().IsSome && t.TryGetOutputColumn().IsSome) then
elif v.IsComponent then a.RemoveTable t.Name
CompositeHeader.Component v.Category
else failwithf "what the f is %O" v )
CompositeHeader.Output IOType.Data )
] a.ISA.Value.Studies |> Seq.iter (fun s ->
s.Tables
// Create rows |> Seq.toArray
|> Seq.iter (fun t ->
let getRow (d: QNode) = if not (t.TryGetInputColumn().IsSome && t.TryGetOutputColumn().IsSome) then
[| s.RemoveTable t.Name
CompositeCell.createFreeText (inv.ArcTables.SamplesOf d).[startingNodeNum].Name )
for v in inv.ArcTables.ValuesOf d do )
if v.HasUnit then a
CompositeCell.Unitized(v.ValueText, v.Unit)
else let arc = ARC.load(arcPath) |> clean
CompositeCell.Term(v.Value.AsOntology())
CompositeCell.FreeText d.Name let inv = arc.ISA.Value
|] // Load first data node
// Combine into table let firstData = inv.GetAssay(assayName).FirstData
let t = ArcTable.init "FullTable" // Create headers for output table
t.Headers <- ResizeArray headers let headers = [
CompositeHeader.Input IOType.Sample
for d in firstData do for v in inv.ArcTables.IgnoreShitty().ValuesOf firstData.[0].Name do
t.AddRow (getRow d) if v.IsCharacteristicValue then
CompositeHeader.Characteristic v.Category
// Small detour via workbook elif v.IsParameterValue then
let ws = Spreadsheet.ArcTable.toFsWorksheet t CompositeHeader.Parameter v.Category
elif v.IsFactorValue then
let wb = new FsSpreadsheet.FsWorkbook() CompositeHeader.Factor v.Category
elif v.IsComponent then
wb.AddWorksheet ws CompositeHeader.Component v.Category
else failwithf "what the f is %O" v
// Write to csv
CompositeHeader.Output IOType.Data
wb.ToCsvFile (outName + ".tsv", Separator = '\t') ]
wb.ToXlsxFile (outName + ".xlsx")
// Create rows
let getRow (d: QNode) =
[|
CompositeCell.createFreeText (inv.ArcTables.SamplesOf d).[startingNodeNum].Name
for v in inv.ArcTables.ValuesOf d do
if v.HasUnit then
CompositeCell.Unitized(v.ValueText, v.Unit)
else
CompositeCell.Term(v.Value.AsOntology())
CompositeCell.FreeText d.Name
|]
// Combine into table
let t = ArcTable.init "FullTable"
t.Headers <- ResizeArray headers
for d in firstData do
t.AddRow (getRow d)
// Small detour via workbook
let ws = Spreadsheet.ArcTable.toFsWorksheet None t
let wb = new FsSpreadsheet.FsWorkbook()
wb.AddWorksheet ws
// Write to csv
// wb.To (outName + ".tsv", Separator = '\t')
wb.ToXlsxFile (outName + ".xlsx")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment