Open gheimberg opened 4 years ago
Happens here:
Where does .uns['log1p']
get set other than there?
Hi @gheimberg,
In your example you are not using a deepcopy to assign adata.X
to adata.layers['other']
. So when you log transform the data in the layer, it automatically log transforms the data in adata.X
as well, as you just passed the reference. That being said, this is still a bug as even with a adata.X.copy()
the warning is given.
Guys we should just keep the layer info here in log1p:
data.uns['log1p'] = {'base': base}
like
data.uns['log1p'][layer] = {'base': base}
I've come across a strange behavior related with this issue. Depending on whether or not I save the object I get the same warning as OP.
This works as it should:
import scanpy as sc
adata=sc.read_h5ad(data_dir+'scanpy_QC_sexchrom.h5ad')
adata.raw=adata.copy() #data to save
sc.pp.log1p(adata) # logaritmize
### Test 1, no saving, works as it should
adata=adata.raw.to_adata()
sc.pp.log1p(adata)
##>>> no warning
Saving mid-way does not allow to avoid the warning, even restarting the kernel before reading the data:
import scanpy as sc
## same as above
adata=sc.read_h5ad(data_dir+'scanpy_QC_sexchrom.h5ad')
adata.raw=adata.copy() #data to save
sc.pp.log1p(adata) # logaritmize
### Test 2, saving and re-assigning from raw
### saving object, reading, testing again
### Doesnt work
adata.write_h5ad(tmp+'scanpy_test.h5ad')
adata=sc.read_h5ad(tmp+'scanpy_test.h5ad')
adata=adata.raw.to_adata()
sc.pp.log1p(adata)
###>>>WARNING: adata.X seems to be already log-transformed.
I'm on scanpy 1.9.1 if it matters
I must also mention that upon reading in the data:
adata.uns['log1p']
returns {}
;adata.uns['log1p']["base"] = None
after reading doesn't help.del adata.uns['log1p']
solves the problem. Visual inspection of expression values in adata.X
seem to not be log-transformed.
When I use
sc.pp.log1p(adata)
and thensc.pp.log1p(adata, layer='other')
it warns me that the data has already been logged even though I am logging a layer as opposed to adata.X.Would be nice to flag logging for each layer instead of when anything is logged.
Versions: