Skip to content

Instantly share code, notes, and snippets.

@peterjc
peterjc / reportlab_ps_test.py
Last active January 2, 2016 17:09
Standalone test case originally Biopython for resting ReportLab under Python 2 and 3. Currently seeing a segmentation fault under Python 2.7, and a TypeError under Python 3.3 when testing on Mac OS X - see http://two.pairlist.net/pipermail/reportlab-users/2014-January/010972.html
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.units import inch
from reportlab.lib import colors
from reportlab.pdfbase.pdfmetrics import stringWidth
from reportlab.graphics.shapes import Drawing, String, Line, Rect, Wedge, ArcPath
from reportlab.graphics import renderPDF, renderPS
from reportlab.graphics.widgetbase import Widget
@peterjc
peterjc / make_roomba_lirc.py
Created November 11, 2013 23:40
Python script to generate
#!/usr/bin/env python
#Copyright 2013, Peter Cock. All rights reserved.
#Released under the MIT License.
"""Python scipt to generate Roomba IR codes for LIRC.
Tested under Python 2.7 and Python 3.3, example usage:
$ python make_roomba_lirc.py > roomba.conf
See also:
@peterjc
peterjc / decode_roomba_ir.py
Last active December 26, 2015 09:09
Python scipt to decode Roomba IR codes via the Linux mode2 tool. See http://astrobeano.blogspot.co.uk/2013/10/roomba-620-infrared-signals.html
#!/usr/bin/env python
#Copyright 2013, Peter Cock. All rights reserved.
#Released under the MIT License.
"""Python scipt to decode Roomba IR codes via the Linux mode2 tool.
Tested under Python 2.7 and Python 3.3, example usage:
$ mode2 -d /dev/lirc0 | python decode_roomba_ir.py
10101100 - 172 - 0xAC
10101100 - 172 - 0xAC
@peterjc
peterjc / ace_to_contig_stats.py
Created February 19, 2013 16:56
Quick Python script to extract contig summary information (lengths and number of reads, as a tabular file) from an ACE assembly file, using the Biopython ACE parser for convenience.
#!/usr/bin/env python
#Example usage:
#
# $ python ace_to_contig_stats.py < example.ace > example_stats.tsv
#
import sys
from Bio.Sequencing import Ace
sys.stdout.write("#Contig\tPadded length\tUnpadded length\tReads\n")
for contig in Ace.parse(sys.stdin):
@peterjc
peterjc / SAMv1_padded.fasta
Created May 14, 2012 10:00
SAM/BAM examples from the specification
>ref
AGCATGTTAGATAA**GATAGCTGTGCTAGTAGGCAGTCAGCGCCAT
@peterjc
peterjc / green_bottles.py
Created March 20, 2012 14:30
Simple "Green Bottles" Python script to benchmark ZLIB calls under different Python implementations + PyPy target
import zlib
import time
def decompress(comp_data):
d = zlib.decompressobj(-15) #Negative window size means no headers
uncomp_data = d.decompress(comp_data) + d.flush()
del d
return uncomp_data, zlib.crc32(uncomp_data)
def compress(orig_data):
@peterjc
peterjc / select_fastq2.py
Created September 7, 2011 16:29
Selecting FASTQ sequences by ID (Biopython with strings)
from Bio.SeqIO.QualityIO import FastqGeneralIterator
import sys
ids = set(x[:-1] for x in open(sys.argv[1]))
for title, seq, quals in FastqGeneralIterator(sys.stdin):
if title.split(None,1)[0] in ids:
print "@%s\n%s\n+\n%s\n" % (title, seq, quals)
@peterjc
peterjc / select_fastq.py
Created September 7, 2011 16:27
Selecting FASTQ sequences by ID (Biopython with SeqRecord object)
from Bio import SeqIO
import sys
ids = set(x[:-1] for x in open(sys.argv[1]))
wanted = (rec for rec in SeqIO.parse(sys.stdin, "fastq") if rec.id in ids)
SeqIO.write(wanted, sys.stdout, "fastq")
@peterjc
peterjc / brad_gff_import.py
Created August 24, 2011 02:31
Hack script to import selected folders from one git repository to another
#Copyright 2011 Peter Cock, released under GPL v3 licence
#
#Hack script to extract files in selected directories in one git
#repository and apply them to another repository using a potentially
#different directory structure.
#
#This written in Python and needs the git library, I used 0.3.2 RC1
#https://github.com/gitpython-developers/GitPython
#
#I assume when run both repositories are clean (no untracked files,