edward130603 / BayesSpace

Bayesian model for clustering and enhancing the resolution of spatial gene expression experiments.
http://edward130603.github.io/BayesSpace
Other
106 stars 21 forks source link

imagerow and imagecol coordinates are not spread out equidistantly #100

Closed killerz99 closed 1 year ago

killerz99 commented 1 year ago

happens on some Visium, but not others. Not sure what causes the difference.

example

usual arrangement:

example2
edward130603 commented 1 year ago

I don't think I've seen this before. Can you share (a subset of) the tissue_positions file?

killerz99 commented 1 year ago

I don't think its the tissue_positions_list.csv file. I swapped the file with another visium dataset that worked and it produced the same pattern. Also, a different visium dataset produced spots that were overlapping with each other in the original coordinates of the low-dimensional visium. (ie 30,000 spots were mapped to 5,000 spots)

what I used to run: scen<-spatialPreprocess(sce, platform="Visium", n.PCs=20, n.HVGs=2000, log.normalize=T) scen<-spatialCluster(scen, q=12, d=20, platform="Visium", init.method="mclust", model="t", gamma=0, nrep=1000, burn.in=100, save.chain=T) s.en<-spatialEnhance(scen, q=12, platform="Visium", d=20, model="t", gamma=0, jitter_prior=0.3, jitter_scale=3.5, nrep=1000, burn.in=100, save.chain=T)

first 10 lines: ACGCCTGACACGCGCT-1,0,0,0,3969,3317 TACCGATCCAACACTT-1,0,1,1,4204,3706 ATTAAAGCGGACGAGC-1,0,0,2,4421,3308 GATAAGGGACGATTAG-1,0,1,3,4656,3696 GTGCAAATCACCAATA-1,0,0,4,4873,3298 TGTTGGCTGGCGGAAG-1,0,1,5,5108,3686 GCATCCTCTCCTATTA-1,0,0,6,5325,3288 GCGAGGGACTGCTAGA-1,0,1,7,5560,3676 TGGTACCGGCACAGCC-1,0,0,8,5777,3278 GCGCGTTTAAATCGTA-1,1,1,9,6012,3667

killerz99 commented 1 year ago

GSM5924030 https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSM5924030

overlapped spots using imagerow / imagecol coordinates:

overlap
edward130603 commented 1 year ago

Ok in that dataset it seems like imagerow and imagecol (or row and col) got swapped and maybe there's a flipping issue. Ideally, the code expects row and imagerow to have correlation = 1 and same for col vs. imagecol. image image

Assuming the imagerow and imagecol coordinates are correct (I haven't checked against the images), you can 1) multiple col by -1, and 2) swap the colnames of row and col.

We've seen this sort of issue a few times and I probably should add an automated detection+correction of this. I haven't used SpaceRanger before so not sure how these sorts of issues arise.

killerz99 commented 1 year ago

Thanks Edward, that seems to have been the issue. Note that the row/cols can be swapped and/or anti-correlated or not. So if only swapped, it results in the first case of the small hexagons. If swapped and anti-correlated, it results in the overlapping dots.

killerz99 commented 1 year ago

I looked back at the coordinates from using a different tissue_positions_list.csv and actually, it did work so my initial conclusion about it not being the positions file was faulty.

killerz99 commented 1 year ago

if you have a file that works, can use it as a reference for the correct coordinate direction to compare to

filename<-'tissue_positions_list.csv'; reference<-'human_reference_tissue_positions_list.csv';

data<-read.table(file=filename, header=F, sep=','); row<-data[,5]; col<-data[,6];

refdata<-read.table(file=reference, header=T, sep=','); refrow<-refdata[,5]; refcol<-refdata[,6];

pdf(file='qc.pdf', width=8, height=8);

c1<-cor(row, refrow); plot(row, refrow, xlab='row', ylab='refrow', main=paste('cor',c1,sep=' ')); c2<-cor(col, refcol); plot(col, refcol, xlab='col', ylab='refcol', main=paste('cor',c2,sep=' '));

c3<-cor(col, refrow); plot(col, refrow, xlab='col', ylab='refrow', main=paste('cor',c3,sep=' ')); c4<-cor(row, refcol); plot(row, refcol, xlab='row', ylab='refcol', main=paste('cor',c4,sep=' '));

if( (c1 > 0.99) & (c2 > 0.99)){ print("A OK."); }else if( (c3 > 0.99) & (c4 > 0.99)){ print("swap row and col"); data[,5]<-col; data[,6]<-row; }else if( (c3 > 0.99) & (c4 < -0.99)){ print("swap row and col negative row"); data[,5]<-col; data[,6]<- rev(row); }else if( (c3 < -0.99) & (c4 > 0.99)){ print("swap row and col negative column"); data[,5]<- rev(col); data[,6]<-row; }else{ print("Unknown"); }

newfile<-paste(filename,'swap',sep='.'); write.table(data, file=newfile, quote=F, sep=',',row.names=F, col.names=F);

row<-data[,5]; col<-data[,6]; c1<-cor(row, refrow); plot(row, refrow, xlab='row', ylab='refrow', main=paste('cor',c1,sep=' ')); c2<-cor(col, refcol); plot(col, refcol, xlab='col', ylab='refcol', main=paste('cor',c2,sep=' ')); dev.off();