In [14]:
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 ..
%pwd
hdf5_results = h5py.File("results_modisco/results0/results_task0.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 0 hypothetical scores:")
        viz_sequence.plot_weights(pattern["task0_hypothetical_contribs"]["fwd"])
        print("Task 0 actual importance scores:")
        viz_sequence.plot_weights(pattern["task0_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: 9797
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_1
total seqlets: 1438
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_2
total seqlets: 863
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_3
total seqlets: 732
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_4
total seqlets: 724
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_5
total seqlets: 635
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_6
total seqlets: 557
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_7
total seqlets: 479
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_8
total seqlets: 484
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_9
total seqlets: 346
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_10
total seqlets: 309
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_11
total seqlets: 243
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_12
total seqlets: 250
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_13
total seqlets: 213
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_14
total seqlets: 157
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_15
total seqlets: 155
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_16
total seqlets: 130
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_17
total seqlets: 117
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_18
total seqlets: 75
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_19
total seqlets: 83
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
metacluster_1
activity pattern: [-1]
metacluster_1 pattern_0
total seqlets: 260
Task 0 hypothetical scores:
Task 0 actual importance scores:
onehot, fwd and rev:
In [ ]: