In [ ]:
from importlib import reload
from collections import Counter
from modisco.visualization import viz_sequence
reload(viz_sequence)
from matplotlib import pyplot as plt
import h5py
import numpy as np
import modisco.affinitymat.core
reload(modisco.affinitymat.core)
import modisco.cluster.phenograph.core
reload(modisco.cluster.phenograph.core)
import modisco.cluster.phenograph.cluster
reload(modisco.cluster.phenograph.cluster)
import modisco.cluster.core
reload(modisco.cluster.core)
import modisco.aggregator
reload(modisco.aggregator)
%cd ..
hdf5_results = h5py.File("results_modisco/results_task2.hdf5","r")

print("Metaclusters heatmap")
import seaborn as sns
activity_patterns = np.array(hdf5_results['metaclustering_results']['attribute_vectors'])[
                    np.array(
        [x[0] for x in sorted(
                enumerate(hdf5_results['metaclustering_results']['metacluster_indices']),
               key=lambda x: x[1])])]
sns.heatmap(activity_patterns, center=0)
plt.show()

metacluster_names = [
    x.decode("utf-8") for x in 
    list(hdf5_results["metaclustering_results"]
         ["all_metacluster_names"][:])]

all_patterns = []

for metacluster_name in metacluster_names:
    print(metacluster_name)
    metacluster_grp = (hdf5_results["metacluster_idx_to_submetacluster_results"]
                                   [metacluster_name])
    print("activity pattern:",metacluster_grp["activity_pattern"][:])
    all_pattern_names = [x.decode("utf-8") for x in 
                         list(metacluster_grp["seqlets_to_patterns_result"]
                                             ["patterns"]["all_pattern_names"][:])]
    if (len(all_pattern_names)==0):
        print("No motifs found for this activity pattern")
    for pattern_name in all_pattern_names:
        print(metacluster_name, pattern_name)
        all_patterns.append((metacluster_name, pattern_name))
        pattern = metacluster_grp["seqlets_to_patterns_result"]["patterns"][pattern_name]
        print("total seqlets:",len(pattern["seqlets_and_alnmts"]["seqlets"]))
        background = np.array([0.27, 0.23, 0.23, 0.27])
        print("Task 2 hypothetical scores:")
        viz_sequence.plot_weights(pattern["task2_hypothetical_contribs"]["fwd"])
        print("Task 2 actual importance scores:")
        viz_sequence.plot_weights(pattern["task2_contrib_scores"]["fwd"])
        print("onehot, fwd and rev:")
        viz_sequence.plot_weights(viz_sequence.ic_scale(np.array(pattern["sequence"]["fwd"]),
                                                        background=background)) 
        viz_sequence.plot_weights(viz_sequence.ic_scale(np.array(pattern["sequence"]["rev"]),
                                                        background=background)) 
        
hdf5_results.close()
/mnt/lab_data2/tarunc
Metaclusters heatmap
metacluster_0
activity pattern: [1]
metacluster_0 pattern_0
total seqlets: 9382
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_1
total seqlets: 1203
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_2
total seqlets: 1032
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_3
total seqlets: 716
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_4
total seqlets: 720
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_5
total seqlets: 687
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_6
total seqlets: 618
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_7
total seqlets: 440
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_8
total seqlets: 419
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_9
total seqlets: 381
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_10
total seqlets: 353
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_11
total seqlets: 339
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_12
total seqlets: 306
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_13
total seqlets: 289
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_14
total seqlets: 251
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_15
total seqlets: 205
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_16
total seqlets: 176
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_17
total seqlets: 162
Task 2 hypothetical scores:
Task 2 actual importance scores:
onehot, fwd and rev:
In [13]:
%pwd
Out[13]:
'/mnt/lab_data2/tarunc/skinmodisco_results_notebooks'
In [ ]: