Skip to content

Instantly share code, notes, and snippets.

View clintval's full-sized avatar

Clint Valentine clintval

View GitHub Profile
@clintval
clintval / pandas-comma-fmt.py
Created February 25, 2018 00:28
Format DataFrame's with better integer representation e.g. 1,000,00.00
import contextlib
import sys
import pandas as pd
try:
import pandas.io.formats.format as pf
except ImportError:
import pandas.formats.format as pf
except ImportError:
@clintval
clintval / IGV-static.py
Created March 7, 2018 23:07
Generate a static image of a Jupyter IGV canvas
class IgvCanvasToStatic(object):
def __init__(self):
self._javascript = """
// Converts canvas to an image
function convertCanvasToImage(canvas)
{
var image = canvas.toDataURL("image/png");
return '<img src="' + image + '"/>';
}
@clintval
clintval / dcs-pipeline-template.sh
Created March 7, 2018 23:10
Academic DCS pipeline v2.0 from DOI:10.1073/pnas.1700759114
#!/bin.sh
# request Bourne shell as shell for job
#$ -S /bin/sh
#$ -cwd
#$ -V
#$ -m e
#$ -pe whole_nodes 7
#$ -M [email protected]
###############################
module add bwa/0.6.1
@clintval
clintval / aflatoxin-biomarker.pnas.1700759114.json
Created March 7, 2018 23:10
Data manifest from DOI:10.1073/pnas.1700759114
{
"A10": [
0.0034329041, 0.0137316166, 0.0344053282, 0.0188924926, 0.0240140593,
0.0212451426, 0.0821539635, 0.0064712216, 0.0620039955, 0.0524827040,
0.2530320358, 0.0485341620, 0.0114430138, 0.0159038497, 0.0332954789,
0.0099940168, 0.0068658083, 0.0000000000, 0.0062555142, 0.0113354956,
0.0026682288, 0.0070817142, 0.0072488791, 0.0161780540, 0.0074404795,
0.0071567324, 0.0295204042, 0.0000000000, 0.0022886028, 0.0000000000,
0.0030268617, 0.0099940168, 0.0000000000, 0.0000000000, 0.0218942998,
0.0000000000, 0.0000000000, 0.0035408571, 0.0144977583, 0.0032356108,
@clintval
clintval / cosmic-all-muts.py
Last active March 7, 2018 23:18
Faux-object-oriented model for COSMIC used in DOI:10.1073/pnas.1700759114
import textwrap
from operator import itemgetter
from Bio.Seq import reverse_complement
from pyfaidx import Fasta, FetchError
from collections import Counter, defaultdict, OrderedDict
from pymutagenesis.seq import *
link = '<a target="_blank" href={}>{}</a>'
@clintval
clintval / pileup.py
Created March 7, 2018 23:13
An untested Python pileup parser - do not use
import re
import csv
import textwrap
import matplotlib.pyplot as plt
from collections import Counter
class ReadError(LookupError):
"""Raise this when a property of a read is called for and no data exists"""
pass
@clintval
clintval / mutpos-model.py
Last active March 7, 2018 23:18
Mutpos utilities, a faux-object-oriented model but please use VCF
from Bio.Seq import Seq
from Bio.Seq import reverse_complement
dna_bases = ('A', 'C', 'G', 'T')
purines = ('A', 'G')
pyrimidines = ('C', 'T')
transitions = ('A>T', 'C>G', 'G>C', 'T>A')
transversions = ('A>C', 'A>G', 'C>A', 'C>T', 'G>A', 'G>T', 'T>C', 'T>G')
@clintval
clintval / get-karyotype-fasta-demo.sh
Created March 19, 2018 17:39
Grab karyotype assembly from a reference genome
# Pipe in the karyotype chromosomes
# Prefix each chromosome name with `chr` if necessary
# Slice the contigs from the source indexed FASTA with samtools
# Output to file
build="${build}"
echo {1..20} X Y M \
| xargs printf -- 'chr%s ' \
| xargs samtools faidx "${build}".fa \
@clintval
clintval / spinner.py
Created March 20, 2018 23:09
A non-blocking terminal spinner for Python
import sys
import threading
import time
# Really though just use a library for this:
# https://github.com/ManrajGrover/halo
#
class Spinner:
"""https://stackoverflow.com/a/39504463/3727678"""
busy = False
#!/bin/bash
#
# drawHelix.sh <input.fa>
#
# Reads a fasta input file and stream a B-Form DNA
# helix with the sequence to STDOUT
#
## __ __ __ ___
### |__) | / \ /__` \ / |\ | | /\ \_/
#### |__) | \__/ .__/ | | \| | /~~\ / \