Giter Club home page Giter Club logo

Comments (11)

LiQian-XC avatar LiQian-XC commented on August 25, 2024

Hi,
Please run adata = adata.raw.to_adata() to get raw counts in adata.X before all steps as both the sc.pp.highly_variable_genes (when using flavor='seurat_v3') and scTour under default mode expect raw UMI counts. Please let me know if you have any further questions.

from sctour.

pandaqiuqiu avatar pandaqiuqiu commented on August 25, 2024

@LiQian-XC

Thanks for your fast response. When running run adata = adata.raw.to_adata() at the beginning, it encounters a new error as follows:

tnode = sct.train.Trainer(adata, loss_mode='nb', alpha_recon_lec=0.5, alpha_recon_lode=0.5)
tnode.train()

Running using CPU.

AttributeError Traceback (most recent call last)
Cell In[16], line 2
1 tnode = sct.train.Trainer(adata, loss_mode='nb', alpha_recon_lec=0.5, alpha_recon_lode=0.5)
----> 2 tnode.train()

File ~/.../sctour/lib/python3.10/site-packages/sctour/train.py:258, in Trainer.train(self)
254 def train(self):
255 """
256 Model training.
257 """
--> 258 self._get_data_loaders()
260 params = filter(lambda p: p.requires_grad, self.model.parameters())
261 self.optimizer = torch.optim.Adam(params, lr = self.lr, weight_decay = self.wt_decay, eps = self.eps)

File ~/.../sctour/lib/python3.10/site-packages/sctour/train.py:245, in Trainer._get_data_loaders(self)
240 """
241 Generate Data Loaders for training and validation datasets.
242 """
244 train_data, val_data = split_data(self.adata, self.percent, self.val_frac)
--> 245 self.train_dataset = MakeDataset(train_data, self.loss_mode)
246 self.val_dataset = MakeDataset(val_data, self.loss_mode)
248 # sampler = BatchSampler(train_data.n_obs, self.batch_size, self.drop_last)
249 # self.train_dl = DataLoader(self.train_dataset, batch_sampler = sampler)

File ~/miniconda3/envs/sctour/lib/python3.10/site-packages/sctour/data.py:99, in MakeDataset.init(self, adata, loss_mode)
97 X = np.log1p(X)
98 if sparse.issparse(X):
---> 99 X = X.A
100 self.data = torch.tensor(X)
101 self.library_size = self.data.sum(-1)

AttributeError: 'SparseCSRView' object has no attribute 'A'

from sctour.

LiQian-XC avatar LiQian-XC commented on August 25, 2024

Hi,

Can you try the following steps to see whether it works?

from scipy.sparse import csr_matrix
adata.X = csr_matrix(adata.X)

Please let me know if you have any other questions.

from sctour.

pandaqiuqiu avatar pandaqiuqiu commented on August 25, 2024

@LiQian-XC
After running
from scipy.sparse import csr_matrix
adata.X = csr_matrix(adata.X),
the same issue persisted. However, I tried using adata.X = adata.X.toarray() later, and it solved the problem. Thank you for your prompt response.

from sctour.

bbimber avatar bbimber commented on August 25, 2024

@LiQian-XC : we are having what I assume is an analogous issue. I was the

AttributeError: 'SparseCSRView' object has no attribute 'X' error just like above, when calling train(). The csr_matrix() solution did not work. FWIW, our code is subsetting the adata object right before training, and I suspect this is converting into this this View class:

adataObj = adataObj[:, list(set(adataObj.var_names) - set(exclusionList))]
tnode = sct.train.Trainer(adataObj)

My guess is that something about sutsetting is converting the AnnData object into a view of the data, and that isnt interacting well with scTour. Do you have any debugging suggestions or tests on the anndata object to verify that theory?

from sctour.

LiQian-XC avatar LiQian-XC commented on August 25, 2024

Hi,

Can you try to copy the data when subsetting (please see your example below)?

adataObj = adataObj[:, list(set(adataObj.var_names) - set(exclusionList))].copy()

I think this may address this issue and please let me know if it does not work.

from sctour.

bbimber avatar bbimber commented on August 25, 2024

Thanks for the idea. Yes, after posting I came to the same conclusion. Tests are running on the code here: https://github.com/bimberlabinternal/CellMembrane/blob/407adf4f1d998af41c1de79f257e94bfe256d0ee/inst/scripts/run_sctour.py#L31

If this is a solution, would you consider adding this kind of test directly to scTour?

from sctour.

LiQian-XC avatar LiQian-XC commented on August 25, 2024

Thanks for sharing your code. I will consider adding this in a new version of scTour.

from sctour.

GWMcElfresh avatar GWMcElfresh commented on August 25, 2024

Hi everyone,

The solution @pandaqiuqiu pointed out works for this error as well. Scipy stopped supporting .A as a shorthand for .toarray() in 1.14 (released Jun 24th, https://docs.scipy.org/doc/scipy/release/1.14.0-notes.html#expired-deprecations).

To support scipy >= 1.14, changing

X = X.A
to X = X.toarray() should do it.

from sctour.

bbimber avatar bbimber commented on August 25, 2024

To be clear, I think there's two total lines of code, the one above and this that would need to be changed:

X = X.A

from sctour.

LiQian-XC avatar LiQian-XC commented on August 25, 2024

Thank you all for pointing this out. I will fix it and release a new version.

from sctour.

Related Issues (11)

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.