BiomedicalMachineLearning / stLearn

A novel machine learning pipeline to analyse spatial transcriptomics data
Other
176 stars 23 forks source link

Installation issues on linux machine #291

Open chiwwong opened 2 months ago

chiwwong commented 2 months ago

I use conda for managing packages but the stLearn seems to have some dependencies (numpy >1.18, <1.22) that were outdated, while I used numpy=1.26.4.

conda install -c conda-forge stlearn=0.4.11
Channels:
 - conda-forge
 - bioconda
 - defaults
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: - warning  libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE
failed

LibMambaUnsatisfiableError: Encountered problems while solving:
  - package stlearn-0.4.11-pyhd8ed1ab_0 requires numpy >=1.18,<1.22, but none of the providers can be installed

Could not solve for environment specs
The following packages are incompatible
├─ pin-1 is installable and it requires
│  └─ python 3.12.* , which can be installed;
└─ stlearn 0.4.11**  is not installable because it requires
   └─ numpy >=1.18,<1.22  but there are no viable options
      ├─ numpy [1.18.1|1.18.4|...|1.19.5] would require
      │  └─ python >=3.6,<3.7.0a0 , which conflicts with any installable versions previously reported;
      ├─ numpy [1.18.1|1.18.4|...|1.21.6] would require
      │  └─ python >=3.7,<3.8.0a0 , which conflicts with any installable versions previously reported;
      ├─ numpy [1.18.1|1.18.4|...|1.21.6] would require
      │  └─ python >=3.8,<3.9.0a0 , which conflicts with any installable versions previously reported;
      ├─ numpy [1.19.2|1.19.4|...|1.21.6] would require
      │  └─ python >=3.9,<3.10.0a0 , which conflicts with any installable versions previously reported;
      └─ numpy [1.21.2|1.21.3|1.21.4|1.21.5|1.21.6] would require
         └─ python >=3.10,<3.11.0a0 , which conflicts with any installable versions previously reported.

Pins seem to be involved in the conflict. Currently pinned specs:
 - python 3.12.* (labeled as 'pin-1')

But I can confirm a successful installation after forcing the python back to 3.10 (from 3.12.2).

duypham2108 commented 2 months ago

Thank you for reporting it. We will update all the dependencies soon

chiwwong commented 2 months ago

@duypham2108 I would also like to know how to save the PSTS analysis with adata. The following code does not work: adata.write_h5ad("adata_after_StLean_PSTS.h5ad",compression='gzip')


TypeError Traceback (most recent call last) File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_io/utils.py:246, in report_write_key_on_error..func_wrapper(*args, *kwargs) 245 try: --> 246 return func(args, **kwargs) 247 except Exception as e:

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_io/specs/registry.py:280, in Writer.write_elem(self, store, k, elem, dataset_kwargs, modifiers) 279 # Normalize k to abosulte path --> 280 if not PurePosixPath(k).is_absolute(): 281 k = str(PurePosixPath(store.name) / k)

File /miniconda3/envs/spatial.p/lib/python3.8/pathlib.py:651, in PurePath.new(cls, *args) 650 cls = PureWindowsPath if os.name == 'nt' else PurePosixPath --> 651 return cls._from_parts(args)

File /miniconda3/envs/spatial.p/lib/python3.8/pathlib.py:683, in PurePath._from_parts(cls, args, init) 682 self = object.new(cls) --> 683 drv, root, parts = self._parse_args(args) 684 self._drv = drv

File /miniconda3/envs/spatial.p/lib/python3.8/pathlib.py:667, in PurePath._parse_args(cls, args) 666 else: --> 667 a = os.fspath(a) 668 if isinstance(a, str): 669 # Force-cast str subclasses to str (issue #21127)

TypeError: expected str, bytes or os.PathLike object, not int

The above exception was the direct cause of the following exception:

