IGEM:Harvard/2006/Container Design 5/Python Code

From OpenWetWare

Jump to: navigation, search




scaffold splitting

Barrel

!/usr/bin/python

import string
import sys
import fileinput

def nowhite(s):
  return ''.join([c for c in s if c in string.letters])

seq = ''

# read in sequence
for line in fileinput.input("-"):
  seq = seq + nowhite(line)

box_1 = 96 * 32 + 72
loop = 66
box_2 = 11 + 12 + 96 * 6 + 68
box_3 = 16 + 12 + 6 * 96 + 65
box_4 = 19 + 12 + 6 * 96 + 65
box_5 = 19 + 12 + 6 * 96 + 68
box_6 = 16 + 12 + 6 * 96 + 72
box_7 = 12 + 12 + 3 * 96

box_1_seq = seq[:box_1]
seq = seq[box_1:]
loop_1_seq = seq[:loop]
seq = seq[loop:]
box_2_seq = seq[:box_2]
seq = seq[box_2:]
loop_2_seq = seq[:loop]
seq = seq[loop:]  
box_3_seq = seq[:box_3]
seq = seq[box_3:]
loop_3_seq = seq[:loop]
seq = seq[loop:]
box_4_seq = seq[:box_4]
seq = seq[box_4:]
loop_4_seq = seq[:loop]
seq = seq[loop:]
box_5_seq = seq[:box_5]
seq = seq[box_5:]
loop_5_seq = seq[:loop] 
seq = seq[loop:]
box_6_seq = seq[:box_6]
seq = seq[box_6:]
loop_6_seq = seq[:loop]
seq = seq[loop:]
box_7_seq = seq[:box_7]
seq = seq[box_7:]

extra_scaffold = seq
barrel = box_1_seq + box_2_seq + box_3_seq + box_4_seq + box_5_seq + box_6_seq + box_7_seq

#print out the length of each segment and its sequence

barrel_file = file('barrel_scaffold.txt', 'w')

print len(barrel)
print barrel
barrel_file.write(barrel)

Lids

#!/usr/bin/python

import string
import sys
import fileinput

def nowhite(s):
  return ''.join([c for c in s if c in string.letters])

seq = ''

# read in sequence
for line in fileinput.input("-"):
  seq = seq + nowhite(line)

scaffold_len = 7572
lid_1 = 96 * 38
lid_2 = 96 * 38
linker_len = scaffold_len - lid_1 - lid_2
linker_1 = linker_len / 2

#store first segment up to end of lid 1
lid_1_seq = seq[:lid_1]
#reset sequence to start at end of lid 1
seq = seq[lid_1:]
linker_1_seq = seq[:linker_1]
seq = seq[linker_1:]
lid_2_seq = seq[:lid_2]
seq = seq[lid_2:]
#linker 2 is the rest of the scaffold
linker_2_seq = seq

# check to make sure linker 1 and linker 2 are the same length
if(len(linker_1_seq) != len(linker_2_seq)):
        print 'Error: linker 1 is not the same length as linker 2'

#print out the length of each segment and its sequence

lid_1_file = file('lid_1_scaffold.txt', 'w')
lid_2_file = file('lid_2_scaffold.txt', 'w')

print len(lid_1_seq)   
print lid_1_seq
lid_1_file.write(lid_1_seq)
print len(linker_1_seq)
print linker_1_seq  
print len(lid_2_seq)   
print lid_2_seq  
lid_2_file.write(lid_2_seq)
print len(linker_2_seq)
print linker_2_seq


Lewis's Automated PyGame Code

Here's a link to a python file that automatically creates a schematic. Call maked(inf,outf) where inf is a token list and outf is the file you'd like to output to (should be .bmp). It uses a nifty module called pygame. I haven't tried it out on Macs yet. Still, it gives fairly colorful results.

Code

Design 6 schematic

Update: v.1.1 is smart enough to create an appropriately sized bitmap, attempts to avoid the overlapping strand problem of v.1, and has slightly better colors. Unfortunately, it runs slower due to a large bitmap size and some exponentiation that's in there for kicks.

v.1.1

Design 6 schematic v.1.1

Personal tools