title: Replace string in a specific line using python
body: <p>I'm writing a python script to replace strings from a each text file in a directory with a specific extension (.seq). The strings replaced should only be from the second line of each file, and the output is a new subdirectory (call it clean) with the same file names as the original files, but with a *.clean suffix. The output file contains exactly the same text as the original, but with the strings replaced. I need to replace all these strings: 'K','Y','W','M','R','S' with 'N'.</p>
  
  <p>This is what I've come up with after googling. It's very messy (2nd week of programming), and it stops at copying the files into the clean directory without replacing anything. I'd really appreciate any help.</p>
  
  <p>Thanks before!</p>
  
  <pre><code>import os, shutil
  
  os.mkdir('clean')
  
  for file in os.listdir(os.getcwd()):
      if file.find('.seq') != -1:
          shutil.copy(file, 'clean')
  
  os.chdir('clean')
  
  for subdir, dirs, files in os.walk(os.getcwd()):
      for file in files:
          f = open(file, 'r')
          for line in f.read():
              if line.__contains__('&gt;'): #indicator for the first line. the first line always starts with '&gt;'. It's a FASTA file, if you've worked with dna/protein before.
                  pass
              else:
                  line.replace('M', 'N')
                  line.replace('K', 'N')
                  line.replace('Y', 'N')
                  line.replace('W', 'N')
                  line.replace('R', 'N')
                  line.replace('S', 'N')
  </code></pre>