Skip to content

Commit

Permalink
✨ Format all notebooks (#155)
Browse files Browse the repository at this point in the history
Signed-off-by: zethson <[email protected]>
  • Loading branch information
Zethson authored Sep 25, 2024
1 parent 772696b commit b7a7cf3
Show file tree
Hide file tree
Showing 20 changed files with 105 additions and 76 deletions.
10 changes: 5 additions & 5 deletions docs/analysis-flow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@
"outputs": [],
"source": [
"curate = ln.Curator.from_anndata(\n",
" adata_subset.to_memory(), \n",
" var_index=bt.Gene.ensembl_gene_id, \n",
" adata_subset.to_memory(),\n",
" var_index=bt.Gene.ensembl_gene_id,\n",
" categoricals={\n",
" \"cell_type\": bt.CellType.name, \n",
" \"disease\": bt.Disease.name, \n",
" \"cell_type\": bt.CellType.name,\n",
" \"disease\": bt.Disease.name,\n",
" \"tissue\": bt.Tissue.name,\n",
" },\n",
" organism=\"human\"\n",
" organism=\"human\",\n",
")\n",
"\n",
"curate.validate()"
Expand Down
2 changes: 1 addition & 1 deletion docs/analysis-registries.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@
"source": [
"artifact.features._add_set_from_anndata(\n",
" var_field=bt.Gene.symbol,\n",
" organism=\"human\", # optionally, globally set organism via bt.settings.organism = \"human\"\n",
" organism=\"human\", # optionally, globally set organism via bt.settings.organism = \"human\"\n",
")"
]
},
Expand Down
13 changes: 7 additions & 6 deletions docs/bulkrna.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@
"outputs": [],
"source": [
"# pretend we're running a bulk RNA-seq pipeline\n",
"ln.track(transform=ln.Transform(name=\"nf-core RNA-seq\", reference=\"https://nf-co.re/rnaseq\"))\n",
"ln.track(\n",
" transform=ln.Transform(name=\"nf-core RNA-seq\", reference=\"https://nf-co.re/rnaseq\")\n",
")\n",
"# create a directory for its output\n",
"Path(\"./test-bulkrna/output_dir\").mkdir(exist_ok=True)\n",
"# get the count matrix\n",
Expand Down Expand Up @@ -364,10 +366,7 @@
},
"outputs": [],
"source": [
"curated_file = ln.Artifact.from_anndata(\n",
" adata,\n",
" description=\"Curated bulk RNA counts\"\n",
")"
"curated_file = ln.Artifact.from_anndata(adata, description=\"Curated bulk RNA counts\")"
]
},
{
Expand Down Expand Up @@ -407,7 +406,9 @@
},
"outputs": [],
"source": [
"curated_file.features._add_set_from_anndata(var_field=bt.Gene.stable_id, organism=\"saccharomyces cerevisiae\")"
"curated_file.features._add_set_from_anndata(\n",
" var_field=bt.Gene.stable_id, organism=\"saccharomyces cerevisiae\"\n",
")"
]
},
{
Expand Down
4 changes: 1 addition & 3 deletions docs/cell_marker.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,7 @@
"metadata": {},
"outputs": [],
"source": [
"source = bt.Source.get(\n",
" name=\"cellmarker\", version=\"2.0\", organism=\"human\"\n",
")\n",
"source = bt.Source.get(name=\"cellmarker\", version=\"2.0\", organism=\"human\")\n",
"public = bt.CellMarker.public(source=source)\n",
"public"
]
Expand Down
1 change: 1 addition & 0 deletions docs/celltypist.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"description = \"CellTypist Pan Immune Atlas v2: basic cell type information\"\n",
"celltypist_source_v2_url = \"https://github.com/Teichlab/celltypist_wiki/raw/main/atlases/Pan_Immune_CellTypist/v2/tables/Basic_celltype_information.xlsx\"\n",
"\n",
Expand Down
4 changes: 3 additions & 1 deletion docs/facs2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,9 @@
"outputs": [],
"source": [
"collection_v2 = ln.Collection(\n",
" [artifact, collection_v1.ordered_artifacts[0]], is_new_version_of=collection_v1, version=\"2\"\n",
" [artifact, collection_v1.ordered_artifacts[0]],\n",
" is_new_version_of=collection_v1,\n",
" version=\"2\",\n",
")\n",
"collection_v2.describe()"
]
Expand Down
4 changes: 1 addition & 3 deletions docs/facs4.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
},
"outputs": [],
"source": [
"collection = ln.Collection.get(\n",
" name=\"My versioned cytometry collection\", version=\"2\"\n",
")"
"collection = ln.Collection.get(name=\"My versioned cytometry collection\", version=\"2\")"
]
},
{
Expand Down
4 changes: 1 addition & 3 deletions docs/gene.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,7 @@
"metadata": {},
"outputs": [],
"source": [
"source = bt.Source.get(\n",
" name=\"ensembl\", version=\"release-112\", organism=\"human\"\n",
")\n",
"source = bt.Source.get(name=\"ensembl\", version=\"release-112\", organism=\"human\")\n",
"public = bt.Gene.public(source=source)\n",
"public"
]
Expand Down
12 changes: 6 additions & 6 deletions docs/multimodal.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@
"curate = ln.Curator.from_mudata(\n",
" mdata,\n",
" var_index={\n",
" \"rna\": bt.Gene.symbol, # gene expression\n",
" \"adt\": bt.CellMarker.name, # antibody derived tags reflecting surface proteins\n",
" \"hto\": ln.Feature.name, # cell hashing\n",
" \"gdo\": ln.Feature.name, # guide RNAs\n",
" \"rna\": bt.Gene.symbol, # gene expression\n",
" \"adt\": bt.CellMarker.name, # antibody derived tags reflecting surface proteins\n",
" \"hto\": ln.Feature.name, # cell hashing\n",
" \"gdo\": ln.Feature.name, # guide RNAs\n",
" },\n",
" categoricals={\n",
" \"perturbation\": ln.ULabel.name, # shared categorical\n",
" \"replicate\": ln.ULabel.name, # shared categorical\n",
" \"hto:technique\": bt.ExperimentalFactor.name # note this is a modality specific categorical\n",
" \"replicate\": ln.ULabel.name, # shared categorical\n",
" \"hto:technique\": bt.ExperimentalFactor.name, # note this is a modality specific categorical\n",
" },\n",
" organism=\"human\",\n",
")"
Expand Down
10 changes: 7 additions & 3 deletions docs/perturbation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,11 @@
"genetic_treatments = []\n",
"for name, symbol, target_name in treatments:\n",
" treatment = wl.GeneticTreatment(system=\"CRISPR KO\", name=name).save()\n",
" gene = bt.Gene.from_source(symbol=symbol, organism=organism).save() if symbol != \"lacz\" else bt.Gene(symbol=symbol, organism=organism).save()\n",
" gene = (\n",
" bt.Gene.from_source(symbol=symbol, organism=organism).save()\n",
" if symbol != \"lacz\"\n",
" else bt.Gene(symbol=symbol, organism=organism).save()\n",
" )\n",
" target = wl.TreatmentTarget(name=target_name).save()\n",
" target.genes.add(gene)\n",
" treatment.targets.add(target)\n",
Expand Down Expand Up @@ -457,8 +461,8 @@
"# We found a synonym for jq1. Let's use the correct name for the metadata\n",
"drug_metadata = adata.obs[adata.obs[\"perturbation_type\"] == \"drug\"].copy()\n",
"drug_metadata[\"perturbation\"] = drug_metadata[\"perturbation\"].cat.rename_categories(\n",
" {\"jq1\": wl.Compound.search(\"jq1\").one().name}\n",
" )"
" {\"jq1\": wl.Compound.search(\"jq1\").one().name}\n",
")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/project-flow-scripts/hit-identification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"metadata": {},
"outputs": [],
"source": [
"#ln.context.finish()"
"# ln.context.finish()"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion docs/project-flow-scripts/integrated-analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"metadata": {},
"outputs": [],
"source": [
"#ln.context.finish()"
"# ln.context.finish()"
]
}
],
Expand Down
9 changes: 7 additions & 2 deletions docs/project-flow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
" )\n",
" output_file.save()\n",
"\n",
"\n",
"mock_upload_crispra_result_app()"
]
},
Expand Down Expand Up @@ -170,7 +171,9 @@
"from pathlib import Path\n",
"\n",
"cwd = Path.cwd()\n",
"nbproject_test.execute_notebooks(cwd / \"project-flow-scripts/hit-identification.ipynb\", write=True)"
"nbproject_test.execute_notebooks(\n",
" cwd / \"project-flow-scripts/hit-identification.ipynb\", write=True\n",
")"
]
},
{
Expand Down Expand Up @@ -316,7 +319,9 @@
"source": [
"# the following mimics the integrated analysis notebook\n",
"# In reality, you would execute inside the notebook\n",
"nbproject_test.execute_notebooks(cwd / \"project-flow-scripts/integrated-analysis.ipynb\", write=True)"
"nbproject_test.execute_notebooks(\n",
" cwd / \"project-flow-scripts/integrated-analysis.ipynb\", write=True\n",
")"
]
},
{
Expand Down
9 changes: 6 additions & 3 deletions docs/rdf-sparql.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"outputs": [],
"source": [
"import warnings\n",
"\n",
"warnings.filterwarnings(\"ignore\")"
]
},
Expand Down Expand Up @@ -102,10 +103,12 @@
"namespace = URIRef(\"http://sparql-example.org/\")\n",
"\n",
"for _, row in diseases.iterrows():\n",
" subject = URIRef(namespace + str(row['ontology_id']))\n",
" subject = URIRef(namespace + str(row[\"ontology_id\"]))\n",
" rdf_graph.add((subject, RDF.type, URIRef(namespace + \"Disease\")))\n",
" rdf_graph.add((subject, URIRef(namespace + \"name\"), Literal(row['name'])))\n",
" rdf_graph.add((subject, URIRef(namespace + \"description\"), Literal(row['description'])))\n",
" rdf_graph.add((subject, URIRef(namespace + \"name\"), Literal(row[\"name\"])))\n",
" rdf_graph.add(\n",
" (subject, URIRef(namespace + \"description\"), Literal(row[\"description\"]))\n",
" )\n",
"\n",
"rdf_graph"
]
Expand Down
48 changes: 29 additions & 19 deletions docs/scrna-tiledbsoma.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@
},
"outputs": [],
"source": [
"collection = ln.Collection.get(\n",
" name=\"My versioned scRNA-seq collection\", version=\"2\"\n",
")\n",
"collection = ln.Collection.get(name=\"My versioned scRNA-seq collection\", version=\"2\")\n",
"collection.describe()"
]
},
Expand Down Expand Up @@ -96,9 +94,15 @@
"adatas = [artifact.load() for artifact in collection.ordered_artifacts]\n",
"\n",
"# compute the intersection of columns for these objects\n",
"var_columns = reduce(pd.Index.intersection, [adata.var.columns for adata in adatas]) # this only affects metadata columns of features (say, gene annotations)\n",
"var_raw_columns = reduce(pd.Index.intersection, [adata.raw.var.columns for adata in adatas])\n",
"obs_columns = reduce(pd.Index.intersection, [adata.obs.columns for adata in adatas]) # this actually subsets features (dataset dimensions)"
"var_columns = reduce(\n",
" pd.Index.intersection, [adata.var.columns for adata in adatas]\n",
") # this only affects metadata columns of features (say, gene annotations)\n",
"var_raw_columns = reduce(\n",
" pd.Index.intersection, [adata.raw.var.columns for adata in adatas]\n",
")\n",
"obs_columns = reduce(\n",
" pd.Index.intersection, [adata.obs.columns for adata in adatas]\n",
") # this actually subsets features (dataset dimensions)"
]
},
{
Expand All @@ -120,17 +124,19 @@
"source": [
"for i, adata in enumerate(adatas):\n",
" del adata.obsp # not supported by tiledbsoma\n",
" del adata.uns # not supported by tiledbsoma\n",
" \n",
" del adata.uns # not supported by tiledbsoma\n",
"\n",
" adata.obs = adata.obs.filter(obs_columns) # filter columns to intersection\n",
" adata.obs[\"obs_id\"] = adata.obs.index # prepare a column for tiledbsoma to use as an index\n",
" adata.obs[\"obs_id\"] = (\n",
" adata.obs.index\n",
" ) # prepare a column for tiledbsoma to use as an index\n",
" adata.obs[\"dataset\"] = i\n",
" adata.obs.index.name = None\n",
" \n",
"\n",
" adata.var = adata.var.filter(var_columns) # filter columns to intersection\n",
" adata.var[\"var_id\"] = adata.var.index\n",
" adata.var.index.name = None\n",
" \n",
"\n",
" drop_raw_var_columns = adata.raw.var.columns.difference(var_raw_columns)\n",
" adata.raw.var.drop(columns=drop_raw_var_columns, inplace=True)\n",
" adata.raw.var[\"var_id\"] = adata.raw.var.index\n",
Expand Down Expand Up @@ -167,7 +173,7 @@
" measurement_name=\"RNA\",\n",
" obs_id_name=\"obs_id\",\n",
" var_id_name=\"var_id\",\n",
" append_obsm_varm=True\n",
" append_obsm_varm=True,\n",
")"
]
},
Expand Down Expand Up @@ -211,12 +217,12 @@
"with soma_artifact.open() as soma_store:\n",
" obs = soma_store[\"obs\"]\n",
" var = soma_store[\"ms\"][\"RNA\"][\"var\"]\n",
" \n",
"\n",
" obs_columns_store = obs.schema.names\n",
" var_columns_store = var.schema.names\n",
" \n",
"\n",
" obs_store_df = obs.read().concat().to_pandas()\n",
" \n",
"\n",
" display(obs_store_df)"
]
},
Expand Down Expand Up @@ -280,10 +286,14 @@
"\n",
"adata.obs[\"dataset\"] = obs_store_df[\"dataset\"].max()\n",
"\n",
"obs_columns_same = [obs_col for obs_col in adata.obs.columns if obs_col in obs_columns_store]\n",
"obs_columns_same = [\n",
" obs_col for obs_col in adata.obs.columns if obs_col in obs_columns_store\n",
"]\n",
"adata.obs = adata.obs[obs_columns_same]\n",
"\n",
"var_columns_same = [var_col for var_col in adata.var.columns if var_col in var_columns_store]\n",
"var_columns_same = [\n",
" var_col for var_col in adata.var.columns if var_col in var_columns_store\n",
"]\n",
"adata.var = adata.var[var_columns_same]\n",
"\n",
"adata.write_h5ad(\"adata_to_append.h5ad\")"
Expand Down Expand Up @@ -311,7 +321,7 @@
" revises=soma_artifact,\n",
" measurement_name=\"RNA\",\n",
" obs_id_name=\"obs_id\",\n",
" var_id_name=\"var_id\"\n",
" var_id_name=\"var_id\",\n",
")"
]
},
Expand Down Expand Up @@ -373,7 +383,7 @@
" measurement_name=\"RNA\",\n",
" collection_name=\"obsm\",\n",
" matrix_name=\"pca\",\n",
" matrix_data=pca_array\n",
" matrix_data=pca_array,\n",
" )"
]
},
Expand Down
16 changes: 8 additions & 8 deletions docs/scrna.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"outputs": [],
"source": [
"# !pip install 'lamindb[jupyter,aws,bionty]' \n",
"# !pip install 'lamindb[jupyter,aws,bionty]'\n",
"!lamin init --storage ./test-scrna --schema bionty"
]
},
Expand Down Expand Up @@ -124,14 +124,14 @@
"outputs": [],
"source": [
"curate = ln.Curator.from_anndata(\n",
" adata, \n",
" var_index=bt.Gene.ensembl_gene_id, \n",
" adata,\n",
" var_index=bt.Gene.ensembl_gene_id,\n",
" categoricals={\n",
" adata.obs.donor.name: ln.ULabel.name, \n",
" adata.obs.tissue.name: bt.Tissue.name, \n",
" adata.obs.cell_type.name: bt.CellType.name, \n",
" adata.obs.assay.name: bt.ExperimentalFactor.name\n",
" }, \n",
" adata.obs.donor.name: ln.ULabel.name,\n",
" adata.obs.tissue.name: bt.Tissue.name,\n",
" adata.obs.cell_type.name: bt.CellType.name,\n",
" adata.obs.assay.name: bt.ExperimentalFactor.name,\n",
" },\n",
" organism=\"human\",\n",
")"
]
Expand Down
Loading

0 comments on commit b7a7cf3

Please sign in to comment.