Skip to content

Instantly share code, notes, and snippets.

View vjcitn's full-sized avatar

Vince Carey vjcitn

View GitHub Profile
@vjcitn
vjcitn / gist:48fdf3ecd17d15bcf6771e8f1efd2fbe
Last active April 25, 2020 17:27
highly specialized function to demonstrate how to produce an estimated Rt based on JHU confirmed case time-series
library(sars2pack)
easyRt = function(alpha3="ITA", src = (suppressWarnings(enriched_jhu_data())),
init = "2020-03-01", ...) {
cur = cumulative_events_ejhu(src, eventtype="confirmed",
alpha3=alpha3)
inc = form_incident_events( trim_from (cur, init ) )
newd = data.frame(I=inc$count, dates=inc$dates)
EpiEstim::estimate_R(newd, ...)
}
rtBya3 = function(a3="ITA") {
@vjcitn
vjcitn / foo.md
Last active November 19, 2020 21:30
testing
title leader tab_date comment
Cloud computing cost measurement and control Vince 2020-09-03 cloud agnostic?
Orchestra for workshops (Guest talk) Sean Davis 2020-10-01 Infra. for Bioc2020 wkshops
The Bioc Hubs: enhancements for training Mike Love NA scale/formats
Large data methods Stephanie Hicks NA many players
Reliability and code validation Levi Waldron NA goals/resources
Build system automation NA NA build on commit report
Documentation evaluation and maintenance CAB NA doc rot reporting mechanism
@vjcitn
vjcitn / revise_source.R
Created July 28, 2021 22:19
code that can revise DESCRIPTION to add a package that is needed, bump version, and take care of git operations
#' @param dry_run logical(1) if TRUE, just return revised DESCRIPTION
#' @return `desc::description` instance; will write revised DESCRIPTION to `path` if `dry_run` FALSE.
#' @note Bumps third component of version tag
#' @export
revise_desc = function(path, type="Suggests", to_add="rmarkdown", dry_run=TRUE) {
stopifnot(is.atomic(to_add) && length(to_add)==1)
init = desc::description$new(path)
deps = init$get_deps()
if (to_add %in% deps$package) stop("already depended upon")
init = init$set_dep(type=type, package=to_add)
@vjcitn
vjcitn / cgxapp.R
Created February 1, 2022 19:32
sketch of app to work with mtmorgan/cellxgenedp
library(shiny)
library(cellxgenedp)
library(jsonlite)
db = try(db())
if (inherits(db, "try-error")) stop("can't get db")
jsdb = fromJSON(db) # is character, makes data.frame!
nn = jsdb$name
names(nn) = paste(seq_len(nrow(jsdb)), nn)
#' produce matrices of allele calls 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
#' @param pat1 character(1) gsub regexp to isolate first allele code (might need to have
#' / instead of | if unphased)
#' @param pat2 character(1) gsub regexp to isolate second allele code (might need to have
#' / instead of | if unphased)
#' x = VariantAnnotation::VcfFile("ALL.chr22.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz")
#' param = GRanges("22", IRanges(16e6, width=200000))
@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]
@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 / 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 / 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 / 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], ]