#!/usr/bin/env python
# vim: fdm=indent
'''
author:     Fabio Zanini
date:       07/08/17
content:    Test Dataset class.
'''
import numpy as np


# Script
if __name__ == '__main__':

    # NOTE: an env variable for the config file needs to be set when
    # calling this script
    from singlet.dataset import Dataset
    ds = Dataset(
            samplesheet='example_sheet_tsv',
            counts_table='example_table_tsv')

    # FIXME: these test assertions need to be checked!
    print('Test Dataset PCA')
    ds.counts = ds.counts.iloc[:200]
    d = ds.dimensionality.pca(
            n_dims=2,
            transform='log10',
            robust=False,
            random_state=0)
    print(d)
    assert(np.allclose(d['eigenvalues'], [250.63398104, 154.97900214]))
    print('Done!')

    print('Test cache for PCA')
    ds.dimensionality._pca_cache['func_kwargs']['n_dims'] = 'none'
    d = ds.dimensionality.pca(
            n_dims='none',
            transform='log10',
            robust=False,
            random_state=0)
    print('Done!')

    print('Test Dataset robust PCA')
    ds.counts = ds.counts.iloc[:200]
    d = ds.dimensionality.pca(
            n_dims=2,
            transform='log10',
            robust=True)
    assert(np.allclose(d['eigenvalues'][:1], [408.0]))
    print('Done!')

    print('Test Dataset t-SNE')
    ds.counts = ds.counts.iloc[:200]
    vs = ds.dimensionality.tsne(
            n_dims=2,
            transform='log10',
            theta=0.5,
            perplexity=0.8)
    assert(np.allclose(vs.values[0], [43.83527909, 1426.60556519]))
    print('Done!')

    print('Test cache for t-SNE')
    ds.dimensionality._tsne_cache['func_kwargs']['n_dims'] = 'none'
    vs = ds.dimensionality.tsne(
            n_dims='none',
            transform='log10',
            theta=0.5,
            perplexity=0.8)
    print('Done!')

@@ -686,21 +686,8 @@
 =0)%0A
-    print(d)%0A
     
@@ -712,50 +712,45 @@
 (d%5B'
-eigen
+vs'%5D.
 values
-'
+%5B0
 %5D, %5B
-250.63398104, 154.97900214
+-2.677194, -5.129792
 %5D))%0A
@@ -1244,33 +1244,40 @@
 (d%5B'
-eigen
+vs'%5D.
 values
-'%5D%5B
+%5B0, 
 :1%5D, %5B
-408.0
+-4.38351382
 %5D))%0A

Test eigenvectors instead of eigenvalues in PCA (more stable)