{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Create a simple ISA descriptor\n", "\n", "This example creates minimal metadata for a single study ISA descriptor with no assay declared. \n", "\n", "It shows how to serialize (write) the ISA Model content to ISA-Tab and ISA-JSON formats." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# If executing the notebooks on `Google Colab`,uncomment the following command \n", "# and run it to install the required python libraries. Also, make the test datasets available.\n", "\n", "# !pip install -r requirements.txt" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from isatools.model import (\n", " Investigation,\n", " Study,\n", " OntologyAnnotation,\n", " Sample,\n", " Source,\n", " Protocol,\n", " ProtocolParameter,\n", " Process\n", ")\n", "import datetime" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Study metadata" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "investigation = Investigation()\n", "study = Study(filename=\"s_study.txt\")\n", "study.identifier = \"S1\"\n", "study.title = \"My Simple ISA Study\"\n", "study.description = \"We could alternatively use the class constructor's parameters to set some default \" \\\n", " \"values at the time of creation, however we want to demonstrate how to use the \" \\\n", " \"object's instance variables to set values.\"\n", "study.submission_date = str(datetime.datetime.today())\n", "study.public_release_date = str(datetime.datetime.today())\n", "study.sources = [Source(name=\"source1\")]\n", "study.samples = [Sample(name=\"sample1\")]\n", "study.protocols = [\n", " Protocol(name=\"sample collection\"),\n", " Protocol(\n", " name=\"data analysis with Galaxy\",\n", " uri=\"https://doi.org/10.5464/workflow.cwl\",\n", " protocol_type=OntologyAnnotation(term=\"data transformation\"),\n", " parameters=[\n", " ProtocolParameter(parameter_name=OntologyAnnotation(term=\"genome assembly\")),\n", " ProtocolParameter(parameter_name=OntologyAnnotation(term=\"cut-off value\"))\n", " ]\n", " ),\n", " Protocol(\n", " name=\"data visualization with Intermine\",\n", " uri=\"https://intermine.org/10.5464/network.svg\",\n", " protocol_type=OntologyAnnotation(term=\"data visualization\"),\n", " )\n", "]\n", "study.process_sequence = [\n", " Process(\n", " executes_protocol=study.protocols[-1],\n", " inputs=[study.sources[-1]],\n", " outputs=[study.samples[-1]]\n", " )\n", "]\n", "investigation.studies = [study]\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Let's see the object :\n", "investigation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Writing to ISA-Tab" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from isatools.isatab import dumps\n", "print(dumps(investigation))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Writing to ISA-JSON" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import json\n", "from isatools.isajson import ISAJSONEncoder\n", "print(json.dumps(investigation, cls=ISAJSONEncoder, sort_keys=True, indent=4, separators=(',', ': ')))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## About this notebook\n", "\n", "- authors: philippe.rocca-serra@oerc.ox.ac.uk, massimiliano.izzo@oerc.ox.ac.uk\n", "- license: CC-BY 4.0\n", "- support: isatools@googlegroups.com\n", "- issue tracker: https://github.com/ISA-tools/isa-api/issues" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.1" } }, "nbformat": 4, "nbformat_minor": 1 }