Ejemplo n.º 1
0
        def storage_closure():
            def id_and_path_function():
                self.count += 1
                return self.count, temp_dir + '/{0}'.format(self.count)

            storage = PeerToPeer(common_directory=temp_dir + '/common',
                                 id_and_path_function=id_and_path_function)
            return storage
Ejemplo n.º 2
0
    def too_slow_test_peertopeer(self):
        logging.info("test_peertopeer")

        output_file = self.file_name("peertopeer")

        def id_and_path_function():
            from pysnptools.util.filecache import ip_address_pid
            ip_pid = ip_address_pid()
            #Need to put the 'cache_top' here explicitly.
            return ip_pid, 'peertopeer/{0}'.format(ip_pid)

        storage = PeerToPeer(common_directory='peertopeer/common',
                             id_and_path_function=id_and_path_function)
        test_snps_cache = storage.join('test_snps')
        test_snps_cache.rmtree()
        test_snps = DistributedBed.write(test_snps_cache,
                                         self.bed,
                                         piece_per_chrom_count=2)

        runner = LocalMultiProc(
            taskcount=5)  #Run on 5 additional Python processes

        for clear_cache in (True, False):
            if clear_cache:
                storage.join('cache').rmtree()
            results_df = single_snp_scale(test_snps=test_snps,
                                          pheno=self.phen_fn,
                                          covar=self.cov_fn,
                                          cache=storage.join('cache'),
                                          output_file_name=output_file,
                                          runner=runner)
            self.compare_files(results_df, "old")
Ejemplo n.º 3
0
        if os.path.exists(directory_name) and os.path.isfile(directory_name):
            os.remove(directory_name)
        pstutil.create_directory_if_necessary(local, isfile=True)


if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)

    if False:
        from pysnptools.util.filecache import PeerToPeer, ip_address

        def id_and_path_function():
            ip = ip_address()
            return ip, 'peertopeer1/{0}'.format(ip)

        file_cache = PeerToPeer(common_directory='peertopeer1/common',
                                id_and_path_function=id_and_path_function)
        file_cache
        #PeerToPeer('peertopeer1/common',id_and_path_function=...')
        file_cache.rmtree()

        from pysnptools.snpreader import SnpGen, Dense
        snp_gen = SnpGen(seed=123, iid_count=1000, sid_count=5000)
        with file_cache.open_write(
                'r123.1000x5000.dense.txt') as local_filename:
            Dense.write(local_filename, snp_gen.read())
        list(file_cache.walk())
        #['r123.1000x5000.dense.txt']

    import doctest
    doctest.testmod(optionflags=doctest.ELLIPSIS)
    # There is also a unit test case in 'pysnptools\test.py' that calls this doc test