Skip to content

Instantly share code, notes, and snippets.

View ArtPoon's full-sized avatar

Art Poon ArtPoon

View GitHub Profile
import random
import argparse
description = """
Random permutation of FASTA file.
This script reads a FASTA-formatted file containing aligned sequences and
applies a random permutation of alignment columns (nucleotide sites),
writing the result to a new FASTA file. A random permutation changes the
order of a sequence. For example, (1,2,3,4,5) may become (4,2,1,3,5).
@ArtPoon
ArtPoon / mangolin.py
Created July 23, 2021 17:43
MPI-enabled Pangolin (SARS-CoV-2 lineage classification)
import sys
import lzma
import os
import csv
import subprocess
import tempfile
from mpi4py import MPI
comm = MPI.COMM_WORLD
my_rank = comm.Get_rank()
@ArtPoon
ArtPoon / canada-data-sharing.R
Last active January 21, 2021 14:48
R script for generating a graphic of SARS-CoV-2 genome data availability from Canada
# Let 25,000 be a circle of unit radius (area = pi)
require(ggfree)
png(file="~/Desktop/canada-data-sharing.png", width=5*200, height=5.25*200, res=200)
par(mar=c(1,1,3,1), family='Palatino', bg=rgb(.14, .12, .27), xpd=NA)
plot(NA, xlim=c(-1, 1), ylim=c(0, 2),
xaxt='n', yaxt='n', xlab=NA, ylab=NA, bty='n')
@ArtPoon
ArtPoon / plot-skyline.R
Last active August 20, 2023 04:58
Generate a Bayesian skyline plot from BEAST log files using R
require(ape)
#' get.intervals
#'
#' Scan through BEAST tree log line-by-line and parse each
#' Newick string to retrieve the coalescent intervals
#'
#' @param treefile: (character) relative or absolute path to trees log file
#' @return List containing objects of class coalescentIntervals (ape) keyed
#' by state (MCMC step number)
@ArtPoon
ArtPoon / batch-micall.py
Created September 5, 2019 03:32
Python script for running a batch processing job with MiCall-Lite
import os
import sys
import csv
from glob import glob
import argparse
from micall.core.parse_interop import read_errors, write_phix_csv
from micall.core.filter_quality import report_bad_cycles
from micall.core.censor_fastq import censor
from micall.core.prelim_map import prelim_map
@ArtPoon
ArtPoon / gist:42facbf7a1ffde281da001daa9e7e24b
Last active August 9, 2019 02:37
Patch for ggridge corn R script
require(ggfree)
# prep lists of data
attach(pheno.sel)
l1 <- split(Oil[Exp=='IHO'], Year[Exp=='IHO'])
l2 <- split(Oil[Exp=='ILO'], Year[Exp=='ILO'])
# ILO missing data for 1985
z <- which(names(l2)=='1984')
l2 <- c(l2[1:z], list('1985'=numeric(0)), l2[(z+1):length(l2)])
@ArtPoon
ArtPoon / add-grid.R
Created July 19, 2019 15:24
Generic R function to add a ggplot2-style grid to the background of the current plot
add.grid <- function(fg.col='white', bg.col='ivory2', lwd.major=3, lwd.minor=1) {
# call this after plot() but *before* drawing any data with points() or lines()
u <- par('usr') # get plot region dimensions
x <- par('xaxp')
y <- par('yaxp')
# fill background
rect(xl=u[1], yb=u[3], xr=u[2], yt=u[4], col=bg.col, border=NA)
x.major <- seq(x[1], x[2], length.out=x[3]+1)
import urllib.request as ur, random, json, webbrowser
aid=','.join([str(random.randint(0,4e6)) for i in range(20)])
r=ur.urlopen("https://itunes.apple.com/lookup?amgAlbumId="+aid)
res=json.loads(r.read())
album=res['results'][0]['collectionViewUrl']
webbrowser.open(album)
@ArtPoon
ArtPoon / get_terminals.R
Last active January 24, 2017 18:07
Emulate functionality of BioPython's Phylo.get_terminals() for ape:phylo objects in R
get.terminals <- function(node, tree) {
parents <- c(node)
tips <- c()
while (length(parents) > 0) {
for (parent in parents) {
children <- tree$edge[which(tree$edge[,1]==parent),2]
parents <- parents[parents!=parent]
if (length(children) > 0) {
parents <- c(parents, children)
} else {
@ArtPoon
ArtPoon / sierra.py
Created September 8, 2016 18:28
A simple Python script using the Stanford HIVdb Sierra web service to score HIV PR-RT sequences in an input FASTA. Requires the `suds` module.
import argparse
from suds.client import Client
import sys
import re
def iter_fasta (handle):
header = None
sequence = ''
for line in handle:
if line.startswith('$'):