Giter Site home page Giter Site logo

comseg's Introduction

News (16/07/24)

Support

If you have any questions relative to the package or bug, please open an issue in this repository.

ComSeg framework

A detail documentation is available at https://comseg.readthedocs.io/

Single cell spatial RNA profiling

ComSeg is an algorithm for single cell spatial RNA profiling in image-based transcriptomic data.

It takes as input a csv with the spot coordinates and output an anndata object with the genes expression and coordinates of each cell.

Citation

Defard, T., Laporte, H., Ayan, M. et al. A point cloud segmentation framework for image-based spatial transcriptomics. Commun Biol 7, 823 (2024). https://doi.org/10.1038/s42003-024-06480-3

comseg's People

Contributors

tdefa avatar lardenoije avatar

Stargazers

Daniel León-Periñán avatar loic-chadoutaud avatar weize avatar hycai avatar  avatar Istan Ding avatar  avatar Quentin Blampey avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

comseg's Issues

'PCA' object has no attribute 'explained_variance_'

Hi, I am trying to run Comseg in Sopa and get the following error:

       sopa segmentation comseg /work/rwth1209/projects/merfish_segmentation/final_heart_benchmark_2024/methods/cellpose/run_sopa/results/ffpe_comseg/sdata.zarr --patch-dir /work/rwth1209/projects/merfish_segmentation/final_heart_benchmark_2024/methods/cellpose/run_sopa/results/ffpe_comseg/sdata.zarr/.sopa_cache/comseg_boundaries --patch-index 75
        
100%|██████████| 1/1 [00:11<00:00, 11.58s/it]
image name :  transcripts
100%|██████████| 549/549 [01:53<00:00,  4.85it/s]
100%|██████████| 1/1 [01:30<00:00, 90.34s/it]
/work/rwth1209/enviroments/sopa2/lib/python3.10/site-packages/comseg/clustering.py:298: UserWarning: param_sctransform is none, expression vector are not normalized
  warnings.warn('param_sctransform is none, expression vector are not normalized')
