Skip to content

Instantly share code, notes, and snippets.

View vjcitn's full-sized avatar

Vince Carey vjcitn

  • Boston
View GitHub Profile
@vjcitn
vjcitn / gist:cb316b89d08be63ebc9e3c9194e17b36
Created September 6, 2023 13:55
import semantic SQL content to ontology_index
#' produce an ontology_index instance from semantic sql sqlite connection
#' @param con DBI::dbConnect value for sqlite table
#' @return result of ontologyIndex::ontology_index evaluated for the labels and
#' parent-child relations in tables statements and edge of the semantic sql resource
#' @export
semsql_to_oi = function(con) {
# sqlite> select * from statements where predicate = 'rdfs:label' limit 40;
alltabs = DBI::dbListTables(con)
stopifnot(all(c("edge", "statements") %in% alltabs))
labdf = dplyr::tbl(con, "statements") |> dplyr::filter(predicate == "rdfs:label") |>
@vjcitn
vjcitn / happ.R
Created August 10, 2023 19:47
defines function happ() to manipulate image of activated mast cell
library(shiny)
library(imager)
mpath = "https://mghp.osn.xsede.org/bir190004-bucket01/BiocGeneralData/mast.jpg"
happ = function () {
ui = fluidPage(
sidebarLayout(
sidebarPanel(
helpText("slider for cannyEdges alpha"),
sliderInput("alpha", "alpha", min = 0, max = 1, step = 0.05,
@vjcitn
vjcitn / colorapp2.R
Created August 8, 2023 18:39
simple color model exploration with shiny
library(shiny)
colorapp2 = function ()
{
colordot = function (r, g, b) {
plot(0, 0, col = grDevices::rgb(r, g, b), pch = 19, cex = 15)
}
ui = fluidPage(
sidebarLayout(
sidebarPanel(
@vjcitn
vjcitn / SCPDockerFIle
Created June 15, 2023 21:14
A dockerfile for working with R (quickly via r2u) and SCP from Hao Zhang
FROM ubuntu:jammy
LABEL org.label-schema.license="GPL-2.0" \
org.label-schema.vcs-url="https://github.com/rocker-org/" \
org.label-schema.vendor="Rocker Project" \
maintainer="Dirk Eddelbuettel <edd@debian.org>"
## Set a default user. Available via runtime flag `--user docker`
## Add user to 'staff' group, granting them write privileges to /usr/local/lib/R/site.library
## User should also have & own a home directory (for rstudio or linked volumes to work properly).
@vjcitn
vjcitn / pbmcDemo.R
Last active May 15, 2023 23:56
produce a plotly biplot for labeled PBMCs
# this code will process 4k PBMCs from TENx with SingleR and scater
# compute some approximate PCs and produce an interactive scatterplot
# in PC space with a biplot
ii = rownames(installed.packages())
if (!("BiocManager" %in% ii))install.packages("BiocManager")
req = c("celldex", "TENxPBMCData", "SingleR", "irlba", "scater",
"scales", "ggplot2", "devtools", "plotly")
needed = setdiff(req, ii)
if (length(needed)>0) BiocManager::install(needed, ask=FALSE, update=FALSE)
library(celldex)
@vjcitn
vjcitn / filtered_biplot.R
Created May 15, 2023 23:04
a biplot function using ggplot
filtered_biplot = function (prcomp_output, sce, sampvar = "Barcode", colorvar = "label.main",
which = c(1, 2), nvar = 5, shr = 0.6, ...)
{
rownames(prcomp_output$x) = sce[[sampvar]]
rownames(prcomp_output$rotation) = rownames(sce)
proj = prcomp_output$x[, which]
rot = prcomp_output$rot[, which]
sss = function(x) sum(x^2)
lens = apply(rot, 1, sss)
kprot = rot[order(lens, decreasing = TRUE)[1:nvar], ]
@vjcitn
vjcitn / vjcreport.txt
Created April 29, 2023 18:18
errors from anvil GPU
> r1 = run_cifar100() # pip3 install tensorflow; BiocManager::install("vjcitn/littleDeep", dependencies=TRUE)
No non-system installation of Python could be found.
Would you like to download and install Miniconda?
Miniconda is an open source environment management system for Python.
See https://docs.conda.io/en/latest/miniconda.html for more details.
Would you like to install Miniconda? [Y/n]: n
Installation aborted.
2023-04-29 18:14:44.950515: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
@vjcitn
vjcitn / txbib.txt
Last active March 25, 2023 02:54
transform a .bib file to queries to pubmed batch processor
# process .bib file into a batch query to pubmed (https://pubmed.ncbi.nlm.nih.gov/batchcitmatch/)
# get first page
fixp = function(x) gsub("--.*", "", x)
# produce a batch query
build_query = function (x)
paste(x$journal, x$year, x$volume, fixp(x$pages), x$author[[1]]$family,
paste0(x$author[[1]]$family, x$year), sep = "|")
@vjcitn
vjcitn / gist:2ec74f495df23bce64e2e6521b92569c
Created November 6, 2022 13:48
process_renv_lock will attempt to clone and check out sources of packages corresponding to specs in renv lockfile
as_renv_entry = function(x) {
stopifnot(all(c("Package", "git_url", "git_last_commit") %in% names(x)))
class(x) = c("renv_entry", class(x))
x
}
print.renv_entry = function(x, ...) {
cat(sprintf("renv entry for %s %s\n", x$Package, x$git_branch))
}
@vjcitn
vjcitn / ad_mats.R
Last active August 10, 2022 14:53
use VariantAnnotation::readVcf etc. to get allelic depth count matrices from VCF
#' produce matrices of AD values from VcfFile instance for a given genomic interval
#' @param vf instance of VcfFile, should be tabix indexed
#' @param rng compatible GRanges instance
#' @param genome character(1) obligatory for readVcf
#' @return list with matrices allele1 and allele2, similar to the AD matrix, and ref and alt as obtained directly
#' @examples
#' x = VariantAnnotation::VcfFile("ALL.chrX.BI_Beagle.20100804.genotypes.vcf.gz")
#' param = GRanges("X", IRanges(60000, width=10000))
#' m = ad_mats(x, param)
#' m$allele1[1:4,1:10]