User:ShawnDouglas/scripts: Difference between revisions

From OpenWetWare
Jump to navigationJump to search
mNo edit summary
(clean up some old python code)
 
(2 intermediate revisions by the same user not shown)
Line 8: Line 8:
*[[/hexgui.py]] - Tk GUI for honeycomb lattice program
*[[/hexgui.py]] - Tk GUI for honeycomb lattice program


'''Misc'''
'''DNA sequence manipulation'''
*reverse complement
 
<pre>
*reverse complement & remove whitespace
 
<syntaxhighlight lang="python">
complement = string.maketrans('ACGTacgt','TGCAtgca')
complement = string.maketrans('ACGTacgt','TGCAtgca')
def comp(s):
def comp(s):
   return s.translate(complement)[::-1]
   return s.translate(complement)[::-1]
</pre>
*replace mac return character ('\r') with unix return ('\n')
<pre>
cat foo | tr '\r' '\n' > bar
mv bar foo
</pre>
*print first n chars of STDIN
<pre>
#!/usr/bin/python
import string
import sys
import fileinput


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


seq = ''
</syntaxhighlight>


if len(sys.argv) > 1:
  n = int(sys.argv[1])
else:
  sys.exit("usage: " + sys.argv[0] + " [length]")


# read in sequence
*replace mac return character ('\r') with unix return ('\n')
for line in fileinput.input("-"):
  seq = seq + nowhite(line)
 
#seq = seq[offset:] + seq[:offset]    # wrap around first offset bases
 
# print last n chars
#print seq[-n:]
 
# print first n chars
print seq[:n]
</pre>
 
*Check for restriction site
<pre>
<pre>
##
cat foo | tr '\r' '\n' > bar
# return True if s DOES contain any restriction sites
mv bar foo
# return False if s DOES NOT contain any restriction sites
##
def hasresite(s):
  BamHI = 'ggatcc'
  EcoRI = 'gaattc'
  FokI = 'ggatg'
  HindIII = 'aagctt'
  BglII = 'agatct'
  XbaI = 'tctaga'
  XhoI = 'ctcgag'
  BbvCIA = 'cctcagc'
  BbvCIB = antisense(BbvCIA)
 
  result = False
 
  if s.count(BamHI) > 0:
    #print 'BamHI found'
    result = True
  elif s.count(EcoRI) > 0:
    #print 'EcoRI found'
    result = True
  elif s.count(FokI) > 0:
    #print 'FokI found'
    result = True
  elif s.count(HindIII) > 0:
    #print 'HindIII found'
    result = True
  elif s.count(BglII) > 0:
    #print 'BglII found'
    result = True
  elif s.count(XbaI) > 0:
    #print 'XbaI found'
    result = True
  elif s.count(XhoI) > 0:
    #print 'XhoI found'
    result = True
  elif s.count(BbvCIA) > 0:
    #print 'BbvCI.IA found'
    result = True
  elif s.count(BbvCIB) > 0:
    #print 'BbvCI.IB found'
    result = True
 
  return result
</pre>
</pre>

Latest revision as of 11:56, 12 February 2012

PCR

  • /make-pcr-oligos.py - given target sequence, generate oligos that can be used for PCR assembly of that sequence
  • /random-sequence.py - generate random DNA sequence of specified length
  • /primer.py - given upstream and downstream sense sequence of region to amplify, print out correct primers

Nanostructures

  • /toehold.py - given input sequence generate N-mers orthogonal (to seq and its complement) to be used as toeholds
  • /hexgui.py - Tk GUI for honeycomb lattice program

DNA sequence manipulation

  • reverse complement & remove whitespace

<syntaxhighlight lang="python"> complement = string.maketrans('ACGTacgt','TGCAtgca') def comp(s):

 return s.translate(complement)[::-1]

def nowhite(s):

 return .join([c for c in s if c in string.letters])

</syntaxhighlight>


  • replace mac return character ('\r') with unix return ('\n')
cat foo | tr '\r' '\n' > bar
mv bar foo