User:ShawnDouglas/scripts/toehold.py

From OpenWetWare
Revision as of 05:58, 26 June 2006 by ShawnDouglas (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
#!/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()