Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miniscule table documentation script in javascript #260

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ and __JavaScript__! ❤️

| Version | Downloads |
| :--------|-----------:|
|![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/ARCtrl?logo=nuget&color=%234fb3d9)|![Nuget](https://img.shields.io/nuget/dt/ARCtrl?color=%234FB3D9)|
|![npm (scoped with tag)](https://img.shields.io/npm/v/%40nfdi4plants/arctrl/next?logo=npm&color=%234fb3d9)|![npm](https://img.shields.io/npm/dt/%40nfdi4plants%2Farctrl?color=%234fb3d9)|
|<a href="https://www.nuget.org/packages/ARCtrl/"><img alt="Nuget" src="https://img.shields.io/nuget/vpre/ARCtrl?logo=nuget&color=%234fb3d9"></a>|<a href="https://www.nuget.org/packages/ARCtrl/"><img alt="Nuget" src="https://img.shields.io/nuget/dt/ARCtrl?color=%234FB3D9"></a>|
|<a href="https://www.npmjs.com/package/@nfdi4plants/arctrl"><img alt="NPM" src="https://img.shields.io/npm/v/%40nfdi4plants/arctrl/next?logo=npm&color=%234fb3d9"></a>|<a href="https://www.npmjs.com/package/@nfdi4plants/arctrl"><img alt="NPM" src="https://img.shields.io/npm/dt/%40nfdi4plants%2Farctrl?color=%234fb3d9"></a>|


## Install

Expand Down
50 changes: 50 additions & 0 deletions docs/scripts_js/Tables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// This script presents the most straightforward way to create and write an assay file filled with tables
// In principle, there are three steps
// 1. Create and manipulate object in datamodel
// 2. Transform object to generic spreadsheet
// 3. Write spreadsheet to xlsx file (or bytes)

// Import ARCtrl
import * as arctrl from "@nfdi4plants/arctrl"
// Alternative import
// import {
// Comment$ as Comment, OntologyAnnotation, Person, Publication,
// IOType, CompositeHeader, CompositeCell, CompositeColumn, ArcTable,
// ArcAssay, ArcStudy, ArcInvestigation,
// Template, Organisation, Templates, JsWeb,
// ARC } from "@nfdi4plants/arctrl";

// Import ARCtrl Assay to Spreadsheet transformation
import {toFsWorkbook,fromFsWorkbook} from "@nfdi4plants/arctrl/ISA/ISA.Spreadsheet/ArcAssay.js"

// Import Spreadsheet to XLSX reader/writer
import {Xlsx} from "@fslab/fsspreadsheet";

// -------- 1. Create and manipulate object in datamodel ----------

// Create assay
const myAssay = arctrl.ArcAssay.init("MyAssay");

// Create annotation table
const growth = arctrl.ArcTable.init("Growth");

// Add input column with one value to table
growth.AddColumn(new arctrl.CompositeHeader(11, [new arctrl.IOType(0, [])]), [arctrl.CompositeCell.createFreeText("Input1")]);

// Add characteristic column with one value
const oa_species = arctrl.OntologyAnnotation.fromString("species", "GO", "GO:0123456");
const oa_chlamy = arctrl.OntologyAnnotation.fromString("Chlamy", "NCBI", "NCBI:0123456");
growth.AddColumn(new arctrl.CompositeHeader(1, [oa_species]), [arctrl.CompositeCell.createTerm(oa_chlamy)]);

// Add table to assay
myAssay.AddTable(growth);

// -------- 2. Transform object to generic spreadsheet ----------
let spreadsheet = toFsWorkbook(myAssay);

// -------- 3. Write spreadsheet to xlsx file (or bytes) ----------
const outPath = "./myFile.xlsx";

console.log(Xlsx.toBytes(spreadsheet));

await Xlsx.toFile(outPath,spreadsheet);
40 changes: 20 additions & 20 deletions docs/scripts_js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/scripts_js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Kevin Frey",
"license": "MIT",
"dependencies": {
"@nfdi4plants/arctrl": "^1.0.0-alpha6",
"fsspreadsheet": "^4.0.0-alpha2"
"@nfdi4plants/arctrl": "^1.0.0-beta.7",
"@fslab/fsspreadsheet": "^5.0.0"
}
}