Skip to content

Instantly share code, notes, and snippets.

View acvill's full-sized avatar
🪗

Albert Vill acvill

🪗
View GitHub Profile
cat hg18.fa | awk '{
if (substr($0, 1, 1)==">") {filename=(substr($0,2) ".fa")}
print $0 > filename
}'
@davidliwei
davidliwei / getinsertsize.py
Last active October 25, 2022 06:15
Estimating NGS paired-end read insert size (or fragment length) from SAM/BAM files
#!/usr/bin/env python
'''
Automatically estimate insert size of the paired-end reads for a given SAM/BAM file.
Usage: getinsertsize.py <SAM file> or samtools view <BAM file> | getinsertsize.py -
Author: Wei Li
Copyright (c) <2015> <Wei Li>
@nathanhaigh
nathanhaigh / interleave_fastq.sh
Last active March 28, 2022 09:11
Interleave reads from 2 FASTQ files and output to STDOUT.
#!/bin/bash
# Usage: interleave_fastq.sh f.fastq r.fastq > interleaved.fastq
#
# Interleaves the reads of two FASTQ files specified on the
# command line and outputs a single FASTQ file of STDOUT.
#
# Can interleave 100 million paired reads (200 million total
# reads; a 2 x 22Gbyte files), in memory (/dev/shm), in 6m54s (414s)
#
# Latest code: https://gist.github.com/4544979
@wch
wch / speed.r
Last active January 31, 2023 01:56
Modifying objects in loops in R, and other speed pitfalls
# =============================================
# Modifying a data frame in place
# =============================================
library(ggplot2)
str(diamonds)
# Modify data frame in place, in loop
# This is super, super slow
system.time({
@Karel-Kroeze
Karel-Kroeze / split_violin_ggplot.R
Created January 31, 2018 08:09
Split Violin Plot for ggplot2
# https://stackoverflow.com/a/45614547
GeomSplitViolin <- ggproto("GeomSplitViolin", GeomViolin, draw_group = function(self, data, ..., draw_quantiles = NULL){
data <- transform(data, xminv = x - violinwidth * (x - xmin), xmaxv = x + violinwidth * (xmax - x))
grp <- data[1,'group']
newdata <- plyr::arrange(transform(data, x = if(grp%%2==1) xminv else xmaxv), if(grp%%2==1) y else -y)
newdata <- rbind(newdata[1, ], newdata, newdata[nrow(newdata), ], newdata[1, ])
newdata[c(1,nrow(newdata)-1,nrow(newdata)), 'x'] <- round(newdata[1, 'x'])
if (length(draw_quantiles) > 0 & !scales::zero_range(range(data$y))) {
stopifnot(all(draw_quantiles >= 0), all(draw_quantiles <=
1))
@benmarwick
benmarwick / rotate-axis-labels-ggplot2.R
Last active March 30, 2024 08:00
I can never remember how to rotate the x-axis labels with ggplot2: theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
# Adapted from https://stackoverflow.com/a/7267364/1036500 by Andrie de Vries
# This is it: theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
library(ggplot2)
td <- expand.grid(
hjust=c(0, 0.5, 1),
vjust=c(0, 0.5, 1),
angle=c(0, 45, 90),
@ilevantis
ilevantis / bedtools_cheatsheet.md
Last active July 9, 2024 01:49
Bedtools cheatsheet

Bedtools Cheatsheet

General:

Tools Description
flank Create new intervals from the flanks of existing intervals.
slop Adjust the size of intervals.
shift Adjust the position of intervals.
subtract Remove intervals based on overlaps b/w two files.