In [3]:
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/results6/results_task6.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 6 hypothetical scores:")
        viz_sequence.plot_weights(pattern["task6_hypothetical_contribs"]["fwd"])
        print("Task 6 actual importance scores:")
        viz_sequence.plot_weights(pattern["task6_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: 8613
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_1
total seqlets: 1613
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_2
total seqlets: 1430
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_3
total seqlets: 923
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_4
total seqlets: 757
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_5
total seqlets: 744
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_6
total seqlets: 663
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_7
total seqlets: 554
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_8
total seqlets: 550
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_9
total seqlets: 535
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_10
total seqlets: 529
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_11
total seqlets: 396
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_12
total seqlets: 386
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_13
total seqlets: 390
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_14
total seqlets: 277
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_15
total seqlets: 269
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_16
total seqlets: 204
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_17
total seqlets: 210
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_0 pattern_18
total seqlets: 143
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_1
activity pattern: [-1]
metacluster_1 pattern_0
total seqlets: 338
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
metacluster_1 pattern_1
total seqlets: 233
Task 6 hypothetical scores:
Task 6 actual importance scores:
onehot, fwd and rev:
In [ ]: