code: def append(args):
      
      p = OptionParser(append.__doc__)
      p.add_option("--prepend", help="Prepend string to read names")
      opts, args = p.parse_args(args)
  
      if len(args) != 1:
          sys.exit(not p.print_help())
  
      bamfile, = args
      prepend = opts.prepend
  
      icmd = "samtools view -h {0}".format(bamfile)
      bamfile = bamfile.rsplit(".", 1)[0] + ".append.bam"
      ocmd = "samtools view -b -@ 64 - -o {0}".format(bamfile)
      p = Popen(ocmd, stdin=PIPE)
      for row in popen(icmd):
          if row[0] == '@':
              print(row.strip(), file=p.stdin)
          else:
              s = SamLine(row)
              if prepend:
                  s.qname = prepend + "_" + s.qname
              else:
                  s.update_readname()
              print(s, file=p.stdin)
docs: %prog append bamfile
  
      Append /1 or /2 to read names. Useful for using the Tophat2 bam file for
      training AUGUSTUS gene models.