improvement of modularity 0.03243277275433021
improvement of modularity 0.004491945689702903
improvement of modularity 0.0007862247392484978
improvement of modularity 9.563138478208e-05
improvement of modularity 2.2354873049357238e-06
number of cluster 14
number of cluster after merging 3
╭───────────────────── Traceback (most recent call last) ──────────────────────╮
│ /work/rwth1209/enviroments/sopa2/lib/python3.10/site-packages/sopa/cli/segme │
│ ntation.py:229 in comseg                                                     │
│                                                                              │
│   226 │   if patch_index is not None:                                        │
│   227 │   │   with open(patch_dir / str(patch_index) / config_name, "r") as  │
│   228 │   │   │   config = json.load(f)                                      │
│ ❱ 229 │   │   comseg_patch(temp_dir=patch_dir, patch_index=patch_index, conf │
│   230 │   else:                                                              │
│   231 │   │   log.warn(                                                      │
│   232 │   │   │   "Running segmentation in a sequential manner. This is not  │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │ _default_boundary_dir = <function _default_boundary_dir at               │ │
│ │                         0x14883325fd00>                                  │ │
│ │          comseg_patch = <function comseg_patch at 0x148756497b50>        │ │
│ │                config = {                                                │ │
│ │                         │   'dict_scale': {'x': 1, 'y': 1, 'z': 1},      │ │
│ │                         │   'mean_cell_diameter': 50,                    │ │
│ │                         │   'max_cell_radius': 100,                      │ │
│ │                         │   'allow_disconnected_polygon': True,          │ │
│ │                         │   'alpha': 0.5,                                │ │
│ │                         │   'min_rna_per_cell': 5,                       │ │
│ │                         │   'gene_column': 'gene',                       │ │
│ │                         │   'norm_vector': False                         │ │
│ │                         }                                                │ │
│ │           config_name = 'config.json'                                    │ │
│ │                     f = <_io.TextIOWrapper                               │ │
│ │                         name='/work/rwth1209/projects/merfish_segmentat… │ │
│ │                         mode='r' encoding='UTF-8'>                       │ │
│ │                  json = <module 'json' from                              │ │
│ │                         '/work/rwth1209/enviroments/sopa2/lib/python3.1… │ │
│ │                   log = <Logger sopa.cli.segmentation (INFO)>            │ │
│ │               logging = <module 'logging' from                           │ │
│ │                         '/work/rwth1209/enviroments/sopa2/lib/python3.1… │ │
│ │             patch_dir = PosixPath('/work/rwth1209/projects/merfish_segm… │ │
│ │           patch_index = 75                                               │ │
│ │                  Path = <class 'pathlib.Path'>                           │ │
│ │            sdata_path = '/work/rwth1209/projects/merfish_segmentation/f… │ │
│ │             SopaFiles = <class 'sopa._constants.SopaFiles'>              │ │
│ │              SopaKeys = <class 'sopa._constants.SopaKeys'>               │ │
│ │                  tqdm = <class 'tqdm.std.tqdm'>                          │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│                                                                              │
│ /work/rwth1209/enviroments/sopa2/lib/python3.10/site-packages/sopa/segmentat │
│ ion/methods.py:117 in comseg_patch                                           │
│                                                                              │
│   114 │   │   mean_cell_diameter=config["mean_cell_diameter"],               │
│   115 │   )                                                                  │
│   116 │                                                                      │
│ ❱ 117 │   Comsegdict.run_all(config=config)                                  │
│   118 │                                                                      │
│   119 │   if "return_polygon" in config:                                     │
│   120 │   │   assert config["return_polygon"] is True, "Only return_polygon= │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │              comseg = <module 'comseg' from                              │ │
│ │                       '/work/rwth1209/enviroments/sopa2/lib/python3.10/… │ │
│ │          Comsegdict = "ComSegDict {'transcripts':                        │ │
│ │                       <comseg.model.ComSegGraph object at                │ │
│ │                       0x148754eefa30>}"                                  │ │
│ │              config = {                                                  │ │
│ │                       │   'dict_scale': {'x': 1, 'y': 1, 'z': 1},        │ │
│ │                       │   'mean_cell_diameter': 50,                      │ │
│ │                       │   'max_cell_radius': 100,                        │ │
│ │                       │   'allow_disconnected_polygon': True,            │ │
│ │                       │   'alpha': 0.5,                                  │ │
│ │                       │   'min_rna_per_cell': 5,                         │ │
│ │                       │   'gene_column': 'gene',                         │ │
│ │                       │   'norm_vector': False                           │ │
│ │                       }                                                  │ │
│ │             dataset = "dataset comseg  ['transcripts']"                  │ │
│ │          dictionary = <module 'comseg.dictionary' from                   │ │
│ │                       '/work/rwth1209/enviroments/sopa2/lib/python3.10/… │ │
│ │                  ds = <module 'comseg.dataset' from                      │ │
│ │                       '/work/rwth1209/enviroments/sopa2/lib/python3.10/… │ │
│ │                json = <module 'json' from                                │ │
│ │                       '/work/rwth1209/enviroments/sopa2/lib/python3.10/… │ │
│ │         patch_index = 75                                                 │ │
│ │ path_dataset_folder = PosixPath('/work/rwth1209/projects/merfish_segmen… │ │
│ │            temp_dir = PosixPath('/work/rwth1209/projects/merfish_segmen… │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│                                                                              │
│ /work/rwth1209/enviroments/sopa2/lib/python3.10/site-packages/comseg/diction │
│ ary.py:571 in run_all                                                        │
│                                                                              │
│   568 │   │                                                                  │
│   569 │   │   self.compute_community_vector(k_nearest_neighbors=k_nearest_ne │
│   570 │   │                                                                  │
│ ❱ 571 │   │   self.compute_insitu_clustering(                                │
│   572 │   │   │   size_commu_min=size_commu_min,                             │
│   573 │   │   │   norm_vector=norm_vector,                                   │
│   574 │   │   │   ### parameter clustering                                   │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │            clustering_method = 'leiden'                                  │ │
│ │                       config = {                                         │ │
│ │                                │   'dict_scale': {                       │ │
│ │                                │   │   'x': 1,                           │ │
│ │                                │   │   'y': 1,                           │ │
│ │                                │   │   'z': 1                            │ │
│ │                                │   },                                    │ │
│ │                                │   'mean_cell_diameter': 50,             │ │
│ │                                │   'max_cell_radius': 100,               │ │
│ │                                │   'allow_disconnected_polygon': True,   │ │
│ │                                │   'alpha': 0.5,                         │ │
│ │                                │   'min_rna_per_cell': 5,                │ │
│ │                                │   'gene_column': 'gene',                │ │
│ │                                │   'norm_vector': False                  │ │
│ │                                }                                         │ │
│ │               file_extension = '.csv'                                    │ │
│ │          k_nearest_neighbors = 10                                        │ │
│ │              max_cell_radius = 100                                       │ │
│ │        min_merge_correlation = 0.8                                       │ │
│ │            n_clusters_kmeans = 4                                         │ │
│ │                  n_neighbors = 20                                        │ │
│ │                        n_pcs = 3                                         │ │
│ │               nb_min_cluster = 0                                         │ │
│ │                  norm_vector = False                                     │ │
│ │ path_dataset_folder_centroid = None                                      │ │
│ │                   resolution = 1                                         │ │
│ │                         self = "ComSegDict {'transcripts':               │ │
│ │                                <comseg.model.ComSegGraph object at       │ │
│ │                                0x148754eefa30>}"                         │ │
│ │               size_commu_min = 3                                         │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│                                                                              │
│ /work/rwth1209/enviroments/sopa2/lib/python3.10/site-packages/comseg/diction │
│ ary.py:281 in compute_insitu_clustering                                      │
│                                                                              │
│   278 │   │   │   classify_mode = "pca"                                      │
│   279 │   │   else:                                                          │
│   280 │   │   │   classify_mode = "euclidien"                                │
│ ❱ 281 │   │   self.in_situ_clustering.classify_small_community(              │
│   282 │   │   │   key_pred=self.clustering_method,                           │
│   283 │   │   │   classify_mode=classify_mode,                               │
│   284 │   │   │   min_proba_small_commu=0, )                                 │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │         classify_mode = 'pca'                                            │ │
│ │     clustering_method = 'leiden'                                         │ │
│ │         merge_cluster = True                                             │ │
│ │ min_merge_correlation = 0.8                                              │ │
│ │     n_clusters_kmeans = 4                                                │ │
│ │               n_comps = 3                                                │ │
│ │           n_neighbors = 20                                               │ │
│ │                 n_pcs = 3                                                │ │
│ │        nb_min_cluster = 0                                                │ │
│ │           norm_vector = False                                            │ │
│ │               palette = None                                             │ │
│ │            resolution = 1                                                │ │
│ │                  self = "ComSegDict {'transcripts':                      │ │
│ │                         <comseg.model.ComSegGraph object at              │ │
│ │                         0x148754eefa30>}"                                │ │
│ │        size_commu_min = 3                                                │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│                                                                              │
│ /work/rwth1209/enviroments/sopa2/lib/python3.10/site-packages/comseg/cluster │
│ ing.py:404 in classify_small_community                                       │
│                                                                              │
│   401 │   │   │                                                              │
│   402 │   │   │   if len(unclassified_vector) > 0 and np.sum(unclassified_ve │
│   403 │   │   │   │   ## classify unclassified community                     │
│ ❱ 404 │   │   │   │   norm_expression_vectors, proba, list_pred_rna_seq = se │
│   405 │   │   │   │   │   array_of_vect=unclassified_vector,                 │
│   406 │   │   │   │   │   pca_model=pca_model,                               │
│   407 │   │   │   │   │   kn_neighb=kn_neighb,                               │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │ bool_index_unclassified = array([ True,  True,  True, ..., False, False, │ │
│ │                           False])                                        │ │
│ │           classify_mode = 'pca'                                          │ │
│ │             components_ = array([[ 4.80786221e-03, -2.55749067e-04,      │ │
│ │                           1.09719959e-03, ...,                           │ │
│ │                           │   │    1.26593392e-03,  1.06963687e-02,      │ │
│ │                           3.56953394e-04],                               │ │
│ │                           │      [ 1.94754449e-02,  1.51023755e-03,      │ │
│ │                           -8.65052371e-06, ...,                          │ │
│ │                           │   │    1.05369599e-03, -1.80849317e-03,      │ │
│ │                           1.58422214e-04],                               │ │
│ │                           │      [-2.16752469e-02, -3.86102166e-04,      │ │
│ │                           -5.38286748e-03, ...,                          │ │
│ │                           │   │   -1.36155919e-03, -3.45688662e-02,      │ │
│ │                           1.14200557e-03]])                              │ │
│ │      index_unclassified = array([   0,    1,    2,    4,    5,    6,     │ │
│ │                           7,    8,    9,   10,   11,                     │ │
│ │                           │   │    12,   13,   15,   16,   17,   18,     │ │
│ │                           19,   20,   21,   22,   25,                    │ │
│ │                           │   │    26,   27,   28,   29,   30,   31,     │ │
│ │                           32,   33,   35,   36,   37,                    │ │
│ │                           │   │    38,   39,   40,   41,   43,   44,     │ │
│ │                           45,   46,   47,   49,   50,                    │ │
│ │                           │   │    53,   55,   56,   57,   58,   59,     │ │
│ │                           60,   61,   62,   63,   64,                    │ │
│ │                           │   │    65,   66,   67,   68,   69,   70,     │ │
│ │                           71,   72,   73,   74,   76,                    │ │
│ │                           │   │    77,   78,   79,   80,   81,   82,     │ │
│ │                           83,   85,   86,   87,   88,                    │ │
│ │                           │   │    89,   90,   91,   92,   94,   95,     │ │
│ │                           96,   97,   98,   99,  100,                    │ │
│ │                           │   │   102,  103,  104,  105,  106,  107,     │ │
│ │                           108,  109,  112,  113,  114,                   │ │
│ │                           │   │   116,  117,  118,  119,  120,  121,     │ │
│ │                           122,  123,  124,  125,  126,                   │ │
│ │                           │   │   127,  128,  129,  130,  131,  132,     │ │
│ │                           134,  137,  138,  140,  141,                   │ │
│ │                           │   │   142,  143,  144,  145,  146,  147,     │ │
│ │                           148,  149,  150,  151,  152,                   │ │
│ │                           │   │   153,  155,  156,  157,  158,  160,     │ │
│ │                           161,  163,  164,  165,  166,                   │ │
│ │                           │   │   167,  168,  169,  170,  172,  173,     │ │
│ │                           175,  176,  177,  178,  179,                   │ │
│ │                           │   │   180,  181,  182,  183,  184,  185,     │ │
│ │                           186,  187,  188,  189,  190,                   │ │
│ │                           │   │   191,  192,  193,  195,  196,  197,     │ │
│ │                           198,  199,  201,  202,  204,                   │ │
│ │                           │   │   205,  207,  208,  209,  210,  211,     │ │
│ │                           212,  213,  214,  215,  216,                   │ │
│ │                           │   │   217,  218,  219,  220,  221,  222,     │ │
│ │                           223,  224,  225,  226,  228,                   │ │
│ │                           │   │   229,  230,  231,  232,  233,  234,     │ │
│ │                           235,  236,  237,  239,  240,                   │ │
│ │                           │   │   241,  242,  243,  245,  247,  248,     │ │
│ │                           249,  250,  251,  252,  253,                   │ │
│ │                           │   │   254,  255,  256,  257,  258,  259,     │ │
│ │                           260,  261,  264,  265,  267,                   │ │
│ │                           │   │   268,  269,  270,  271,  272,  273,     │ │
│ │                           274,  275,  276,  277,  278,                   │ │
│ │                           │   │   279,  280,  281,  284,  285,  286,     │ │
│ │                           287,  288,  289,  290,  291,                   │ │
│ │                           │   │   292,  293,  294,  295,  296,  297,     │ │
│ │                           298,  299,  300,  301,  302,                   │ │
│ │                           │   │   303,  304,  305,  306,  307,  308,     │ │
│ │                           309,  310,  311,  313,  314,                   │ │
│ │                           │   │   315,  316,  317,  318,  320,  321,     │ │
│ │                           322,  323,  324,  325,  326,                   │ │
│ │                           │   │   327,  328,  329,  330,  331,  332,     │ │
│ │                           333,  334,  335,  336,  337,                   │ │
│ │                           │   │   338,  339,  340,  341,  342,  343,     │ │
│ │                           344,  345,  346,  347,  348,                   │ │
│ │                           │   │   349,  350,  351,  352,  353,  354,     │ │
│ │                           355,  356,  357,  358,  359,                   │ │
│ │                           │   │   360,  361,  362,  363,  364,  366,     │ │
│ │                           367,  368,  369,  372,  373,                   │ │
│ │                           │   │   374,  375,  376,  377,  379,  380,     │ │
│ │                           382,  383,  384,  386,  387,                   │ │
│ │                           │   │   388,  389,  390,  391,  392,  394,     │ │
│ │                           395,  396,  397,  398,  399,                   │ │
│ │                           │   │   400,  402,  403,  404,  405,  406,     │ │
│ │                           407,  409,  410,  411,  412,                   │ │
│ │                           │   │   413,  414,  415,  416,  417,  418,     │ │
│ │                           419,  420,  421,  422,  423,                   │ │
│ │                           │   │   424,  425,  427,  428,  429,  430,     │ │
│ │                           431,  432,  433,  434,  436,                   │ │
│ │                           │   │   437,  438,  439,  440,  441,  443,     │ │
│ │                           444,  445,  447,  448,  450,                   │ │
│ │                           │   │   451,  452,  454,  455,  456,  457,     │ │
│ │                           458,  459,  460,  464,  465,                   │ │
│ │                           │   │   466,  467,  468,  469,  470,  471,     │ │
│ │                           473,  474,  475,  477,  478,                   │ │
│ │                           │   │   479,  480,  481,  482,  483,  484,     │ │
│ │                           485,  486,  487,  488,  489,                   │ │
│ │                           │   │   490,  492,  493,  494,  495,  496,     │ │
│ │                           497,  498,  500,  501,  502,                   │ │
│ │                           │   │   503,  504,  505,  506,  507,  508,     │ │
│ │                           510,  511,  512,  513,  514,                   │ │
│ │                           │   │   515,  516,  517,  518,  519,  520,     │ │
│ │                           521,  522,  523,  524,  525,                   │ │
│ │                           │   │   526,  527,  528,  530,  531,  532,     │ │
│ │                           533,  534,  995, 1103, 1201,                   │ │
│ │                           │      1211, 1219])                            │ │
│ │                key_pred = 'leiden_merged'                                │ │
│ │               kn_neighb = KNeighborsClassifier(n_neighbors=10,           │ │
│ │                           weights='distance')                            │ │
│ │   min_proba_small_commu = 0                                              │ │
│ │               pca_model = PCA(n_components=3)                            │ │
│ │                    self = <comseg.clustering.InSituClustering object at  │ │
│ │                           0x14875cf2b8e0>                                │ │
│ │     unclassified_vector = array([[1.04811707, 0.        , 0.        ,    │ │
│ │                           ..., 0.        , 0.24732749,                   │ │
│ │                           │   │   0.        ],                           │ │
│ │                           │      [0.        , 0.65930151, 0.        ,    │ │
│ │                           ..., 0.        , 0.18003074,                   │ │
│ │                           │   │   0.        ],                           │ │
│ │                           │      [0.91672206, 0.        , 0.        ,    │ │
│ │                           ..., 0.        , 0.        ,                   │ │
│ │                           │   │   0.        ],                           │ │
│ │                           │      ...,                                    │ │
│ │                           │      [0.        , 0.        , 0.        ,    │ │
│ │                           ..., 0.        , 0.        ,                   │ │
│ │                           │   │   0.        ],                           │ │
│ │                           │      [0.65846223, 0.30354829, 0.17145903,    │ │
│ │                           ..., 0.        , 0.        ,                   │ │
│ │                           │   │   0.        ],                           │ │
│ │                           │      [0.02120467, 0.        , 0.        ,    │ │
│ │                           ..., 0.        , 0.68621713,                   │ │
│ │                           │   │   0.        ]])                          │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│                                                                              │
│ /work/rwth1209/enviroments/sopa2/lib/python3.10/site-packages/comseg/cluster │
│ ing.py:317 in classify_by_nn                                                 │
│                                                                              │
│   314 │   │                                                                  │
│   315 │   │   if pca_model is not None:                                      │
│   316 │   │   │   list_boll_nan = np.sum(np.isnan(norm_expression_vectors),  │
│ ❱ 317 │   │   │   projected_vect = pca_model.transform(norm_expression_vecto │
│   318 │   │   else:                                                          │
│   319 │   │   │   list_boll_nan = np.sum(np.isnan(norm_expression_vectors),  │
│   320 │   │   │   projected_vect = norm_expression_vectors[list_boll_nan]    │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │           array_of_vect = array([[1.04811707, 0.        , 0.        ,    │ │
│ │                           ..., 0.        , 0.24732749,                   │ │
│ │                           │   │   0.        ],                           │ │
│ │                           │      [0.        , 0.65930151, 0.        ,    │ │
│ │                           ..., 0.        , 0.18003074,                   │ │
│ │                           │   │   0.        ],                           │ │
│ │                           │      [0.91672206, 0.        , 0.        ,    │ │
│ │                           ..., 0.        , 0.        ,                   │ │
│ │                           │   │   0.        ],                           │ │
│ │                           │      ...,                                    │ │
│ │                           │      [0.        , 0.        , 0.        ,    │ │
│ │                           ..., 0.        , 0.        ,                   │ │
│ │                           │   │   0.        ],                           │ │
│ │                           │      [0.65846223, 0.30354829, 0.17145903,    │ │
│ │                           ..., 0.        , 0.        ,                   │ │
│ │                           │   │   0.        ],                           │ │
│ │                           │      [0.02120467, 0.        , 0.        ,    │ │
│ │                           ..., 0.        , 0.68621713,                   │ │
│ │                           │   │   0.        ]])                          │ │
│ │               kn_neighb = KNeighborsClassifier(n_neighbors=10,           │ │
│ │                           weights='distance')                            │ │
│ │           list_boll_nan = array([ True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True,  True,  True,                     │ │
│ │                           │   │   True,  True,  True,  True,  True,      │ │
│ │                           True,  True])                                  │ │
│ │               min_proba = 0                                              │ │
│ │ norm_expression_vectors = array([[1.04811707, 0.        , 0.        ,    │ │
│ │                           ..., 0.        , 0.24732749,                   │ │
│ │                           │   │   0.        ],                           │ │
│ │                           │      [0.        , 0.65930151, 0.        ,    │ │
│ │                           ..., 0.        , 0.18003074,                   │ │
│ │                           │   │   0.        ],                           │ │
│ │                           │      [0.91672206, 0.        , 0.        ,    │ │
│ │                           ..., 0.        , 0.        ,                   │ │
│ │                           │   │   0.        ],                           │ │
│ │                           │      ...,                                    │ │
│ │                           │      [0.        , 0.        , 0.        ,    │ │
│ │                           ..., 0.        , 0.        ,                   │ │
│ │                           │   │   0.        ],                           │ │
│ │                           │      [0.65846223, 0.30354829, 0.17145903,    │ │
│ │                           ..., 0.        , 0.        ,                   │ │
│ │                           │   │   0.        ],                           │ │
│ │                           │      [0.02120467, 0.        , 0.        ,    │ │
│ │                           ..., 0.        , 0.68621713,                   │ │
│ │                           │   │   0.        ]])                          │ │
│ │       param_sctransform = None                                           │ │
│ │               pca_model = PCA(n_components=3)                            │ │
│ │                    self = <comseg.clustering.InSituClustering object at  │ │
│ │                           0x14875cf2b8e0>                                │ │
│ │                warnings = <module 'warnings' from                        │ │
│ │                           '/work/rwth1209/enviroments/sopa2/lib/python3… │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│                                                                              │
│ /work/rwth1209/enviroments/sopa2/lib/python3.10/site-packages/sklearn/utils/ │
│ _set_output.py:313 in wrapped                                                │
│                                                                              │
│   310 │                                                                      │
│   311 │   @wraps(f)                                                          │
│   312 │   def wrapped(self, X, *args, **kwargs):                             │
│ ❱ 313 │   │   data_to_wrap = f(self, X, *args, **kwargs)                     │
│   314 │   │   if isinstance(data_to_wrap, tuple):                            │
│   315 │   │   │   # only wrap the first output for cross decomposition       │
│   316 │   │   │   return_tuple = (                                           │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │   args = ()                                                              │ │
│ │      f = <function _BasePCA.transform at 0x1487553bf1c0>                 │ │
│ │ kwargs = {}                                                              │ │
│ │ method = 'transform'                                                     │ │
│ │   self = PCA(n_components=3)                                             │ │
│ │      X = array([[1.04811707, 0.        , 0.        , ..., 0.        ,    │ │
│ │          0.24732749,                                                     │ │
│ │          │   │   0.        ],                                            │ │
│ │          │      [0.        , 0.65930151, 0.        , ..., 0.        ,    │ │
│ │          0.18003074,                                                     │ │
│ │          │   │   0.        ],                                            │ │
│ │          │      [0.91672206, 0.        , 0.        , ..., 0.        , 0. │ │
│ │          ,                                                               │ │
│ │          │   │   0.        ],                                            │ │
│ │          │      ...,                                                     │ │
│ │          │      [0.        , 0.        , 0.        , ..., 0.        , 0. │ │
│ │          ,                                                               │ │
│ │          │   │   0.        ],                                            │ │
│ │          │      [0.65846223, 0.30354829, 0.17145903, ..., 0.        , 0. │ │
│ │          ,                                                               │ │
│ │          │   │   0.        ],                                            │ │
│ │          │      [0.02120467, 0.        , 0.        , ..., 0.        ,    │ │
│ │          0.68621713,                                                     │ │
│ │          │   │   0.        ]])                                           │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│                                                                              │
│ /work/rwth1209/enviroments/sopa2/lib/python3.10/site-packages/sklearn/decomp │
│ osition/_base.py:139 in transform                                            │
│                                                                              │
│   136 │   │   │   Projection of X in the first principal components, where ` │
│   137 │   │   │   is the number of samples and `n_components` is the number  │
│   138 │   │   """                                                            │
│ ❱ 139 │   │   xp, _ = get_namespace(X, self.components_, self.explained_vari │
│   140 │   │                                                                  │
│   141 │   │   check_is_fitted(self)                                          │
│   142                                                                        │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │ self = PCA(n_components=3)                                               │ │
│ │    X = array([[1.04811707, 0.        , 0.        , ..., 0.        ,      │ │
│ │        0.24732749,                                                       │ │
│ │        │   │   0.        ],                                              │ │
│ │        │      [0.        , 0.65930151, 0.        , ..., 0.        ,      │ │
│ │        0.18003074,                                                       │ │
│ │        │   │   0.        ],                                              │ │
│ │        │      [0.91672206, 0.        , 0.        , ..., 0.        , 0.   │ │
│ │        ,                                                                 │ │
│ │        │   │   0.        ],                                              │ │
│ │        │      ...,                                                       │ │
│ │        │      [0.        , 0.        , 0.        , ..., 0.        , 0.   │ │
│ │        ,                                                                 │ │
│ │        │   │   0.        ],                                              │ │
│ │        │      [0.65846223, 0.30354829, 0.17145903, ..., 0.        , 0.   │ │
│ │        ,                                                                 │ │
│ │        │   │   0.        ],                                              │ │
│ │        │      [0.02120467, 0.        , 0.        , ..., 0.        ,      │ │
│ │        0.68621713,                                                       │ │
│ │        │   │   0.        ]])                                             │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────╯

AttributeError: 'PCA' object has no attribute 'explained_variance_'

Any idea what is going wrong?

My comseg settings for Sopa:

  comseg:
    min_area: 10
    config:
      dict_scale:
        x: 1
        y: 1
        z: 1
      mean_cell_diameter: 50
      max_cell_radius: 100
      allow_disconnected_polygon : true
      alpha: 0.5
      min_rna_per_cell: 5
      gene_column: "gene"
      norm_vector: false 

Name: scikit-learn
Version: 1.5.1

Typo in function get_anndata_from_result

Describe the typo
There is a typo in the function get_anndata_from_result in the comseg/model.py file.

Location of the typo

  • File: comseg/model.py
  • Function: get_anndata_from_result
  • Line: 851

Incorrect text
The parameter allow_disconnected_polygone is misspelled

Correct text
The correct spelling should be allow_disconnected_polygon.

Additional context
This typo causes a NameError when trying to use the allow_disconnected_polygon parameter.

Tutorial data - divide by zero encountered in log10

Thanks for the tool.
I am trying to follow the tutorial, however I receive the following error during the compute_insitu_clustering step:

Running scTransform via Rscript...

Attaching package: arrow

The following objects are masked from package:feather:

    read_feather, write_feather

The following object is masked from package:utils:

    timestamp

Calculating cell attributes from input UMI matrix: log_umi
Variance stabilizing transformation of count matrix of size 13 by 470
Model formula is y ~ log_umi
Get Negative Binomial regression parameters per gene
Using 13 genes, 470 cells
  |======================================================================| 100%
Second step: Get residuals using fitted parameters for 13 genes
  |======================================================================| 100%
Calculating gene attributes
Wall clock passed: Time difference of 0.5148628 secs
Reading output files...
Clipping residuals...
 TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm
number of cluster 7
0
1
2
3
4
5
6
number of cluster after merging 8
[/work/rwth1209/enviroments/comseg/lib/python3.8/site-packages/comseg/utils/preprocessing.py:41]: RuntimeWarning: divide by zero encountered in log10
  regressor_data[:, 1] = np.log10(np.sum(array_of_vect, axis=1))

another error TypeError: np.matrix is not supported. Please convert to a numpy array with np.asarray. For more information see: https://numpy.org/doc/stable/reference/generated/numpy.matrix.html also pops up.

Any ideas?

Invalid shape for Image Data Error

Hello, excited to try out this method. I'm currently adapting the 'minimal example' from the docs to 4 sections. My data consists of 4 tiffs with DAPI staining, and 4 csv files with x,y,z coords and gene names. I've manually added in the 'in_nucleus' column with all values set to 0 due to no prior, as per the documents instructions.

I'm having trouble visualizing the cells afterwords with the plot_result function:

from comseg.utils import plot

img_name = "32917-slide7_A1-1_DAPI"
G = Comsegdict[img_name].G
nuclei = tifffile.imread(
    path_to_mask_prior + f'/{img_name}.tiff')

plot.plot_result(G=G,
            nuclei = nuclei,
               key_node = 'cell_index_pred',
                title = None,
                dico_cell_color = None,
                figsize=(15, 15),
                spots_size = 10,
                plot_outlier = False)

This error occurs:

TypeError: Invalid shape (4288,) for image data

Traced specifically to:

ax.imshow(mip_nuclei > 0, cmap='gist_gray', alpha=0.8)
if data is None:
    return func(ax, *map(sanitize_sequence, args), **kwargs)
...
im.set_data(X)

And after doing some digging through the source code, I can't seem to figure out what the image data is, or why the error is occurring to begin with. I'm assuming it's the pixel length of the tiff image. Despite the error, it still overlays cell_index_pred over the tiff I feed it. Though, I can't make sense of it- and the cells seem more chaotic than the initial DAPI stain would imply.

Image for reference:
slide7_A_try_1

Probably user error on my part, but I'd appreciate any help you guys can provide. Is it a soft-requirement to run cellpose as a prior? Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.