Skip to content

Instantly share code, notes, and snippets.

View dpryan79's full-sized avatar

Devon Ryan dpryan79

  • Genedata AG
  • Basel, Switzerland / Freiburg, Germany
View GitHub Profile
#include "htslib/sam.h"
#include "htslib/bgzf.h"
#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
void process_alignment(bam1_t *b, bam_hdr_t *hdr, FILE *of, int length) {
int32_t pos = b->core.pos, apos = 0;
int i, j, op, op_len;
@dpryan79
dpryan79 / example.sam
Created May 14, 2015 08:10
An example alignment that will be assigned an incorrect bin
@HD VN:1.0
@SQ SN:1 LN:195471971
39V34V1:69:D265MACXX:3:1213:20484:44810 133 1 11042802 0 35M15S = 11042802 0 CTCCCCCCTCCCCCCCCCCCCACCTCTTTGCCCTGGGGTCCCCCCTTTGT <'7BBB############################################ XC:i:35
#!/usr/bin/env python
# This is just a quick hack and hasn't been tested, but it'll likely work
import pysam
import argparse
import gzip
def writeAlignment(of, al):
name = al.query_name
seq = al.query_sequence
qual = al.query_qualities
#!/usr/bin/env python
e2g = []
e2u = []
g2e = []
g2u = []
u2e = []
u2g = []
ifile = open("GCA_000001405.22_GRCh38.p7_assembly_report.txt", "r")
for line in ifile:
if line.startswith("#"):
@dpryan79
dpryan79 / slack.py
Last active February 16, 2017 21:15
This is an only partially tested script to check that various NFS servers are still working and post messages to slack accordingly.
#!/usr/bin/env python3
import urllib.request
import json
from subprocess import Popen
from time import sleep
def checkUp(path, timeout):
p = Popen(['ls', path])
try:
@dpryan79
dpryan79 / BamToInsertsizeBigWig.py
Last active April 24, 2017 11:35
Convert a BAM file to a bigWig or bedGraph file containing the mean insert size (uses the deepTools API)
#!/usr/bin/env python
import deeptools.utilities
from deeptools import bamHandler
from deeptools import mapReduce
from deeptools import writeBedGraph
from deeptools import utilities
from deeptools.utilities import getCommonChrNames, toBytes
import sys
import shutil
@dpryan79
dpryan79 / estimateReadFiltering.py
Last active May 4, 2017 13:12
estimate read filtering using deepTools
#!/usr/bin/env python
import argparse
import numpy as np
import sys
from deeptools import parserCommon, bamHandler, utilities
from deeptools.mapReduce import mapReduce
from deeptools._version import __version__
import deeptools.config as cfg
@dpryan79
dpryan79 / convertBigWigChroms.py
Last active September 30, 2024 06:07
Convert chromosome names in a bigWig file
#!/usr/bin/env python
import argparse
import pyBigWig
parser = argparse.ArgumentParser(description="Convert the chromosome names of a bigWig file.")
parser.add_argument("conv", metavar="conversion.txt", help="Text file with two columns, the first a chromosome name and the second the converted chromosome name.")
parser.add_argument("input", metavar="input.bigWig", help="Input bigWig file")
parser.add_argument("output", metavar="output.bigWig", help="Output bigWig file name")
args = parser.parse_args()
@dpryan79
dpryan79 / README.md
Created September 2, 2018 14:00
Reproduction of snakemake issue #916

This demonstrates the issue discussed in https://bitbucket.org/snakemake/snakemake/issues/916/integrated-r-scripts-and-directory

To reproduce that and test any fixes, simply clone this github respository and chmod -R a-w it. Then go to a different directory and snakemake -s path/to/the/snakefile/here. With an unpatched copy of snakemake you'll get a permissions error. Note that the Snakefile has examples using R and Rmd files, so you'll need to ensure that R is in your PATH.

@dpryan79
dpryan79 / findSites.py
Created May 13, 2019 20:11
Generate a blacklist file of polyX stretches of a given minimum length not within a specified distance of a TES
#!/usr/bin/env python
# This can take up to ~20 minutes and use up to ~2GB RAM for mammals
import argparse
import py2bit
from deeptoolsintervals import GTF, tree
from deeptoolsintervals.parse import openPossiblyCompressed, parseExonBounds, findRandomLabel
parser = argparse.ArgumentParser(description="Generate a blacklist file of polyX stretches of a given minimum length not within a specified distance of a TES")
parser.add_argument("--output", "-o", help="Output file", required=True)
parser.add_argument("--tb", help="2bit file", required=True)