Skip to content

Instantly share code, notes, and snippets.

View mdshw5's full-sized avatar

Matt Shirley mdshw5

View GitHub Profile
@mdshw5
mdshw5 / printer.cfg
Last active December 18, 2021 03:41
klipper config for modified wanhao d9
# This file contains pin mappings for the Wanhao Duplicator 9 MK1,
# also sold as the Monoprice Maker Pro MK1. To use this config,
# the firmware should be compiled for the AVR atmega2560.
# See the example.cfg file for a description of available parameters.
[stepper_x]
step_pin: PF7
dir_pin: !PK0
enable_pin: !PF6
@mdshw5
mdshw5 / sunpie.R
Last active June 8, 2021 01:25
some jokey charts
title <- "Kinds of sunscreen I get to use:"
names <- c("SunSport Waterproof SPF30",
"The organic zinc kids one",
"The moisturizing one",
"The expensive one",
"The one I like")
colors <- c("#EFD8B5", "#F9EDD4", "#CDE2CE", "#82C6BD", "#5BB6CC")
data <- data.frame(values=c(80,12,5,2,1), names=factor(names, levels=names))
library(ggplot2)
library(xkcd)
@mdshw5
mdshw5 / select rows by value
Created December 11, 2019 20:49
Spotfire scripts
from Spotfire.Dxp.Application.Visuals import VisualContent
vc = vis.As[VisualContent]()
dataTable=vc.Data.DataTableReference
marking=vc.Data.MarkingReference
marking.SetSelection(marking.GetSelection(dataTable),dataTable)
import gffutils
import os.path
from pyfaidx import Fasta
gtf_path = "/path/to/gencode.gtf"
gtf_db = gtf_path + ".db"
fasta_path = "/path/to/hg38.fasta"
if os.path.exists(gtf_db):
db = gffutils.FeatureDB(gtf_db)
@mdshw5
mdshw5 / Snakefile
Created April 14, 2019 22:04
IGV headless screenshots
rule screenshot_config:
input: bam="{dataset}.sort.bam", bai="{dataset}.sort.bam.bai", calls="{dataset}.calls"
output: batch="{dataset}.igv.batch"
params: runtime="600", memory="1G", filename="{dataset}.alignments.png"
run:
import os.path
batch_template = """load {bam}
preference SAM.SHOW_CENTER_LINE false
snapshotDirectory {directory}
genome hg38
@mdshw5
mdshw5 / vcd_to_geno.py
Created October 13, 2018 20:47
gencove to DNA.land
import vcf
file = ''
with open('outfile.txt', 'w') as out:
for variant in vcf.Reader(open(file)):
if len(variant.FILTER) == 0:
if variant.is_snp:
for sample in variant.samples:
ref, alt = sample.gt_bases.replace('|', '/').split('/')
print(variant.CHROM, str(variant.POS), ref, alt, sep='\t', file=out)
@mdshw5
mdshw5 / answer.py
Created March 22, 2018 01:16
biostars 305027
from simplesam import Reader
with Reader(open("input.sam")) as sam, open("output.fastq", "w") as fastq:
for read in sam:
fastq.write("@%s\n" % read.qname)
fastq.write("%s\n" % read.seq)
fastq.write("+\n")
fastq.write("%s\n" % read.qual)
@mdshw5
mdshw5 / bug.py
Created January 7, 2018 04:02
Minimal example for mdshw5/pyfaidx #125
from Bio import bgzf
with bgzf.open('Homo_sapiens.GRCh38.dna.primary_assembly.fa.gz') as fasta:
fasta.tell()
for line in fasta:
if line.startswith('>'):
fasta.tell()
@mdshw5
mdshw5 / answer.py
Last active March 9, 2020 15:51
biostars 265811
from pyfaidx import Fasta
# positions.txt:
# chr1 1 T
# chr1 100 C
# chr2 10 G
# ...
with open('positions.txt') as mut_table:
# mutable Fasta modifies input file in-place
@mdshw5
mdshw5 / answer.py
Last active August 1, 2017 21:07
biostars 265692
import gffutils
import pyfaidx
db = gffutils.create_db('input.gff')
fasta = pyfaidx.Fasta('input.fa')
for cds in db.features_of_type('cds', order_by='start'):
print(cds.sequence(fasta))