code: def needle(args):
      
      from jcvi.formats.fasta import Fasta, SeqIO
  
      p = OptionParser(needle.__doc__)
  
      opts, args = p.parse_args(args)
  
      if len(args) != 3:
          sys.exit(not p.print_help())
  
      manager = mp.Manager()
      results = manager.list()
      needle_pool = mp.Pool(processes=mp.cpu_count())
  
      pairsfile, apep, bpep = args
      afasta, bfasta = Fasta(apep), Fasta(bpep)
      fp = must_open(pairsfile)
      for i, row in enumerate(fp):
          a, b = row.split()
          a, b = afasta[a], bfasta[b]
          fa, fb = must_open("{0}_{1}_a.fasta".format(pairsfile, i), "w"), \
              must_open("{0}_{1}_b.fasta".format(pairsfile, i), "w")
          SeqIO.write([a], fa, "fasta")
          SeqIO.write([b], fb, "fasta")
          fa.close()
          fb.close()
  
          needlefile = "{0}_{1}_ab.needle".format(pairsfile, i)
          needle_pool.apply_async(_needle, \
              (fa.name, fb.name, needlefile, a.id, b.id, results))
  
      needle_pool.close()
      needle_pool.join()
  
      fp.close()
  
      scoresfile = "{0}.scores".format(pairsfile.rsplit(".")[0])
      fw = must_open(scoresfile, "w")
      for result in results:
          print(result, file=fw)
      fw.close()
docs: %prog needle nw.pairs a.pep.fasta b.pep.fasta
  
      Take protein pairs and needle them
      Automatically writes output file `nw.scores`