# -*- coding: utf-8 -*-
'''
.. module:: genomics.mapreduce
   :synopsis: MapReduce framework
   :noindex:
   :copyright: Copyright 2014 by Tiago Antao
   :license: GNU Affero, see LICENSE for details

.. moduleauthor:: Tiago Antao <tra@popgen.net>

'''
import pickle
import tempfile

import genomics

mr_dir = genomics.cfg.mr_dir


def pickle_in(datum):
    w, fname = tempfile.mkstemp(dir=mr_dir)
    pickle.dump(datum, w)
    w.close()
    return fname

@@ -246,16 +246,26 @@
 t%3E%0A%0A'''%0A
+import os%0A
 import p
@@ -270,16 +270,16 @@
  pickle%0A
-
 import t
@@ -366,15 +366,8 @@
    w
-, fname
  = t
@@ -378,26 +378,51 @@
 ile.
-mkstemp(dir=mr_dir
+NamedTemporaryFile(dir=mr_dir, delete=False
 )%0A  
@@ -470,14 +470,15 @@
  return 
-f
+w.
 name%0A

correct fds