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.
arc get --nolfs -r https://git.nfdi4plants.org/brilator/Facultative-CAM-in-Talinum.gitGIT_LFS_SKIP_SMUDGE=1 git clone --filter=blob:none https://git.nfdi4plants.org/brilator/Facultative-CAM-in-Talinum.gitFirst, load the required libraries and load the local ARC into an ArcInvestigation object for easy access.
#r "nuget: ARCtrl"#r "nuget: ARCtrl.QueryModel"
open ARCtrlopen ARCtrl.QueryModelopen ARCtrl.Jsonopen 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 accesslet investigation = arc.ISA.Valuefrom arctrl.arc import ARCfrom arctrl.arctrl import JsonController
import json
# Path to a local ARC
arcPath = "Facultative-CAM-in-Talinum"
# Load local ARC from scaffold
arc = ARC.load(arcPath)
# Store the ArcInvestigation object for easier accessinvestigation = arc.ISAWe 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.
// Function to export a selected study to a .json file
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"# Function to export a selected study to a .json file
def exportStudyToJson (arcInvestigation, studyIdentifier): study = arcInvestigation.GetStudy (studyIdentifier) studyJson = JsonController.Study().to_json_string(study, spaces = 2)
with open(studyIdentifier + ".arctrl.json", 'w') as f: f.write(studyJson)
# Print all study identifiers
print (*investigation.StudyIdentifiers, sep='\n')
# TalinumGenomeDraft # TalinumSamples-STRI
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.
// Function to export a selected assay to a .json file
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"# Function to export a selected assay to a .json file
def exportAssayToJson (arcInvestigation, assayIdentifier): assay = arcInvestigation.GetAssay (assayIdentifier) assayJson = JsonController.Assay().to_json_string(assay, spaces = 2)
with open(assayIdentifier + ".arctrl.json", 'w') as f: f.write(assayJson)
# Print all assay identifiers
print(*investigation.AssayIdentifiers, sep='\n')
# MassHunter_targets # RNASeq # GCqTOF_targets
exportAssayToJson (investigation, "RNASeq")Export a single table
Section titled “Export a single table”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.
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"Download example
Section titled “Download example”You can download the example script to adapt it to your needs.