Skip to content

Instantly share code, notes, and snippets.

View mfansler's full-sized avatar
⚙️

Mervin Fansler mfansler

⚙️
View GitHub Profile
@mfansler
mfansler / conda.txt
Last active April 25, 2024 13:53 — forked from dataprofessor/conda.txt
Installing mamba on Google Colab
#################################################################################
# INSTALL MAMBA ON GOOGLE COLAB
#################################################################################
! wget -O miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-py37_4.10.3-Linux-x86_64.sh
! chmod +x miniconda.sh
! bash ./miniconda.sh -b -f -p /usr/local
! rm miniconda.sh
! conda config --add channels conda-forge
! conda install -y mamba
! mamba update -qy --all
@mfansler
mfansler / new-cran-pkg.sh
Last active April 20, 2024 22:20
Conda Forge `staged-recipes` utility scripts
#!/usr/bin/env bash -l
#' Usage: `bash -l new-cran-pkg.sh {r-package}`
#' Purpose: Generates a Conda Forge recipe using `conda_r_skeleton_helper` and
#' pushes this to a personal fork of `staged-recipes`.
#' Notes: Should be located in and run from a `staged-recipes` clone prefix.
#' `git remote -v` should show `origin` set to a personal fork
#' and `upstream` set to 'git@github.com:conda-forge/staged-recipes.git'.
#' CRAN package name should be prefixed with 'r-' and given in all lowercase.
set -xe -o pipefail
@mfansler
mfansler / install-ascp.sh
Last active March 26, 2024 20:07
Install ascp on Linux
#!/bin/bash
## How to install ascp, in a gist.
## The URI below is not persistent!
## Check for latest link: https://www.ibm.com/aspera/connect/
wget -qO- https://ak-delivery04-mul.dhe.ibm.com/sar/CMA/OSA/0a07f/0/ibm-aspera-connect_4.1.0.46-linux_x86_64.tar.gz | tar xvz
## run it
chmod +x ibm-aspera-connect_4.1.0.46-linux_x86_64.sh
@mfansler
mfansler / index-gtf.sh
Last active December 19, 2023 15:14
GTF file compressed indexing for IGV compatibility
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo -e "Incorrect number of parameters! Usage:\n index-gtf.sh <file.gtf(.gz)>" >&2
exit 1
fi
gtf="$1"
if [[ $gtf =~ \.gz$ ]]; then
@mfansler
mfansler / list_export_to_yaml.awk
Last active November 30, 2023 20:18
Convert `conda list` output to YAML
#!/usr/bin/env awk -f
#' Author: Mervin Fansler
#' GitHub: @mfansler
#' License: MIT
#'
#' Basic usage
#' $ conda list --export | awk -f list_export_to_yaml.awk
#'
#' Omitting builds with 'no_builds'
#' $ conda list --export | awk -v no_builds=1 -f list_export_to_yaml.awk
## see https://stackoverflow.com/q/76039888/570918
diffmat <- function(drow_margin, dcol_margin, freeze=TRUE) {
nrow <- length(drow_margin)
ncol <- length(dcol_margin)
rmat <- matrix(drow_margin, nrow, ncol)
cmat <- matrix(dcol_margin, nrow, ncol, byrow=TRUE)
dmat <- 0.5*(rmat + cmat)
if (freeze) {
## keep satisfactory rows and columns fixed
@mfansler
mfansler / list_r_pkg_linked_libs.sh
Created December 22, 2022 23:43
List all libraries a Conda Forge R library links against
#!/usr/bin/env bash -l
## PARAMS
## file should have one "[name]=[version]=[build]" per line
FILE_PKG_BUILDS="r-tiff.cf_pkgs.txt"
##
DYLIB_LOC="lib/R/library/tiff/libs"
tmp=$(mktemp -d)
@mfansler
mfansler / read_ad_df.R
Created August 26, 2022 17:02
Read anndata dataframes with pure R
library(rhdf5)
library(tidyverse)
read_ad_df <- function (file, name) {
x_attrs <- h5readAttributes(file, name)
## check requested entry is a dataframe
## TODO: do we need to check encoding-version?
stopifnot(x_attrs[['encoding-type']] == "dataframe")
@mfansler
mfansler / xargs_parallel_syntax.sh
Created July 22, 2022 16:38
Notes on xargs syntax for parallel execution
#!/bin/bash
## space-separated input
## -n1: run each separately
## -P6: run up to 6 in parallel
## -I '{}': replace {} with argument
## \$ delays evaluation to bash execution
## waits randomly for up to five seconds, then prints
echo {1..12} |\
xargs -n1 -P6 -I '{}' \
bash -c "sleep \$[ \$RANDOM % 5 ]; echo {}"
@mfansler
mfansler / get-srr.sh
Created June 8, 2017 19:39
bash commands for downloading SRRs from NCBI's SRA
#!/bin/bash
# download SRR from NCBI SRA via Aspera Connect
#
# > get-srr SRR304976
get-srr () {
SRR=${1}
SRR_6=$(echo $SRR | cut -c1-6)
ascp -i ~/.aspera/connect/etc/asperaweb_id_dsa.openssh \