Skip to content

Instantly share code, notes, and snippets.

View peterk87's full-sized avatar

Peter Kruczkiewicz peterk87

  • Canadian Food Inspection Agency
  • Canada
View GitHub Profile
@peterk87
peterk87 / comparing_partitions.py
Created April 19, 2013 19:03
Python: Calculate Adjusted Wallace, Wallace and Rand coefficients, and Simpson's index of diversity
import sys
import math
def getContTable(ar1, ar2):
cont = {}
for i in xrange(0, len(ar1)):
keyAr1 = ar1[i]
keyAr2 = ar2[i]
if keyAr1 in cont:
@peterk87
peterk87 / Parse Genbank file using BioPython.py
Last active September 16, 2024 12:25
Python: Parse Genbank file using BioPython
import os
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from Bio.SeqFeature import SeqFeature, FeatureLocation
from Bio import SeqIO
# get all sequence records for the specified genbank file
recs = [rec for rec in SeqIO.parse("genbank_file.gbk", "genbank")]
# print the number of sequence records that were extracted
@peterk87
peterk87 / Python: Parse binary patterns from file and get unique patterns.py
Created April 19, 2013 18:01
Python: Parse binary patterns from file and get the unique binary patterns
# assuming that the file is tab-delimited ('\t')
delim = '\t'
# binary file path:
binary_patterns_filename = "binary_patterns.txt"
# get all of the lines in the binary patterns file
lines = [line.rstrip() for line in open(binary_patterns_filename, "r")]
# 1st line should contain the headers