Skip to content

Export annotation Tables from ARCs

This guide demonstrates how to use ARCtrl to export annotation tables from an ARC into individual json files.

Some users want to quickly export studies, assays or individual annotation tables into easily shareable and reusable json files. This might help to establish SOPs from a lab-typical ARC.

To follow this example you can download the public ARC Facultative-CAM-in-Talinum and store it parallel to the script.

First, load the required libraries and load the local ARC into an ArcInvestigation object for easy access.

export-tables.fsx
#r "nuget: ARCtrl"
#r "nuget: ARCtrl.QueryModel"
open ARCtrl
open ARCtrl.QueryModel
open ARCtrl.Json
open System.IO
// Path to a local ARC
let arcPath = @"Facultative-CAM-in-Talinum"
// Load local ARC from scaffold
let arc = ARC.load arcPath
// Store the ArcInvestigation object for easier access
let investigation = arc.ISA.Value

We can simply create a function exportStudyToJson, which takes an ArcInvestigation object and a selected study identifier as inputs and writes the json (of type ARCtrl json) to a file named by the study identifier with the extension “.arctrl.json”. In this example, we select “TalinumSamples-STRI” from the available studies.

export-tables.fsx
let exportStudyToJson (a: ArcInvestigation) (studyIdentifier : string) =
a.GetStudy studyIdentifier
|> ArcStudy.toJsonString 2
|> fun c -> File.WriteAllText(studyIdentifier + ".arctrl.json", c)
// Print all study identifiers
investigation.StudyIdentifiers |> Seq.iter (printfn "%s")
// TalinumGenomeDraft
// TalinumSamples-STRI
// val it: unit = ()
exportStudyToJson investigation "TalinumSamples-STRI"

In the same manner, we can create a function exportAssayToJson, which takes an ArcInvestigation object and a selected assay identifier as inputs and writes the json (of type ARCtrl json) to a file named by the assay identifier with the extension “.arctrl.json”. In this example, we select “RNASeq” from the available assays.

export-tables.fsx
let exportAssayToJson (a: ArcInvestigation) (assayIdentifier : string) =
a.GetAssay assayIdentifier
|> ArcAssay.toJsonString 2
|> fun c -> File.WriteAllText(assayIdentifier + ".arctrl.json", c)
// Print all assay identifiers
investigation.AssayIdentifiers |> Seq.iter (printfn "%s")
// MassHunter_targets
// RNASeq
// GCqTOF_targets
// val it: unit = ()
exportAssayToJson investigation "RNASeq"

Instead of exporting a full study or assay, including all annotation tables and the respective metadata sheet, respectively, you can also export a single annotation table.

export-tables.fsx
let exportArcTableToJson (a: ArcInvestigation) (tableName : string) =
let at = investigation.ArcTables
at.GetTable tableName
|> ArcTable.toJsonString 2
|> fun c -> File.WriteAllText(tableName + ".arctrl.json", c)
// Print all Table Names
investigation.ArcTables.TableNames |> Seq.iter (printfn "%s")
// val it: string list =
// ["TalinumGenomeDraft"; "plant_material"; "mh-quant-results";
// "mh-quant-report"; "rna_extraction"; "illumina"; "metabolite_extraction";
// "gas_chromatography"; "mass_spec"]
exportArcTableToJson investigation "rna_extraction"

You can download the example script to adapt it to your needs.