Skip to content

Instantly share code, notes, and snippets.

@daler
daler / gffutils-flybase-convert.py
Last active October 6, 2017 16:11
Convert FlyBase GFF to GTF.
#!/usr/bin/env python
import os
import logging
from collections import Counter
import gffutils
from gffutils.create import logger
logger.setLevel(logging.INFO)
usage = """
"""
Illustrates how to use pybedtools to count motifs along sliding windows
of UTRs from a GFF file.
This uses example data shipped with pybedtools.
"""
import pybedtools
@daler
daler / issue-99.py
Last active January 5, 2018 03:01
for pybedtools issue #99
# for pybedtools issue #99
import pybedtools
# make a demo list of chrom:start-stop strings from example data shipped with
# pybedtools
n_intervals = 20000
loc_list = []
for i, feature in enumerate(pybedtools.example_bedtool('x.bed')):
if i >= n_intervals:
"""
Demo pathfinding, with obstacles
"""
from matplotlib import pyplot as plt
import networkx as nx
GRID_SIZE = [100, 100]
G = nx.grid_graph(dim=GRID_SIZE)
@daler
daler / gffutils-seq.py
Created February 6, 2014 13:09
demo for getting sequences for GFF features
"""
Demonstration of getting the coding sequence for each alterative isoform of
each gene in a GFF file.
Uses pybedtools.BedTool.seq to extract sequences from a FASTA file.
"""
import gffutils
import pybedtools
from gffutils.helpers import asinterval
@daler
daler / gffutils-gtf.py
Last active August 29, 2015 14:00
infer GTF genes, for biostars #99287
import gffutils
# Import the GTF file into a sqlite3 database.
# This only ever has to be done once.
db = gffutils.create_db("example.gtf", dbfn='example.gtf.db')
# In other scripts, you can connect to the database like this:
db = gffutils.FeatureDB('example.gtf.db')
# Note that gene and transcript have been inferred
@daler
daler / universal-metaseq-installer.sh
Last active July 31, 2019 07:58
install bedtools, samtools, tabix, bigWigSummary, and an isolated miniconda Python installation for testing metaseq
#!/bin/bash
set -e
# Defaults ------------------------------------------------------
MINICONDA_DIR="${HOME}/miniconda"
INSTALL_DIR="$(pwd)/tools"
TO_INSTALL="bedtools,samtools,tabix,bigWigSummary"
INSTALL_MINICONDA=1
@daler
daler / download-metaseq-supplemental.py
Last active August 29, 2015 14:02
Download supplemental data for the metaseq manuscript
#!/usr/bin/env python
import sys
import os
import errno
import argparse
import logging
from urllib2 import urlopen
from urllib2 import Request
from socket import error as SocketError
@daler
daler / ftpes-downloader.py
Created July 23, 2014 15:45
Sync files (downloading only) over FTP with explicit SSL/TLS
#!/usr/bin/env python
import os
import sys
import platform
import argparse
import ftplib
import time
import netrc
from fnmatch import fnmatch
@daler
daler / pybedtools-issue-110.py
Created August 14, 2014 12:04
pybedtools issue #110
import pybedtools
import pandas
def split_coverage(x):
"""
Split a coverage file created using bedtools coverage -hist -- which will
have trailing "all" hist lines -- into 1) a BedTool object with valid BED
lines and 2) a pandas DataFrame of all coverage, parsed from the trailing
"all" lines.