Skip to content

Instantly share code, notes, and snippets.

View docmanny's full-sized avatar

Juan Manuel Vazquez docmanny

View GitHub Profile
@docmanny
docmanny / split_file_ExitStack.py
Created May 8, 2023 16:04
Example of using ExitStack to make a highly efficient file splitter
""" Example of using ExitStack to make a highly efficient file splitter """
from contextlib import ExitStack
# Example file is a BED file where Col 7 is in the form of "genomeA:genomeB"
# and the goal is to split it into files based on if genomeA == genomeB.
f_in = "head1000tail1000_biser.bed"
def get_outfile(col):
@docmanny
docmanny / plot_wrapfigure.R
Created September 18, 2019 19:54
knitr hook for wrapping text around figures in PDF outputs
knitr::knit_hooks$set(wrapf = function(before, options, envir) {
# Inspired by user "CL."'s answer in https://stackoverflow.com/questions/34017777/wrapping-figure-with-latex-environment-in-knitr-rmarkdown-with-hooks
align <- ifelse(is.null(options$fig.align), "left", options$fig.align)
width <- ifelse(is.null(options$out.width), "0.3", gsub("\\linewidth", "", options$out.width, fixed = T)) # fixes out.width to work with either pct or dec
num <- options$fig.num
label <- options$label
caption <- options$fig.cap
if(before) {
return(sprintf("\\begin{wrapfigure}{%s}{%s\\textwidth}\n", align, width)) # Initiates wrapfigure