Skip to content

Instantly share code, notes, and snippets.

View vjcitn's full-sized avatar

Vince Carey vjcitn

  • Boston
View GitHub Profile
@vjcitn
vjcitn / litapp.R
Created September 19, 2024 04:55
small app for zarr store of xenium
library(shiny)
library(xenLite)
library(SpatialExperiment)
what = "LUAD"
ui = fluidPage(
sidebarLayout(
sidebarPanel(
uiOutput("topbox"),
@vjcitn
vjcitn / r-dev.noload.txt
Created September 19, 2024 02:06
error with attempt to install impute from bioc.r-universe.dev
setup:
> options(repos=c(BioCsoft="https://bioc.r-universe.dev", CRAN="https://cloud.r-project.org"))
> getOption("repos")
BioCsoft CRAN
"https://bioc.r-universe.dev" "https://cloud.r-project.org"
> install.packages("impute")
Installing package into ‘/Users/papa/Library/R/arm64/4.4/library’
@vjcitn
vjcitn / ggplot_seg.R
Created September 1, 2024 21:06
code that uses ggplot and some cell-level summaries on XenSPEP/XenSCE
library(plotly)
library(ggplot2)
library(XenSCE)
if (!exists("gbm")) load("gbm.rda")
print.xen_ggprep = function(x, ...) {
cat(sprintf("xen_ggprep instance for %d cells with %d cell boundary vertices.\n", ncol(x$sampd), nrow(x$bounds)))
}
ggprep_seg = function(xsce, xlim=c(5800,6200), ylim=c(6300, 6700), show_tx=TRUE) {
library(plotly)
library(ggplot2)
library(XenSCE)
if (!exists("gbm")) load("gbm.rda")
plotly_seg = function(xsce, xlim=c(5800,6000), ylim=c(6300, 6500), show_tx=TRUE) {
bounds = getCellBoundaries(xsce)
bounds = bounds[bounds$vertex_x > xlim[1] &
bounds$vertex_x < xlim[2] & bounds$vertex_y > ylim[1] & bounds$vertex_y < ylim[2],]
c4 <- as.data.frame(bounds)
#ggplot(c4, aes(x=vertex_x, y=vertex_y, group=cell_id)) + geom_path() -> pas
@vjcitn
vjcitn / vizapp.R
Created August 31, 2024 15:43
interactive xenium exploration
library(shiny)
library(ParquetDataFrame)
library(XenSCE)
if (!exists("gbm")) load("gbm.rda")
ui = fluidPage(
sidebarLayout(
sidebarPanel(
helpText("view gbm"),
@vjcitn
vjcitn / simple.txt
Last active August 22, 2024 10:14
get DESCRIPTIONs
get_bioc_packagelist = function(rel = "RELEASE_3_19") {
system("git clone https://git.bioconductor.org/admin/manifest")
owd = getwd()
setwd("manifest")
on.exit(setwd(owd))
system(paste("git checkout ", rel))
proc_software.txt = function() {
x = readLines("software.txt")[-1] # first line is comment
nn = which(nchar(x)==0)
tmp = x[-nn]
@vjcitn
vjcitn / ebe.R
Created August 13, 2024 10:53
use EBImage to explore spatial transcriptomics data
library(EBImage)
library(shiny)
ui = fluidPage(
sidebarLayout(
sidebarPanel(
helpText("EBImage explorer"),
fileInput("inimg", "file"),
numericInput("scalefactor", "multfac", min=1, max=50, value=10,step=1),
sliderInput("blursig", "sigma for blur", min=1, max=100, value=50)
#tabix Lung.tsv.gz 1:1-300000000 > lung.chr1.tsv
#tabix Lung.tsv.gz 2:1-300000000 > lung.chr2.tsv
#tabix Lung.tsv.gz 3:1-300000000 > lung.chr3.tsv
#tabix Lung.tsv.gz 4:1-300000000 > lung.chr4.tsv
#tabix Lung.tsv.gz 5:1-300000000 > lung.chr5.tsv
#tabix Lung.tsv.gz 6:1-300000000 > lung.chr6.tsv
#tabix Lung.tsv.gz 7:1-300000000 > lung.chr7.tsv
#tabix Lung.tsv.gz 8:1-300000000 > lung.chr8.tsv
#tabix Lung.tsv.gz 9:1-300000000 > lung.chr9.tsv
#tabix Lung.tsv.gz 10:1-300000000 > lung.chr10.tsv
@vjcitn
vjcitn / XenSCE.R
Created August 6, 2024 16:56
simple collection of matrix.mtx and parquet assets from Xenium exemplary dataset
# retrieve these from https://mghp.osn.xsede.org/bir190004-bucket01/BiocXenData/
#-rw-r--r-- 1 exouser exouser 3300521324 Mar 20 21:17 transcripts.parquet
#-rw-r--r-- 1 exouser exouser 68454210 Mar 20 21:16 nucleus_boundaries.parquet
#-rw-r--r-- 1 exouser exouser 73791358 Mar 20 21:15 cell_boundaries.parquet
#-rw-r--r-- 1 exouser exouser 242459483 Apr 10 03:46 cell_feature_matrix.tar.gz
#-rw-r--r-- 1 exouser exouser 44907408 Mar 20 21:15 cells.csv.gz
# tar zxf cell_feature_matrix.tar.gz to obtain folder cell_feature_matrix
library(Matrix)
@vjcitn
vjcitn / explore_bert.R
Last active July 17, 2024 13:35
look at 'safetensors' component of bert (use after usebert.R succeeds)
# probe R user cache file system for bert resources
explore_bert = function() {
if (!requireNamespace("tibble")) stop("please install tibble to use this function")
res = dir(tools::R_user_dir("../huggingface/hub/models--google-bert--bert-base-uncased/snapshots/", "cache"), full=TRUE, recursive=TRUE)
if (length(res)<1) stop("not finding huggingface/hub or bert components in cache")
safetpath = grep("model.safetensors", res, value=TRUE)
st = try(reticulate::import("safetensors"))
if (inherits(st, "try-error")) stop("can't import safetensors with reticulate")
oo = st$safe_open(filename=safetpath, framework="pt")
kk = oo$keys()