Skip to content

Instantly share code, notes, and snippets.

@lennax
lennax / mailstatus.py
Created July 29, 2015 19:43
call process and send unicode mail with status
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2015 Lenna X. Peterson
# All rights reserved
import os
import socket
import subprocess
import sys
import re
units = {
'day': 'd',
'hour': 'h',
'minute': 'm',
'second': 's',
}
# Matches only valid data (I hope)
@lennax
lennax / float.py
Created March 9, 2012 05:23
float regex
float_t = r"[+-]?(\d*\.\d+|\d+\.?)(e{1,2}[+-]?\d+)?"
@lennax
lennax / __init__.py
Created April 21, 2012 00:28
Conditional NumPyPy import
"""
This is located inside a fake numpy, and could allow "import numpy"
to work invisibly on both Python and PyPy.
Not quite sure how to get files to find it.
In any case, NumPyPy is only a partial implementation of NumPy,
so it's probably not ready for unintended/untested/automatic use.
"""
import sys
# Delete current directory from module search path
@lennax
lennax / VariantSkeleton.py
Created May 9, 2012 23:22
Skeleton for a genomic variant interface
class Variant(object):
"""This is the top level class for genomic variants"""
def __init__(self, filename, filetype=None, gvfreader=None, vcfreader=None):
"""
Uses the default parser Wrappers unless otherwise specified.
Currently supported arguments to filetype are "vcf" and "gvf".
If filetype is not specified, guessed from file extension.
"""
self.filename = filename
if filetype is not None:
@lennax
lennax / supertest.py
Created July 1, 2012 17:27
Quick example of multiple inheritance for alts
class _AltRecord(object):
def __init__(self, alt_type, **kwargs):
print "_AltRecord"
super(_AltRecord, self).__init__(**kwargs)
self.alt_type = alt_type
class _Substitution(_AltRecord):
def __init__(self, sequence, **kwargs):
print "_Substitution"
if len(sequence) == 1:
@lennax
lennax / progress_spinner.py
Created July 22, 2012 22:42
Updating a single printed line
#!/usr/bin/python
import sys
import time
spinner = ["-", "\\", "|", "/"]
print "This is the header row"
try:
for i in range(10):
@lennax
lennax / describe_align.py
Created November 4, 2015 20:37
Describe alignment
sbjct_aln = "C-GGLK-GAPFLAC"
query_aln = "CHG--KTGASFLQC"
gap = "-"
sbjct_idx = -1
query_idx = -1
for sbjct_resn, query_resn in zip(sbjct_aln, query_aln):
# Check for gaps
-- More than one chain is possible for each code
CREATE TABLE IF NOT EXISTS smallest
(
id INTEGER PRIMARY KEY NOT NULL,
code TEXT NOT NULL,
chain TEXT NOT NULL,
timestamp TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS ligands
@lennax
lennax / bareclass.py
Last active April 21, 2017 22:49
Minimal class
#!/usr/bin/env python
from __future__ import division
import argparse
import glob
import inspect
import logging
import os