TypeError Traceback (most recent call last) Cell In[67], line 1 ----> 1 adata.write_h5ad("adata_after_StLean_PSTS.h5ad",compression='gzip')

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_core/anndata.py:1959, in AnnData.write_h5ad(self, filename, compression, compression_opts, as_dense) 1956 if filename is None: 1957 filename = self.filename -> 1959 _write_h5ad( 1960 Path(filename), 1961 self, 1962 compression=compression, 1963 compression_opts=compression_opts, 1964 as_dense=as_dense, 1965 ) 1967 if self.isbacked: 1968 self.file.filename = filename

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_io/h5ad.py:99, in write_h5ad(filepath, adata, as_dense, dataset_kwargs, **kwargs) 97 write_elem(f, "varp", dict(adata.varp), dataset_kwargs=dataset_kwargs) 98 write_elem(f, "layers", dict(adata.layers), dataset_kwargs=dataset_kwargs) ---> 99 write_elem(f, "uns", dict(adata.uns), dataset_kwargs=dataset_kwargs)

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_io/specs/registry.py:353, in write_elem(store, k, elem, dataset_kwargs) 329 def write_elem( 330 store: GroupStorageType, 331 k: str, (...) 334 dataset_kwargs: Mapping = MappingProxyType({}), 335 ) -> None: 336 """ 337 Write an element to a storage group using anndata encoding. 338 (...) 351 E.g. for zarr this would be chunks, compressor. 352 """ --> 353 Writer(_REGISTRY).write_elem(store, k, elem, dataset_kwargs=dataset_kwargs)

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_io/utils.py:248, in report_write_key_on_error..func_wrapper(*args, *kwargs) 246 return func(args, **kwargs) 247 except Exception as e: --> 248 re_raise_error(e, elem, key)

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_io/utils.py:246, in report_write_key_on_error..func_wrapper(*args, *kwargs) 244 break 245 try: --> 246 return func(args, **kwargs) 247 except Exception as e: 248 re_raise_error(e, elem, key)

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_io/specs/registry.py:311, in Writer.write_elem(self, store, k, elem, dataset_kwargs, modifiers) 302 return self.callback( 303 write_func, 304 store, (...) 308 iospec=self.registry.get_spec(elem), 309 ) 310 else: --> 311 return write_func(store, k, elem, dataset_kwargs=dataset_kwargs)

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_io/specs/registry.py:52, in write_spec..decorator..wrapper(g, k, *args, kwargs) 50 @wraps(func) 51 def wrapper(g, k, *args, *kwargs): ---> 52 result = func(g, k, args, kwargs) 53 g[k].attrs.setdefault("encoding-type", spec.encoding_type) 54 g[k].attrs.setdefault("encoding-version", spec.encoding_version)

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_io/specs/methods.py:281, in write_mapping(f, k, v, _writer, dataset_kwargs) 279 g = f.create_group(k) 280 for sub_k, sub_v in v.items(): --> 281 _writer.write_elem(g, sub_k, sub_v, dataset_kwargs=dataset_kwargs)

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_io/utils.py:248, in report_write_key_on_error..func_wrapper(*args, *kwargs) 246 return func(args, **kwargs) 247 except Exception as e: --> 248 re_raise_error(e, elem, key)

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_io/utils.py:246, in report_write_key_on_error..func_wrapper(*args, *kwargs) 244 break 245 try: --> 246 return func(args, **kwargs) 247 except Exception as e: 248 re_raise_error(e, elem, key)

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_io/specs/registry.py:311, in Writer.write_elem(self, store, k, elem, dataset_kwargs, modifiers) 302 return self.callback( 303 write_func, 304 store, (...) 308 iospec=self.registry.get_spec(elem), 309 ) 310 else: --> 311 return write_func(store, k, elem, dataset_kwargs=dataset_kwargs)

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_io/specs/registry.py:52, in write_spec..decorator..wrapper(g, k, *args, kwargs) 50 @wraps(func) 51 def wrapper(g, k, *args, *kwargs): ---> 52 result = func(g, k, args, kwargs) 53 g[k].attrs.setdefault("encoding-type", spec.encoding_type) 54 g[k].attrs.setdefault("encoding-version", spec.encoding_version)

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_io/specs/methods.py:281, in write_mapping(f, k, v, _writer, dataset_kwargs) 279 g = f.create_group(k) 280 for sub_k, sub_v in v.items(): --> 281 _writer.write_elem(g, sub_k, sub_v, dataset_kwargs=dataset_kwargs)

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_io/utils.py:248, in report_write_key_on_error..func_wrapper(*args, *kwargs) 246 return func(args, **kwargs) 247 except Exception as e: --> 248 re_raise_error(e, elem, key)

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/anndata/_io/utils.py:229, in report_write_key_on_error..re_raise_error(e, elem, key) 227 else: 228 parent = _get_parent(elem) --> 229 raise type(e)( 230 f"{e}\n\n" 231 f"Above error raised while writing key {key!r} of {type(elem)} " 232 f"to {parent}" 233 ) from e

TypeError: expected str, bytes or os.PathLike object, not int

Above error raised while writing key 6 of <class 'h5py._hl.group.Group'> to /

chiwwong commented 2 months ago

I found that the clade ID can be saved but not the arrows. Maybe something else is not saved too, but not sure.

(Sorry, I have recently joined the Python family from R, not very sure how to debug Python yet).

