User:ShawnDouglas/scripts/toehold.py

From OpenWetWare
Jump to navigationJump to search
#!/usr/bin/env python

# encoding: utf-8

# toehold.py
# Copyright (c) 2006 Shawn Douglas

import sys
import os
import random
import string
import fileinput

N = 7   # Number of toeholds
L = 12  # Length in bases

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

def rev(s):
  return s[::-1]

complement = string.maketrans('ACGTacgt','TGCAtgca')
def comp(s):
  return rev(s.translate(complement))

def getinput():
  s = ''
  for line in fileinput.input("-"):       
    s += nowhite(string.rstrip(line)).upper()
  return s

def randseq(l):
  s = []
  for i in range(l):
    s.append(random.choice(['A', 'C', 'G', 'T']))
  return ''.join(s)

def main():
  s = getinput()
  r = comp(s)
  toehold = []
  while (len(toehold) < N):
    foo = randseq(L)
    if (s.find(foo) > 0) | (r.find(foo) > 0):
      continue    
    toehold.append(foo)
  for toe in toehold:
    print toe

if __name__ == '__main__':
    main()