Skip to content

Instantly share code, notes, and snippets.

View mdshw5's full-sized avatar

Matt Shirley mdshw5

View GitHub Profile
@mdshw5
mdshw5 / human-mutation.csl
Created July 7, 2012 14:31
Style definition for Human Mutation journal
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" default-locale="en-US">
<info>
<title>Human Mutation</title>
<link href="http://onlinelibrary.wiley.com/journal/10.1002/(ISSN)1098-1004/homepage/ForAuthors.html" rel="documentation"/>
<id>http://www.zotero.org/styles/human-mutation</id>
<link href="http://www.zotero.org/styles/human-mutation" rel="self"/>
<updated>2012-07-06T16:31:32+00:00</updated>
<author>
<name>Matthew Shirley</name>
@mdshw5
mdshw5 / f1000-research.csl
Created October 20, 2012 23:29
F1000 Research citation style
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0">
<info>
<title>F1000 Research</title>
<id>http://www.zotero.org/styles/f1000-research</id>
<link href="http://www.zotero.org/styles/vancouver" rel="independent-parent"/>
<link href="http://f1000research.com/author-guidelines/" rel="documentation"/>
<author>
<name>Courtney Shirley</name>
<email>[email protected]</email>
@mdshw5
mdshw5 / .bashrc
Last active November 24, 2017 10:31
bash history in each writeable working directory
#!/bin/bash
# per-directory history
shopt -s histappend # always append to history, don't replace
export PROMPT_COMMAND="builtin history -a;$PROMPT_COMMAND" # write to history file at every new prompt
export HISTTIMEFORMAT="%m/%d/%y %T "
alias cd='cd_with_local_history'
alias history='cat $HOME/.bash_history'
export HISTFILE="$PWD/.bash_cwd_history_$USER"
function cd_with_local_history()
@mdshw5
mdshw5 / py27_demo.py
Last active August 29, 2015 13:55
portable replacement for random.choice()
Python 2.7.5 (default, Oct 9 2013, 20:09:30)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.78)] on darwin
>>> x = range(100)
>>> random.seed(1)
>>> print([random.choice(x) for i in range(10)])
[13, 84, 76, 25, 49, 44, 65, 78, 9, 2]
>>> random.seed(1)
>>> print([choice(x) for i in range(10)])
[13, 84, 76, 25, 49, 44, 65, 78, 9, 2]
@mdshw5
mdshw5 / py27.py
Last active August 29, 2015 13:55
random.choice in Python 2.X vs 3.X
def choice(self, seq):
"""Choose a random element from a non-empty sequence."""
return seq[int(self.random() * len(seq))] # raises IndexError
@mdshw5
mdshw5 / choice.py
Created February 2, 2014 20:20
portable choice
import random
def choice(seq):
"""Choose a random element from a non-empty sequence.
This function produces consistent results from Python2.7 to 3.3
in contrast to random.choice(). """
return seq[int(random.random() * len(seq))]
@mdshw5
mdshw5 / sam_rules
Created February 20, 2014 16:37
snakemake include issue
rule sam_to_bam:
input: "{dataset}.sam"
output: "{dataset}.bam"
shell: "module load sharedapps samtools; samtools view -@ 8 -bSo {output} {input}"
rule bam_index:
input: "{dataset}.bam"
output: "{dataset}.bam.bai"
shell: "module load sharedapps samtools; samtools index {input} {output}"
import urllib2
from bs4 import BeautifulSoup
from icalendar import Calendar, Event
import pytz
from datetime import datetime, timedelta
def scrape_scical():
data = urllib2.urlopen('http://www.hopkinsmedicine.org/scical/').read()
soup = BeautifulSoup(data)
cal = Calendar()
cal.add('prodid', '-//Hopkins Science Calendar//mattshirley.com/scical//')
@mdshw5
mdshw5 / freetype2.pc
Created March 27, 2014 16:43
pkg-config files for custom matplotlib installation
prefix=/home/matt/.local
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Name: freetype2
Description: The freetype2 library
Version: 2.5.3
Cflags: -I${includedir}/freetype2
Libs: -L${libdir} -lfreetype
@mdshw5
mdshw5 / extract_repeats.py
Created March 31, 2014 14:23
Biostars 96573 solution
from pyfaidx import Fasta
with open("regions.txt") as regions, Fasta("sequence.fasta") as fasta:
for line in regions:
fields = line.rstrip().split()
rname, start, end = fields[4:7]
repeat = ' '.join(fields[9:11])
seq = fasta[rname][int(start)-1:int(end)-1]
print(seq.name + repeat)
print(seq.seq)