-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible for Gene_maps values to use the same scale instead of min-max per gene? #72
Comments
Yes, that's correct. There is currently no option to give the gene maps a common scale. The reason for this is that they are produced one gene at a time, so we don't know the max until all genes have been processed. What you could do possibly is to save the underlying data that the maps are based on by setting As an aside, I agree that this gene map looks quite weird. Usually, microstructure (e.g. nuclei) are typically visually distinct. What is the resolution of the H&E after scaling? Usually, I aim for something like 1500 - 2000 px in height/width. |
I tried what you said, and the genes I selected are now in the output folder as a .pt format.
my toml file was something like this;
|
Awesome!
You will have to do this manually. To give you an idea, something like the below script should work (it's untested so it will likely need some slight modifications to work). You need to run it in the same directory as the *.pt files. It first computes the max expression over all maps and then normalizes the gene maps based on that. Note that it could be that the max will be too high and all maps will then be quite dark. In that case, it could make more sense to clip the maps on the 99th percentile or similar instead of the max. import os
from glob import glob
import matplotlib.cm as cm
import tifffile
def load_gene_map(path):
gene_map = torch.load(path, map_location="cpu")
gene_map = gene_map.mean(0)
return gene_map
max_expression_all = 0
gene_map_files = glob("*.pt")
for path in gene_map_files:
gene_map = load_gene_map(path)
max_expression = gene_map.max()
if max_expression > max_expression_all:
max_expression_all = max_expression
for path in gene_map_files:
gene_name,_ = os.path.splitext(os.path.basename(path))
gene_map = load_gene_map(path)
gene_map = gene_map / max_expression_all
gene_map = gene_map.numpy()
gene_map = cm.inferno(gene_map)
tifffile.imsave(f"{gene_name}.tif", gene_map)
Good question! As long as the model is trained on the entire gene expression data, the latent state and therefore maps will also be informed by other genes.
It sets the gene map writer to the "tensor" writer, which saves the sampled gene maps as pytorch tensors (as opposed to image files saved by the "image" writer). The tensor writer is defined here: xfuse/xfuse/analyze/gene_maps.py Lines 157 to 160 in c420abb
|
If I understand correctly; the gene maps are minimum and maximum expression for each gene.
However, genes that are hardly expressed in your biological sample will look like they have a strong expression pattern which is overblown (imho).
Would it be possible to have an output where the gene_maps of all genes have the same scale? In this way, genes that are hardly expressed would also show dramatic expression. For example in my tissue, CD1E expression is really low, but it appears enormous in XFuse (with a distribution that doesnt make much sense, its more noise that gets amplified...)
Maybe I did sth wrong and this should not be? I expect in this case that the entire tissue would be blackish colour...
The text was updated successfully, but these errors were encountered: