import numpy as np
from scipy import ndimage as nd
from matplotlib import pyplot as plt

!wget https://github.com/jeanpat/DeepFISH/blob/master/dataset/Cleaned_FullRes_2164_overlapping_pairs.npz?raw=true
!mv Cleaned_FullRes_2164_overlapping_pairs.npz?raw=true Clean2164.npz

# There's a trick to load and uncompress a numpy .npz array
# https://stackoverflow.com/questions/18231135/load-compressed-data-npz-from-file-using-numpy-load/44693995
#
dataset = np.load('Clean2164.npz')
data = dataset.f.arr_0
data.shape

"""
Explanation: 2164 Full resolution pairs of grayscaled+groundtruth label images
The pairs of images were generated from a previous dataset which suffered from several defects both in the grayscale and in the ground truth components:

The grayscaled images could suffer from two problems:
Some images had black dots: those images were removed (with the corresponding groundtruth)
The images dtype is now np.uint8
The overlapping domain is now more realistic compared with real overlapping chromosomes


The labels of the groundtruth don't have no more spurious pixels
End of explanation
"""


N=203
plt.figure(figsize=(10,8))
plt.subplot(121)
plt.imshow(data[N,:,:,0], cmap=plt.cm.gray)
plt.subplot(122)
plt.imshow(data[N,:,:,1], cmap=plt.cm.flag_r)

"""
Explanation: Have a look to the downloaded images
End of explanation
"""


!wget https://github.com/jeanpat/DeepFISH/blob/master/dataset/Cleaned_FullRes_2164_overlapping_pairs.h5?raw=true
!mv Cleaned_FullRes_2164_overlapping_pairs.h5?raw=true Clean2164.h5

import h5py
filename = './Clean2164.h5'
h5f = h5py.File(filename,'r')
pairs = h5f['chroms_data'][:]
h5f.close()
print('dataset is a numpy array of shape:', pairs.shape)

"""
Explanation: The same dataset saved as a hdf5 file can be downloaded
End of explanation
"""


