def write(filename, kerneldata, hdf5_dtype=None, sid_major=True): """Writes a :class:`KernelData` to KernelHdf5 format and returns the :class:`.KernelHdf5`. :param filename: the name of the file to create :type filename: string :param kerneldata: The in-memory data that should be written to disk. :type kerneldata: :class:`KernelData` :param hdf5_dtype: None (use the .val's dtype) or a Hdf5 dtype, e.g. 'f8','f4',etc. :type hdf5_dtype: string :param col_major: Tells if vals should be stored on disk in sid_major (default) or iid_major format. :type col_major: bool :rtype: :class:`.KernelHdf5` >>> from pysnptools.snpreader import Bed >>> from pysnptools.standardizer import Unit >>> import pysnptools.util as pstutil >>> from pysnptools.util import example_file # Download and return local file name >>> bed_file = example_file('pysnptools/examples/toydata.5chrom.*','*.bed') >>> kerneldata = Bed(bed_file,count_A1=False).read_kernel(Unit()) # Create a kernel from the data in the Bed file >>> pstutil.create_directory_if_necessary("tempdir/toydata.kernel.hdf5") >>> KernelHdf5.write("tempdir/toydata.kernel.hdf5",kerneldata) # Write data in KernelHdf5 format KernelHdf5('tempdir/toydata.kernel.hdf5') """ PstHdf5.write(filename,kerneldata,hdf5_dtype=hdf5_dtype,col_major=sid_major) return KernelHdf5(filename)
def write(filename, snpdata, hdf5_dtype=None, sid_major=True): """Writes a :class:`SnpData` to SnpHdf5 format and return a the :class:`.SnpHdf5`. :param filename: the name of the file to create :type filename: string :param snpdata: The in-memory data that should be written to disk. :type snpdata: :class:`SnpData` :param hdf5_dtype: None (use the .val's dtype) or a Hdf5 dtype, e.g. 'f8','f4',etc. :type hdf5_dtype: string :param sid_major: Tells if vals should be stored on disk in sid_major (default) or iid_major format. :type sid_major: bool :rtype: :class:`.SnpHdf5` >>> from pysnptools.snpreader import SnpHdf5, Bed >>> import pysnptools.util as pstutil >>> from pysnptools.util import example_file # Download and return local file name >>> bedfile = example_file("pysnptools/examples/toydata.5chrom.*","*.bed") >>> snpdata = Bed(bedfile,count_A1=False)[:,:10].read() # Read first 10 snps from Bed format >>> pstutil.create_directory_if_necessary("tempdir/toydata10.snp.hdf5") >>> SnpHdf5.write("tempdir/toydata10.snp.hdf5",snpdata) # Write data in SnpHdf5 format SnpHdf5('tempdir/toydata10.snp.hdf5') """ PstHdf5.write(filename, snpdata, hdf5_dtype=hdf5_dtype, col_major=sid_major) return SnpHdf5(filename)
def write(filename, distdata, hdf5_dtype=None, sid_major=True): """Writes a :class:`DistData` to DistHdf5 format and return a the :class:`.DistHdf5`. :param filename: the name of the file to create :type filename: string :param distdata: The in-memory data that should be written to disk. :type distdata: :class:`DistData` :param hdf5_dtype: None (use the .val's dtype) or a Hdf5 dtype, e.g. 'f8','f4',etc. :type hdf5_dtype: string :param sid_major: Tells if vals should be stored on disk in sid_major (default) or iid_major format. :type col_major: bool :rtype: :class:`.DistHdf5` >>> from pysnptools.distreader import DistHdf5, Bgen >>> import pysnptools.util as pstutil >>> from pysnptools.util import example_file # Download and return local file name >>> bgen_file = example_file("pysnptools/examples/2500x100.bgen") >>> distdata = Bgen(bgen_file)[:,:10].read() # Read first 10 snps from BGEN format >>> pstutil.create_directory_if_necessary("tempdir/toydata10.dist.hdf5") >>> DistHdf5.write("tempdir/toydata10.dist.hdf5",distdata) # Write data in DistHdf5 format DistHdf5('tempdir/toydata10.dist.hdf5') """ PstHdf5.write(filename, distdata, hdf5_dtype=hdf5_dtype, col_major=sid_major) return DistHdf5(filename)
def write(filename, kerneldata, hdf5_dtype=None, sid_major=True): """Writes a :class:`KernelData` to KernelHdf5 format. :param filename: the name of the file to create :type filename: string :param kerneldata: The in-memory data that should be written to disk. :type kerneldata: :class:`KernelData` :param hdf5_dtype: None (use the .val's dtype) or a Hdf5 dtype, e.g. 'f8','f4',etc. :type hdf5_dtype: string :param col_major: Tells if vals should be stored on disk in sid_major (default) or iid_major format. :type col_major: bool """ # >>> from pysnptools.snpreader import Bed # >>> from pysnptools.standardizer import Unit # >>> import pysnptools.util as pstutil # >>> kerneldata = Bed('pysnptools/examples/toydata.bed',count_A1=False).read_kernel(Unit()) # Create a kernel from the data in the Bed file # >>> pstutil.create_directory_if_necessary(b"tempdir/toydata.kernel.hdf5") # >>> KernelHdf5.write("tempdir/toydata.kernel.hdf5",kerneldata) # Write data in KernelHdf5 format PstHdf5.write(filename,kerneldata,hdf5_dtype=hdf5_dtype,col_major=sid_major)
def write(filename, snpdata, hdf5_dtype=None, sid_major=True): """Writes a :class:`SnpData` to SnpHdf5 format. :param filename: the name of the file to create :type filename: string :param snpdata: The in-memory data that should be written to disk. :type snpdata: :class:`SnpData` :param hdf5_dtype: None (use the .val's dtype) or a Hdf5 dtype, e.g. 'f8','f4',etc. :type hdf5_dtype: string :param col_major: Tells if vals should be stored on disk in sid_major (default) or iid_major format. :type col_major: bool >>> from pysnptools.snpreader import SnpHdf5, Bed >>> import pysnptools.util as pstutil >>> snpdata = Bed('../examples/toydata.bed')[:,:10].read() # Read first 10 snps from Bed format >>> pstutil.create_directory_if_necessary("tempdir/toydata10.snp.hdf5") >>> SnpHdf5.write("tempdir/toydata10.snp.hdf5",snpdata) # Write data in SnpHdf5 format """ PstHdf5.write(filename,snpdata,hdf5_dtype=hdf5_dtype,col_major=sid_major)
def test_flush(self): previous_wd = os.getcwd() os.chdir(os.path.dirname(os.path.realpath(__file__))) reader = PstHdf5('../examples/toydata.kernel.hdf5') val1 = reader[0, 0].read() reader.flush() val2 = reader[0, 0].read() assert val1 == val2
def write(filename, snpdata, hdf5_dtype=None, sid_major=True): """Writes a :class:`SnpData` to SnpHdf5 format. :param filename: the name of the file to create :type filename: string :param snpdata: The in-memory data that should be written to disk. :type snpdata: :class:`SnpData` :param hdf5_dtype: None (use the .val's dtype) or a Hdf5 dtype, e.g. 'f8','f4',etc. :type hdf5_dtype: string :param col_major: Tells if vals should be stored on disk in sid_major (default) or iid_major format. :type col_major: bool >>> from pysnptools.snpreader import SnpHdf5, Bed >>> import pysnptools.util as pstutil """ PstHdf5.write(filename, snpdata, hdf5_dtype=hdf5_dtype, col_major=sid_major)
def write(filename, kerneldata, hdf5_dtype=None, sid_major=True): """Writes a :class:`KernelData` to KernelHdf5 format. :param filename: the name of the file to create :type filename: string :param kerneldata: The in-memory data that should be written to disk. :type kerneldata: :class:`KernelData` :param hdf5_dtype: None (use the .val's dtype) or a Hdf5 dtype, e.g. 'f8','f4',etc. :type hdf5_dtype: string :param col_major: Tells if vals should be stored on disk in sid_major (default) or iid_major format. :type col_major: bool >>> from pysnptools.snpreader import Bed >>> from pysnptools.standardizer import Unit >>> import pysnptools.util as pstutil >>> kerneldata = Bed('../examples/toydata.bed').read_kernel(Unit()) # Create a kernel from the data in the Bed file >>> pstutil.create_directory_if_necessary("tempdir/toydata.kernel.hdf5") >>> KernelHdf5.write("tempdir/toydata.kernel.hdf5",kerneldata) # Write data in KernelHdf5 format """ PstHdf5.write(filename,kerneldata,hdf5_dtype=hdf5_dtype,col_major=sid_major)
def test_respect_read_inputs(self): from pysnptools.pstreader import _MergeRows, _MergeCols previous_wd = os.getcwd() os.chdir(os.path.dirname(os.path.realpath(__file__))) for pstreader in [ PstNpz('../examples/toydata10.snp.npz'), _MergeRows([ PstHdf5('../examples/toydata.snpmajor.snp.hdf5') [:5, :].read(), PstHdf5('../examples/toydata.snpmajor.snp.hdf5')[ 5:, :].read() ]), _MergeCols([ PstHdf5( '../examples/toydata.snpmajor.snp.hdf5')[:, :5].read(), PstHdf5('../examples/toydata.snpmajor.snp.hdf5') [:, 5:].read() ]), PstHdf5('../examples/toydata.snpmajor.snp.hdf5')[::2, ::2], PstHdf5('../examples/toydata.snpmajor.dist.hdf5').read(), PstHdf5('../examples/toydata.kernel.hdf5'), PstMemMap('../examples/tiny.pst.memmap') ]: logging.info(str(pstreader)) for order in ['F', 'C', 'A']: for dtype in [np.float32, np.float64]: for force_python_only in [True, False]: for view_ok in [True, False]: val = pstreader.read( order=order, dtype=dtype, force_python_only=force_python_only, view_ok=view_ok).val has_right_order = order == "A" or ( order == "C" and val.flags["C_CONTIGUOUS"] ) or (order == "F" and val.flags["F_CONTIGUOUS"]) if hasattr(pstreader, 'val') and not view_ok: assert pstreader.val is not val if (hasattr(pstreader, 'val') and view_ok and pstreader.val is not val and (order == 'A' or (order == 'F' and pstreader.val.flags['F_CONTIGUOUS']) or (order == 'C' and pstreader.val.flags['C_CONTIGUOUS'])) and (dtype is None or pstreader.val.dtype == dtype)): logging.info( "{0} could have read a view, but didn't". format(pstreader)) assert val.dtype == dtype and has_right_order os.chdir(previous_wd)