@@ -721,141 +721,6 @@ def plot_overview(self):
721
721
722
722
plt .suptitle ('Selected Expression Densities:' , fontsize = 18 )
723
723
724
- # def plot_radial_distribution(self, n_neighbors=30, **kwargs):
725
- # # distances, _, _ = self.knn(n_neighbors=n_neighbors)
726
- # self.graph.update_knn(n_neighbors=n_neighbors)
727
- # distances = self.graph.distances
728
- # plt.hist(distances[:, 1:n_neighbors].flatten(), **kwargs)
729
-
730
- # def spatial_decomposition(
731
- # self,
732
- # mRNAs_center=None,
733
- # mRNAs_neighbor=None,
734
- # n_neighbors=10,
735
- # ):
736
-
737
- # if mRNAs_center is None:
738
- # mRNAs_center = self.genes
739
- # if mRNAs_neighbor is None:
740
- # mRNAs_neighbor = self.genes
741
-
742
- # self.graph.update_knn(n_neighbors=n_neighbors)
743
- # neighbors = self.graph.neighbors
744
- # # np.array(self.gene_ids)[neighbors]
745
- # neighbor_classes = self.graph.neighbor_types
746
-
747
- # pptx = []
748
- # ppty = []
749
- # clrs = []
750
- # intensity = []
751
-
752
- # out = np.zeros((30, 30, len(self.genes)))
753
-
754
- # mask_center = np.logical_or.reduce(
755
- # [neighbor_classes[:, 0] == self.get_id(m) for m in mRNAs_center])
756
-
757
- # for i_n_neighbor in range(1, n_neighbors):
758
-
759
- # mask_neighbor = np.logical_or.reduce([
760
- # neighbor_classes[:, i_n_neighbor] == self.get_id(m)
761
- # for m in mRNAs_neighbor
762
- # ])
763
-
764
- # mask_combined = np.logical_and(mask_center, mask_neighbor)
765
-
766
- # for i_neighbor, n in enumerate(neighbors[mask_combined]):
767
-
768
- # xs = np.array(self.x.iloc[n])
769
- # ys = np.array(self.y.iloc[n])
770
-
771
- # x_centered = xs - xs[0]
772
- # y_centered = ys - ys[0]
773
-
774
- # loc_neighbor = np.array(
775
- # (x_centered[i_n_neighbor], y_centered[i_n_neighbor]))
776
- # loc_neighbor_normalized = loc_neighbor / (loc_neighbor **
777
- # 2).sum()**0.5
778
-
779
- # rotation_matrix = np.array(
780
- # [[loc_neighbor_normalized[1], -loc_neighbor_normalized[0]],
781
- # [loc_neighbor_normalized[0], loc_neighbor_normalized[1]]])
782
-
783
- # rotated_spots = np.inner(
784
- # np.array([x_centered, y_centered]).T, rotation_matrix).T
785
-
786
- # # we want to exclude the central and n_neighbor spots:
787
- # mask = np.arange(rotated_spots.shape[1])
788
- # mask = (mask > 1) & (mask != (i_n_neighbor))
789
-
790
- # # # plt.scatter(rotated[0][mask],rotated[1][mask])
791
-
792
- # pptx.append(rotated_spots[0][mask])
793
- # ppty.append(rotated_spots[1][mask])
794
- # clrs.append(self.gene_ids.iloc[n][mask])
795
-
796
- # pptx = np.concatenate(pptx)
797
- # ppty = np.concatenate(ppty)
798
-
799
- # pptt = np.arctan(pptx / ppty)
800
- # pptr = (pptx**2 + ppty**2)**0.5
801
-
802
- # clrs = np.concatenate(clrs)
803
-
804
- # scale = pptr.max()
805
- # for i in range(len(mRNAs_neighbor)):
806
- # mask = clrs==i
807
- # out[(pptt[mask]/1.5*100).astype(int),(pptr[mask]/scale*100).astype(int),i]+=1
808
-
809
- # plt.axhline(0)
810
- # plt.axvline(0)
811
- # plt.scatter(pptt, pptr, c=clrs, cmap='nipy_spectral', alpha=0.1, s=3)
812
-
813
- # return (pptt, pptr, clrs,)
814
-
815
- # def knn_clean(
816
- # self,
817
- # n_neighbors=10,
818
- # ):
819
- # # distances, indices, types = self.knn(n_neighbors=n_neighbors)
820
- # self.graph.update_knn(n_neighbors=n_neighbors)
821
- # types = self.graph.neighbor_types
822
- # count_matrix = sparse.lil_matrix(
823
- # (types.shape[0], self.genes.shape[0]))
824
- # for i, t in enumerate(types):
825
- # classes, counts = (np.unique(t[:n_neighbors], return_counts=True))
826
- # count_matrix[i, classes] = counts / counts.sum()
827
-
828
- # count_matrix = count_matrix.tocsr()
829
-
830
- # count_matrix_log = count_matrix.copy()
831
- # count_matrix_log.data = np.log(count_matrix.data)
832
- # count_matrix_inv = count_matrix.copy()
833
- # count_matrix_inv.data = 1 / (count_matrix.data)
834
-
835
- # prototypes = np.zeros((len(self.genes), ) * 2)
836
- # for i in range(prototypes.shape[0]):
837
- # prototypes[i] = count_matrix[self.gene_ids == i].sum(0)
838
- # prototypes /= prototypes.sum(0)
839
-
840
- # Dkl = count_matrix.copy()
841
-
842
- # for i in range(prototypes.shape[0]):
843
- # inter = Dkl[self.gene_ids == i]
844
- # inter.data = count_matrix[self.gene_ids == i].data * (np.log(
845
- # (count_matrix_inv[self.gene_ids == i].multiply(
846
- # prototypes[i])).data))
847
- # Dkl[self.gene_ids == i] = inter
848
- # Dkl = -np.array(Dkl.sum(1)).flatten()
849
- # Dkl[np.isinf(Dkl)] = 0
850
-
851
- # return Dkl
852
-
853
- # def scatter_celltype_affinities(self,
854
- # adata,
855
- # celltypes_1,
856
- # celltypes_2=None):
857
- # adata, sdata = synchronize(adata, self)
858
-
859
724
def squidpy (self ):
860
725
# obs={"cluster":self.gene_id.astype('category')}
861
726
obsm = {"spatial" : np .array (self .coordinates )}
@@ -973,3 +838,5 @@ def sorted_bar_compare(stat1, stat2, kwargs1={}, kwargs2={}):
973
838
ax3 .xaxis .set_label_position ('top' )
974
839
# ax3.set_ylabel('log(count) spatial')
975
840
return (ax1 , ax2 , ax3 )
841
+
842
+
0 commit comments