Skip to content

Instantly share code, notes, and snippets.

@gregpinero
gregpinero / insert_barcodes.py
Created April 19, 2012 18:52
Randomly insert genetic barcodes (and weighted randomly chosen quality values) as the first N bp of each read in a FASTQ file.
"""
Randomly insert genetic barcodes (and weighted randomly chosen quality values) as the first N bp of each read in a FASTQ file.
Greg Pinero 2012
"""
import sys
import argparse
@gregpinero
gregpinero / get_free_memory
Created April 24, 2012 17:42
Try to figure out how much memory is free on a Unix system. Returns free memory in mB.
def get_free_memory():
"""
Try to figure out how much memory is free on a Unix system.
Returns free memory in mB.
"""
data = open("/proc/meminfo", 'rt').readlines()
free = 0
for line in data:
if line.startswith("MemFree") or line.startswith("Buffers") or line.startswith("Cached"):
items = line.split()
@gregpinero
gregpinero / clean_fasta_descs.py
Created October 8, 2012 18:31
Clean up a FASTA file that has unwanted characters in the description lines
import re
infile = 'dsim-all-chromosome-r1.3.reassembly1.updated_wsu1.fasta'
ref_count = 0
for line in open(infile,'r'):
if line.startswith('>'):
ref_count += 1
print '>' + re.sub(r'[^0-9a-zA-Z_]', '', line)[:50]
else:
print line,
@gregpinero
gregpinero / read_write_fastq
Created July 8, 2013 17:48
Quick functions for reading and writing fastq files.
"""Quick functions for reading and writing FASTQ"""
def read_fastq(filehandle):
''' Return dictionary with 'seq_id', 'seq', 'qual_id', and 'qual' '''
record_line = 0
read_number = 0
fastq_record = dict()
for line in filehandle:
record_line += 1
@gregpinero
gregpinero / Perl Syntax
Created November 21, 2014 17:47
Perl Syntax Basics
Perl syntax basics:
Perl ===
Start interactive interpreter:
perl -de 1
==== Syntax Basics ====
<pre><nowiki>
data types: $scalars, @lists, and %hashes
""my"" makes a variable be in the scope of its block and lower. Use ""our"" for globals.
Put ""use strict"" at beginning of file to be required to declare variables.
@gregpinero
gregpinero / SQL Server Audit Logging.sql
Last active August 29, 2015 14:10
SQL Server Audit Log
--Log Insert
CREATE TRIGGER LogInsert ON [dbo].[CustomerProduct]
FOR INSERT
AS
INSERT changelog SELECT TOP 1 getdate(), 'Insert', 'CustomerProduct', CustomerID, ProductID, 'PaymenttypeID', '', Paymenttypeid FROM inserted
INSERT changelog SELECT TOP 1 getdate(), 'Insert', 'CustomerProduct', CustomerID, ProductID, 'ExpirationDate', '', convert(varchar(12), ExpirationDate, 110) FROM inserted
INSERT changelog SELECT TOP 1 getdate(), 'Insert', 'CustomerProduct', CustomerID, ProductID, 'Rate', '', Rate FROM inserted
@gregpinero
gregpinero / soap_client.py
Last active August 29, 2015 14:10
Simple SOAP Client
""""""
Sample script using Lyons ABA web service methods
""""""
import httplib
import urllib
import xml.dom.minidom
#-------SETTINGS-------
@gregpinero
gregpinero / format.py
Created November 21, 2014 17:50
Python Formatting Functions
import re
import datetime
import math
def format_timeinterval(start, end=None):
if not end:
end = datetime.now()
return format_timedelta(end - start)
def format_secondsdelta(seconds):
@gregpinero
gregpinero / matview.sql
Created November 21, 2014 17:50
MySQL - Creating Materialized View
/*
name:
mv:
app:
note:
*/
@gregpinero
gregpinero / utilities.py
Last active August 29, 2015 14:10
Python Helper Functions
import re
import datetime
from time import time
import sys
import math
import zipfile
import pickle
from cStringIO import StringIO
from dateutil.relativedelta import relativedelta