Skip to content

Commit

Permalink
Fixed PoE RGB-channel error
Browse files Browse the repository at this point in the history
  • Loading branch information
YinuoJin committed Aug 12, 2024
1 parent bd21996 commit 00b5b62
Show file tree
Hide file tree
Showing 6 changed files with 398 additions and 858 deletions.
10 changes: 5 additions & 5 deletions notebooks/Starfysh_tutorial_integration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,9 @@
" adata_normed_all.append(adata_normed)\n",
" \n",
" img_metadata = utils.preprocess_img(data_path,\n",
" sample_id,\n",
" adata_index=adata.obs.index,\n",
" hchannel=True\n",
" )\n",
" sample_id,\n",
" adata_index=adata.obs.index,\n",
" rgb_channels=True)\n",
" \n",
" adata.obs['patient']=meta_info['patient'][list(meta_info['sample']).index(sample_id)]\n",
" adata.obs['sample_type']=meta_info['tissue_type'][list(meta_info['sample']).index(sample_id)]\n",
Expand Down Expand Up @@ -1592,6 +1591,7 @@
{
"cell_type": "code",
"execution_count": 11,
"id": "53ae6cd9",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1923,7 +1923,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "base",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand Down
670 changes: 237 additions & 433 deletions notebooks/Starfysh_tutorial_real.ipynb

Large diffs are not rendered by default.

185 changes: 8 additions & 177 deletions notebooks/Starfysh_tutorial_real_wo_signatures.ipynb

Large diffs are not rendered by default.

84 changes: 15 additions & 69 deletions notebooks/Starfysh_tutorial_simulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@
" img_metadata = utils.preprocess_img(data_path,\n",
" sample_id,\n",
" adata_index=adata.obs.index,\n",
" hchannel=True)\n",
" rgb_channels=True)\n",
"\n",
" img, map_info, scalefactor = img_metadata['img'], img_metadata['map_info'], img_metadata['scalefactor']\n",
" map_info = map_info[['array_row', 'array_col']].astype(float)\n",
Expand Down Expand Up @@ -369,7 +369,6 @@
" gene_sig,\n",
" img_metadata,\n",
" window_size=1,\n",
" sig_version='gene_score',\n",
" sample_id=sample_id)\n",
"\n",
"adata, adata_normed = visium_args.get_adata()\n",
Expand Down Expand Up @@ -448,17 +447,7 @@
"If users don't provide annotated gene signature sets with cell types, Starfysh identifies candidates for cell types via archetypal analysis (AA). The underlying assumption is that the geometric \"extremes\" are identified as the purest cell types, whereas all other spots are mixture of the \"archetypes\". If the users provide the gene signature sets, they can still optionally apply AA to refine marker genes and update anchor spots for known cell types. In addition, AA can identify & assign potential novel cell types / states. Here are the features provided by the optional archetypal analysis:\n",
"- Finding archetypal spots & assign 1-1 mapping to their closest anchor spot neighbors\n",
"- Finding archetypal marker genes & append them to marker genes of annotated cell types\n",
"- Assigning novel cell type / cell states as the most distant archetypes\n",
"\n",
"Overall, Archetypal analysis is provided as a complementary toolkit for automatic cell-type annotation & signature gene completion:<br>\n",
"\n",
"1. *If signature genes aren't provided:* <br><br>Archetypal analysis defines the geometric extrema of the data as major cell types with corresponding marker genes.<br><br>\n",
"\n",
"2. *If full, completed signatures of all cell types are annotated*: <br><br>Users can skip this section and use only the signature priors<br><br>\n",
"\n",
"3. *If signature genes are incomplete or require refinement*: <br><br>Archetypal analysis can be applied to\n",
" a. Refine signatures of certain cell types\n",
" b. Find novel cell types / states that haven't been provided from the input signature\n"
"- Assigning novel cell type / cell states as the most distant archetypes"
]
},
{
Expand Down Expand Up @@ -547,21 +536,22 @@
"source": [
"aa_model = AA.ArchetypalAnalysis(adata_orig=adata)\n",
"\n",
"# set large resolution / convergence criteria to obtain major archetypes\n",
"# (1). Find archetypal spots & archetypal clusters\n",
"archetype, arche_dict, major_idx, evs = aa_model.compute_archetypes(converge=1e-2,\n",
" display=False)\n",
"\n",
"# Find neighbor community for each archetype\n",
"# (2). Find marker genes associated with each archetypal cluster\n",
"arche_df = aa_model.find_archetypal_spots(major=True)\n",
"markers_df = aa_model.find_markers(display=False)\n",
"\n",
"# Map archetypes to closest anchors within `r` nearest neighbors\n",
"# Choose the top 30% anchors of each cell type for mapping\n",
"percent_anchor = 0.3\n",
"n_ancs = int(percent_anchor*adata.shape[0])\n",
"\n",
"# (3). Map archetypes to the closest anchors within `r` nearest neighbors\n",
"# Choose the top `anchor_percent` (N%) anchors per cell type for archetype mapping\n",
"# In general, set lower `anchor_percent` for fine resolved cell-states\n",
"anchors_df = visium_args.get_anchors()\n",
"map_df, map_dict = aa_model.assign_archetypes(anchor_df=anchors_df[:n_ancs],r=n_ancs)\n"
"anchor_percent = 0.3\n",
"n_top_anchors = int(anchor_percent*adata.shape[0])\n",
"map_df, map_dict = aa_model.assign_archetypes(anchor_df=anchors_df[:n_top_anchors],\n",
" r=n_top_anchors)"
]
},
{
Expand Down Expand Up @@ -630,55 +620,11 @@
},
"outputs": [],
"source": [
"gene_sig_arch = gene_sig.copy()\n",
"visium_args = utils.refine_anchors(visium_args,\n",
" aa_model,\n",
" anchor_threshold=anchor_percent)\n",
"\n",
"for cell_type in map_dict.keys():\n",
" arch = map_dict[cell_type]\n",
" gene_sig_arch = utils.append_sigs(gene_sig_arch, cell_type, markers_df[arch], n_genes=30)\n"
]
},
{
"cell_type": "markdown",
"id": "9284a681-e8c8-4e2f-931e-357fd6ed55b6",
"metadata": {},
"source": [
"Update anchor ranks based on the appended signatures:"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "3723ae72-1ddc-4b4a-9ced-2add3d355c78",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[2024-04-03 16:58:41] Subsetting highly variable & signature genes ...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[2024-04-03 16:58:47] Smoothing library size by taking averaging with neighbor spots...\n",
"[2024-04-03 16:58:48] Retrieving & normalizing signature gene expressions...\n",
"[2024-04-03 16:58:48] Identifying anchor spots (highly expression of specific cell-type signatures)...\n"
]
}
],
"source": [
"visium_args = utils.VisiumArguments(adata,\n",
" adata_normed,\n",
" gene_sig_arch,\n",
" img_metadata,\n",
" window_size=1,\n",
" sample_id=sample_id\n",
" )\n",
"\n",
"adata, adata_normed = visium_args.get_adata()\n",
"anchors_df = visium_args.get_anchors()"
"adata, adata_normed = visium_args.get_adata()"
]
},
{
Expand Down
Loading

0 comments on commit 00b5b62

Please sign in to comment.