Skip to content

Commit

Permalink
📝 Move markdowns into code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyosun committed Mar 27, 2024
1 parent 4251459 commit 9e6d189
Showing 1 changed file with 19 additions and 83 deletions.
102 changes: 19 additions & 83 deletions docs/introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -123,44 +123,33 @@
" index=[\"observation1\", \"observation2\", \"observation3\"],\n",
")\n",
"\n",
"# create an artifact from a DataFrame\n",
"artifact = ln.Artifact.from_df(df, description=\"my RNA-seq\", version=\"1\")\n",
"\n",
"# any artifact comes with typed, relational metadata\n",
"artifact.describe()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you save an artifact, you save data & metadata in one operation."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# if you save an artifact, you save data & metadata in one operation\n",
"artifact.save()\n",
"\n",
"# for any artifact, you can view its data lineage\n",
"artifact.view_lineage()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Load an artifact."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# load an artifact\n",
"artifact.load()"
]
},
Expand All @@ -181,7 +170,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Labels"
"### Labels\n",
"\n",
"Add an universal label {class}`~lamindb.ULabel` to artifact."
]
},
{
Expand All @@ -200,13 +191,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Query"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Query\n",
"\n",
"Because, under-the-hood, LaminDB is SQL & Django, you can write arbitrarily complex relational queries."
]
},
Expand Down Expand Up @@ -265,7 +251,7 @@
"source": [
"### Look up\n",
"\n",
"Look up records in any registry with auto-complete."
"Look up records in a registry with auto-complete."
]
},
{
Expand Down Expand Up @@ -355,15 +341,7 @@
"metadata": {},
"outputs": [],
"source": [
"validator.register_features(validated_only=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"validator.register_features(validated_only=False)\n",
"validator.update_registry(\"perturbation\")"
]
},
Expand Down Expand Up @@ -392,35 +370,23 @@
"ln.ULabel.df()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now the validation passes."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# now the validation passes\n",
"validator.validate()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create, annotate and save an artifact."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# create, annotate and save an artifact\n",
"artifact = validator.register_artifact(description=\"my RNA-seq\", version=\"1\")\n",
"artifact.describe()"
]
Expand All @@ -436,19 +402,13 @@
":::"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Get lookup object for the entities of interest."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# get lookup object for the entities of interest\n",
"lookups = validator.lookup()\n",
"lookups"
]
Expand All @@ -459,6 +419,7 @@
"metadata": {},
"outputs": [],
"source": [
"# filter artifacts with specific labels\n",
"perturbations = lookups[\"perturbation\"]\n",
"ln.Artifact.filter(ulabels=candidate_marker_study).filter(ulabels=perturbations.ifng).one()"
]
Expand Down Expand Up @@ -514,13 +475,6 @@
"artifact.describe()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Query for genes & the linked artifacts:"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -529,6 +483,7 @@
},
"outputs": [],
"source": [
"# query for genes & the linked artifacts\n",
"genes = bt.Gene.filter(organism__name=\"human\").lookup()\n",
"feature_sets_with_cd8a = ln.FeatureSet.filter(genes=genes.cd8a).all()\n",
"ln.Artifact.filter(feature_sets__in=feature_sets_with_cd8a).df()"
Expand Down Expand Up @@ -582,13 +537,6 @@
"## Collections of artifacts"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Access a new batch of data."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -599,6 +547,7 @@
},
"outputs": [],
"source": [
"# access a new batch of data\n",
"df = pd.DataFrame(\n",
" {\n",
" \"CD8A\": [2, 3, 3],\n",
Expand All @@ -610,12 +559,11 @@
")\n",
"adata = ad.AnnData(df[[\"CD8A\", \"CD4\", \"CD38\"]], obs=df[[\"perturbation\"]])\n",
"\n",
"# Validate, annotate and register a new artifact\n",
"# validate, annotate and register a new artifact\n",
"validator = ln.Validate.from_anndata(adata, \n",
" obs_fields={\"perturbation\": ln.ULabel.name}, \n",
" var_field=bt.Gene.symbol, \n",
" organism=\"human\")\n",
"\n",
"validator.validate()\n",
"artifact2 = validator.register_artifact(description=\"my RNA-seq batch 2\")"
]
Expand All @@ -639,35 +587,23 @@
"collection.view_lineage()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If it's small enough, you can load the entire collection into memory as if it was one."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# if it's small enough, you can load the entire collection into memory as if it was one\n",
"collection.load()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Iterate over its artifacts."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# iterate over its artifacts\n",
"collection.artifacts.df()"
]
},
Expand Down

0 comments on commit 9e6d189

Please sign in to comment.