adata = sc.read_h5ad('adata_after_StLean_PSTS.h5ad')
st.pl.cluster_plot(
    adata,
    use_label="leiden",
    show_trajectories=True,
    list_clusters=["0","2"],
    show_subcluster=True,
    zoom_coord=[4500,7000,6500,4000],
    show_node=False
)

ValueError Traceback (most recent call last) Cell In[9], line 1 ----> 1 st.pl.cluster_plot( 2 adata, 3 use_label="leiden", 4 show_trajectories=True, 5 list_clusters=["0","2"], 6 show_subcluster=True, 7 zoom_coord=[4500,7000,6500,4000], 8 show_node=False 9 )

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/stlearn/plotting/cluster_plot.py:87, in cluster_plot(adata, title, figsize, cmap, use_label, list_clusters, ax, fig, show_plot, show_axis, show_image, show_color_bar, zoom_coord, crop, margin, size, image_alpha, cell_alpha, fname, dpi, show_subcluster, show_cluster_labels, show_trajectories, reverse, show_node, threshold_spots, text_box_size, color_bar_size, bbox_to_anchor, trajectory_node_size, trajectory_alpha, trajectory_width, trajectory_edge_color, trajectory_arrowsize) 65 """\ 66 Allows the visualization of a cluster results as the discretes values 67 of dot points in the Spatial transcriptomics array. We also support to (...) 82 83 """ 85 assert use_label != None, "Please select use_label parameter" ---> 87 ClusterPlot( 88 adata, 89 title=title, 90 figsize=figsize, 91 cmap=cmap, 92 use_label=use_label, 93 list_clusters=list_clusters, 94 ax=ax, 95 fig=fig, 96 show_plot=show_plot, 97 show_axis=show_axis, 98 show_image=show_image, 99 show_color_bar=show_color_bar, 100 zoom_coord=zoom_coord, 101 crop=crop, 102 margin=margin, 103 size=size, 104 image_alpha=image_alpha, 105 cell_alpha=cell_alpha, 106 fname=fname, 107 dpi=dpi, 108 show_subcluster=show_subcluster, 109 show_cluster_labels=show_cluster_labels, 110 show_trajectories=show_trajectories, 111 reverse=reverse, 112 show_node=show_node, 113 threshold_spots=threshold_spots, 114 text_box_size=text_box_size, 115 color_bar_size=color_bar_size, 116 bbox_to_anchor=bbox_to_anchor, 117 trajectory_node_size=trajectory_node_size, 118 trajectory_alpha=trajectory_alpha, 119 trajectory_width=trajectory_width, 120 trajectory_edge_color=trajectory_edge_color, 121 trajectory_arrowsize=trajectory_arrowsize, 122 )

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/stlearn/plotting/classes.py:713, in ClusterPlot.init(self, adata, title, figsize, cmap, use_label, list_clusters, ax, fig, show_plot, show_axis, show_image, show_color_bar, crop, zoom_coord, margin, size, image_alpha, cell_alpha, fname, dpi, show_subcluster, show_cluster_labels, show_trajectories, reverse, show_node, threshold_spots, text_box_size, color_bar_size, bbox_to_anchor, trajectory_node_size, trajectory_alpha, trajectory_width, trajectory_edge_color, trajectory_arrowsize) 710 self.trajectory_edge_color = trajectory_edge_color 711 self.trajectory_arrowsize = trajectory_arrowsize --> 713 self._add_trajectories() 715 if fname != None: 716 self._save_output()

File /miniconda3/envs/spatial.p/lib/python3.8/site-packages/stlearn/plotting/classes.py:907, in ClusterPlot._add_trajectories(self) 904 cmap = plt.get_cmap(cmaps) 906 if "PTS_graph" not in self.adata[0].uns: --> 907 raise ValueError("Please run stlearn.spatial.trajectory.pseudotimespace!") 909 tmp = _read_graph(self.adata[0], "PTS_graph") 911 G = tmp.copy()

ValueError: Please run stlearn.spatial.trajectory.pseudotimespace!

duypham2108 commented 2 months ago

Yes, I know this issue but I haven't solved it yet. You can try to save with pickle like this https://github.com/BiomedicalMachineLearning/stLearn/issues/262#issuecomment-1800241654

chiwwong commented 2 months ago

That works for me. Thanks!

Btw, I wonder if the st.spatial.trajectory.pseudotime can be accelerated by multi-thread? It takes a long time to compute for large clusters/datasets (e.g. 90253 nodes). (I also wonder if I did anything wrong if the program is still running after I have waited for 2 hours without).