|
46 | 46 | "from utag import utag\n",
|
47 | 47 | "\n",
|
48 | 48 | "from utag.utils import celltype_connectivity, domain_connectivity\n",
|
49 |
| - "from utag.vizualize import (\n", |
| 49 | + "from utag.visualize import (\n", |
50 | 50 | " add_scale_box_to_fig,\n",
|
51 | 51 | " add_spatial_image,\n",
|
52 | 52 | " adj2chord,\n",
|
|
447 | 447 | "id": "441dbd76-d44d-4cd6-b0fb-61ba6301ae32",
|
448 | 448 | "metadata": {},
|
449 | 449 | "source": [
|
450 |
| - "## Visualizing Results" |
451 |
| - ] |
452 |
| - }, |
453 |
| - { |
454 |
| - "cell_type": "code", |
455 |
| - "execution_count": null, |
456 |
| - "id": "618ed50b-1d71-4139-9170-5ea8f489f317", |
457 |
| - "metadata": {}, |
458 |
| - "outputs": [], |
459 |
| - "source": [ |
460 |
| - "import squidpy as sq\n", |
461 |
| - "import numpy as np\n", |
462 |
| - "\n", |
463 |
| - "UTAG_lab = \"UTAG Label\"\n", |
464 |
| - "sc.settings.set_figure_params(dpi=300, dpi_save=300, fontsize=6)\n", |
465 |
| - "for img in results.obs[\"roi\"].unique():\n", |
466 |
| - " if img in ['20200708_COVID_21_LATE-10','20200804_NL1933A_RUN2-03', '20200804_NL1933A_RUN2-02', '20200701_COVID_11_LATE-08']:\n", |
467 |
| - " try:\n", |
468 |
| - " fig, ax = plt.subplots(1,4, dpi = 500, figsize = (40,16))\n", |
469 |
| - " a1 = results[results.obs[\"roi\"] == img, :].copy()\n", |
470 |
| - "\n", |
471 |
| - " roi = img.split('-')[0]\n", |
472 |
| - " a1.obs[['Y_centroid', 'X_centroid']] = a1.obs[['Y', 'X']]\n", |
473 |
| - " path = f'../covid-imc1/processed/{roi}/tiffs/{img}_full.tiff'\n", |
474 |
| - " print(path)\n", |
475 |
| - " #sc.pp.neighbors(a1)\n", |
476 |
| - " sq.gr.spatial_neighbors(a1, radius = 40, coord_type = 'generic')\n", |
477 |
| - "\n", |
478 |
| - " result_batch = add_spatial_image(adata = a1,\n", |
479 |
| - " image_path = path,\n", |
480 |
| - " rgb_channels = [31, 4, 14], # Col1, aSMA, CD31\n", |
481 |
| - " gamma = 1, gain = 0.3,\n", |
482 |
| - " log_transform = True)\n", |
483 |
| - "\n", |
484 |
| - " sc.pl.spatial(a1, color=UTAG_lab, spot_size=12, title=str(img) + '\\nCol1, aSMA, CD31', frameon=False, ax = ax[0], show = False, alpha = 0, legend_loc = None)\n", |
485 |
| - " add_scale_box_to_fig(a1.uns[\"spatial\"]['image'][\"images\"]['hires'], ax[0], box_width = 200)\n", |
486 |
| - "\n", |
487 |
| - "\n", |
488 |
| - " result_batch = add_spatial_image(adata = a1,\n", |
489 |
| - " image_path = path,\n", |
490 |
| - " rgb_channels = [24, 17, 10], # KRT8, VIM, CD163\n", |
491 |
| - " gamma = 1, gain = 0.3,\n", |
492 |
| - " log_transform = True)\n", |
493 |
| - "\n", |
494 |
| - " sc.pl.spatial(a1, color=UTAG_lab, spot_size=12, title=str(img) + '\\nCD8, VIM, CD163', frameon=False, ax = ax[1], show = False, alpha = 0, legend_loc = None)\n", |
495 |
| - " add_scale_box_to_fig(a1.uns[\"spatial\"]['image'][\"images\"]['hires'], ax[1], box_width = 200)\n", |
496 |
| - "\n", |
497 |
| - " result_batch = add_spatial_image(adata = a1,\n", |
498 |
| - " image_path = path,\n", |
499 |
| - " rgb_channels = [35, 19, 36], # MPO, CD4, CD8\n", |
500 |
| - " gamma = 1, gain = 1,\n", |
501 |
| - " log_transform = True)\n", |
502 |
| - "\n", |
503 |
| - " sc.pl.spatial(a1, color=UTAG_lab, spot_size=12, title=str(img) + '\\nMPO, CD4, KRT8', frameon=False, ax = ax[2], show = False, alpha = 0, legend_loc = None)\n", |
504 |
| - " add_scale_box_to_fig(a1.uns[\"spatial\"]['image'][\"images\"]['hires'], ax[2], box_width = 200)\n", |
505 |
| - "\n", |
506 |
| - " sc.pl.spatial(a1, color=UTAG_lab, spot_size=12, title='Domain Interaction Graph', frameon=False, ax = ax[3], alpha_img = 0, show = False, edges = True, edges_width = 0.2, neighbors_key=\"spatial_neighbors\")\n", |
507 |
| - "\n", |
508 |
| - " #plt.savefig(f'figures/slides/{img}.pdf', bbox_inches = 'tight')\n", |
509 |
| - " #plt.savefig(f'figures/slides/{img}.jpg', bbox_inches = 'tight')\n", |
510 |
| - " plt.show()\n", |
511 |
| - " plt.close()\n", |
512 |
| - " except FileNotFoundError:\n", |
513 |
| - " pass\n", |
514 |
| - " " |
515 |
| - ] |
516 |
| - }, |
517 |
| - { |
518 |
| - "cell_type": "code", |
519 |
| - "execution_count": null, |
520 |
| - "id": "ea42a305-c90c-4051-bef3-a089b8e4e9a7", |
521 |
| - "metadata": {}, |
522 |
| - "outputs": [], |
523 |
| - "source": [ |
524 |
| - "import squidpy as sq\n", |
525 |
| - "import numpy as np\n", |
526 |
| - "\n", |
527 |
| - "UTAG_lab = \"UTAG Label\"\n", |
528 |
| - "sc.settings.set_figure_params(dpi=300, dpi_save=300, fontsize=6)\n", |
529 |
| - "for img in results.obs[\"roi\"].unique():\n", |
530 |
| - "\n", |
531 |
| - " try:\n", |
532 |
| - " fig, ax = plt.subplots(1, 4, dpi=300, figsize=(20, 8))\n", |
533 |
| - " a1 = results[results.obs[\"roi\"] == img, :].copy()\n", |
534 |
| - "\n", |
535 |
| - " roi = img.split(\"-\")[0]\n", |
536 |
| - " a1.obs[[\"Y_centroid\", \"X_centroid\"]] = a1.obs[[\"Y\", \"X\"]]\n", |
537 |
| - " path = f\"../covid-imc1/processed/{roi}/tiffs/{img}_full.tiff\"\n", |
538 |
| - " print(path)\n", |
539 |
| - " # sc.pp.neighbors(a1)\n", |
540 |
| - " sq.gr.spatial_neighbors(a1, radius=40, coord_type=\"generic\")\n", |
541 |
| - "\n", |
542 |
| - " result_batch = add_spatial_image(\n", |
543 |
| - " adata=a1,\n", |
544 |
| - " image_path=path,\n", |
545 |
| - " rgb_channels=[36, 4, 40], # Col1, aSMA, CD31\n", |
546 |
| - " gamma=1,\n", |
547 |
| - " gain=0.3,\n", |
548 |
| - " log_transform=True,\n", |
549 |
| - " )\n", |
550 |
| - "\n", |
551 |
| - " sc.pl.spatial(\n", |
552 |
| - " a1,\n", |
553 |
| - " color=UTAG_lab,\n", |
554 |
| - " spot_size=12,\n", |
555 |
| - " title=str(img) + \"\\nKRT8, aSMA, DNA1\",\n", |
556 |
| - " frameon=False,\n", |
557 |
| - " ax=ax[0],\n", |
558 |
| - " show=False,\n", |
559 |
| - " alpha=0,\n", |
560 |
| - " legend_loc=None,\n", |
561 |
| - " )\n", |
562 |
| - " add_scale_box_to_fig(\n", |
563 |
| - " a1.uns[\"spatial\"][\"image\"][\"images\"][\"hires\"], ax[0], box_width=200\n", |
564 |
| - " )\n", |
565 |
| - "\n", |
566 |
| - " result_batch = add_spatial_image(\n", |
567 |
| - " adata=a1,\n", |
568 |
| - " image_path=path,\n", |
569 |
| - " rgb_channels=[24, 31, 10], # KRT8, VIM, CD163\n", |
570 |
| - " gamma=1,\n", |
571 |
| - " gain=0.3,\n", |
572 |
| - " log_transform=True,\n", |
573 |
| - " )\n", |
574 |
| - "\n", |
575 |
| - " sc.pl.spatial(\n", |
576 |
| - " a1,\n", |
577 |
| - " color=UTAG_lab,\n", |
578 |
| - " spot_size=12,\n", |
579 |
| - " title=str(img) + \"\\nCD8, VIM, CD163\",\n", |
580 |
| - " frameon=False,\n", |
581 |
| - " ax=ax[1],\n", |
582 |
| - " show=False,\n", |
583 |
| - " alpha=0,\n", |
584 |
| - " legend_loc=None,\n", |
585 |
| - " )\n", |
586 |
| - " add_scale_box_to_fig(\n", |
587 |
| - " a1.uns[\"spatial\"][\"image\"][\"images\"][\"hires\"], ax[1], box_width=200\n", |
588 |
| - " )\n", |
589 |
| - "\n", |
590 |
| - " result_batch = add_spatial_image(\n", |
591 |
| - " adata=a1,\n", |
592 |
| - " image_path=path,\n", |
593 |
| - " rgb_channels=[35, 19, 36], # MPO, CD4, CD8\n", |
594 |
| - " gamma=1,\n", |
595 |
| - " gain=1,\n", |
596 |
| - " log_transform=True,\n", |
597 |
| - " )\n", |
598 |
| - "\n", |
599 |
| - " sc.pl.spatial(\n", |
600 |
| - " a1,\n", |
601 |
| - " color=UTAG_lab,\n", |
602 |
| - " spot_size=12,\n", |
603 |
| - " title=str(img) + \"\\nMPO, CD4, KRT8\",\n", |
604 |
| - " frameon=False,\n", |
605 |
| - " ax=ax[2],\n", |
606 |
| - " show=False,\n", |
607 |
| - " alpha=0,\n", |
608 |
| - " legend_loc=None,\n", |
609 |
| - " )\n", |
610 |
| - " add_scale_box_to_fig(\n", |
611 |
| - " a1.uns[\"spatial\"][\"image\"][\"images\"][\"hires\"], ax[2], box_width=200\n", |
612 |
| - " )\n", |
613 |
| - "\n", |
614 |
| - " sc.pl.spatial(\n", |
615 |
| - " a1,\n", |
616 |
| - " color=UTAG_lab,\n", |
617 |
| - " spot_size=12,\n", |
618 |
| - " title=\"Domain Interaction Graph\",\n", |
619 |
| - " frameon=False,\n", |
620 |
| - " ax=ax[3],\n", |
621 |
| - " alpha_img=0,\n", |
622 |
| - " show=False\n", |
623 |
| - " )\n", |
624 |
| - "\n", |
625 |
| - " plt.savefig(f\"figures/slides/{img}_no_edge.pdf\", bbox_inches=\"tight\")\n", |
626 |
| - " plt.savefig(f\"figures/slides/{img}_no_edge.jpg\", bbox_inches=\"tight\")\n", |
627 |
| - " plt.close()\n", |
628 |
| - " except FileNotFoundError:\n", |
629 |
| - " pass" |
| 450 | + "## Domain Cell Type Proportions and Interaction Analysis" |
630 | 451 | ]
|
631 | 452 | },
|
632 | 453 | {
|
|
4137 | 3958 | },
|
4138 | 3959 | {
|
4139 | 3960 | "cell_type": "code",
|
4140 |
| - "execution_count": 55, |
| 3961 | + "execution_count": null, |
4141 | 3962 | "id": "b097b1e6-3f9b-4bb8-86e4-27c3c0e555bd",
|
4142 | 3963 | "metadata": {},
|
4143 |
| - "outputs": [ |
4144 |
| - { |
4145 |
| - "ename": "SyntaxError", |
4146 |
| - "evalue": "invalid syntax (Temp/ipykernel_24944/844197969.py, line 1)", |
4147 |
| - "output_type": "error", |
4148 |
| - "traceback": [ |
4149 |
| - "\u001b[1;36m File \u001b[1;32m\"C:\\Users\\jkim0\\AppData\\Local\\Temp/ipykernel_24944/844197969.py\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m mport numpy as np\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" |
4150 |
| - ] |
4151 |
| - } |
4152 |
| - ], |
| 3964 | + "outputs": [], |
4153 | 3965 | "source": [
|
4154 |
| - "mport numpy as np\n", |
| 3966 | + "import numpy as np\n", |
4155 | 3967 | "utag_mat = utag.iloc[:, 1:7] # / utag.loc[:,'roi_size'][:,np.newaxis]\n",
|
4156 | 3968 | "cell_type_mat = cell_type.iloc[:, 1:-3] # / cell_type.loc[:,'roi_size'][:,np.newaxis]\n",
|
4157 | 3969 | "utag_mat[\"disease\"] = utag[\"phenotypes\"]\n",
|
|
5058 | 4870 | "name": "python",
|
5059 | 4871 | "nbconvert_exporter": "python",
|
5060 | 4872 | "pygments_lexer": "ipython3",
|
5061 |
| - "version": "3.8.10" |
| 4873 | + "version": "3.8.2" |
5062 | 4874 | },
|
5063 | 4875 | "toc-autonumbering": true
|
5064 | 4876 | },
|
|
0 commit comments