In [1]:
%load_ext autoreload
%autoreload 2

In [2]:
from eden.util import configure_logging
import logging
configure_logging(logging.getLogger(),verbosity=2)
%matplotlib inline
!pwd


/home/ikea/GraphLearn/GraphLearn_examples/Abstract

In [3]:
'''
GET RNA DATA
'''
from eden.converter.fasta import fasta_to_sequence
import itertools

def rfam_uri(family_id):
    return 'http://rfam.xfam.org/family/%s/alignment?acc=%s&format=fastau&download=0'%(family_id,family_id)
def rfam_uri(family_id):
    return '%s.fa'%(family_id)
 
def get_graphss(rfam_id = '../toolsdata/RF00005'):
    return fasta_to_sequence(rfam_uri(rfam_id))

def get_graphs(rfam_id = '../toolsdata/RF00005', count=100):
    for a,b in itertools.islice( get_graphss(rfam_id),count):
        yield b

from eden.converter.fasta import fasta_to_sequence
def get_sequences(size=9999):
    sequences = itertools.islice( fasta_to_sequence("../toolsdata/RF00005.fa"), size)
    return [ b for (a,b) in sequences ]

def get_sequences_with_names(size=9999):
    sequences = itertools.islice( fasta_to_sequence("../toolsdata/RF00005.fa"), size)
    return sequences

In [4]:
'''TESTING EXTRACTION AND GRAPHMANAGER'''
from graphlearn.utils import draw
import graphlearn.abstract_graphs.RNA as rna
from graphlearn.graphlearn import Sampler as GLS
from eden.graph import Vectorizer

vectorizer=Vectorizer()
pp=rna.PreProcessor()
pp.fit(get_sequences_with_names(),vectorizer)
graphmanagers=pp.transform(get_sequences()[:4])

print 'DEMONSTRATING GRAPH MANAGER'

for i in range(3):
    print 'grammar example %d' % i
    gm=graphmanagers[i]
    g=gm.graph(nested=True)
    #print g.nodes(data=True)
    #g.node[0].pop('weight')
    vec=vectorizer.transform_single(g)
    draw.graphlearn([gm.graph(nested=True),gm.abstract_graph(),gm.base_graph()], size = 15,vertex_label = 'label',contract=False)


print 'DEMONSTRATING EXTRACTION'  
radius_list=[0,2]
thickness_list=[2,4]
base_thickness_list=[2]

f=lambda x, y: True
d={'radius_list':radius_list,
    'thickness_list':thickness_list,
    'hash_bitmask':2**20-1,
    'include_base':True,
    'node_filter': f}

#cips=gm.all_core_interface_pairs(**d)
cips=[]
for ciplist in cips:
    for cip in ciplist:
        pass 
        draw.graphlearn([cip.graph,cip.abstract_view], size=4, contract=False)
    
#g=gm.graph(nested=False)
#print 'test', g.nodes(data=True)[0][1]


DEMONSTRATING GRAPH MANAGER
grammar example 0
grammar example 1
grammar example 2
DEMONSTRATING EXTRACTION

In [4]:
%%time
'''
learning a grammar
'''
import graphlearn.abstract_graphs.RNA as rna
import graphlearn.graphlearn as gl
from  graphlearn.feasibility import FeasibilityChecker as Checker

# not really needed since after refolding we get an RNA
#feasibility=Checker()
#feasibility.checklist.append(rna.is_rna)

graphs = get_sequences_with_names(size=200)





class testsampler(gl.Sampler):
    def _get_original_cip(self,graphman):
        '''
        overwriting this so we can choose funny cips
        '''
        if self.step < 25: 
            return graphman.random_core_interface_pair( radius_list=self.radius_list, thickness_list=self.thickness_list,
                    hash_bitmask=self.hash_bitmask, node_filter=self.node_entity_check )

        else:
            return graphman.random_core_interface_pair_base( radius_list=self.radius_list, thickness_list=self.thickness_list,
                    hash_bitmask=self.hash_bitmask, node_filter=self.node_entity_check )
    # python bitchin
    def _sample_path_append(self, graph, force=False):
        self._sample_notes+=graph.sequence+"n"
        super(self.__class__,self)._sample_path_append(graph,force=force)


sampler=testsampler(radius_list=[0,1],
                            thickness_list=[2], 
                            min_cip_count=1, 
                            min_interface_count=2, 
                            preprocessor=rna.PreProcessor(include_base=True,ignore_inserts=True), 
                            postprocessor=rna.PostProcessor(),
                            #feasibility_checker=feasibility
                           )
sampler.fit(graphs,grammar_n_jobs=1,grammar_batch_size=1)
sampler.save('../tmp/rna_ubergrammar.ge')


Warning: fit was asked with n=1

Classifier:
SGDClassifier(alpha=0.000986678305653, average=False, class_weight=None,
       epsilon=0.1, eta0=0.260900701615, fit_intercept=True, l1_ratio=0.15,
       learning_rate='optimal', loss='log', n_iter=98, n_jobs=1,
       penalty='l1', power_t=0.125670669404, random_state=None,
       shuffle=True, verbose=0, warm_start=False)

Predictive performance:
            accuracy: 1.000 +- 0.000
           precision: 1.000 +- 0.000
              recall: 1.000 +- 0.000
                  f1: 1.000 +- 0.000
   average_precision: 1.000 +- 0.000
             roc_auc: 1.000 +- 0.000
#instances: 200  #interfaces: 2528   #cores: 1578   #core-interface-pairs: 7788
Saved model: ../tmp/rna_ubergrammar.ge
CPU times: user 4min 10s, sys: 9.97 s, total: 4min 20s
Wall time: 6min 1s

In [5]:
#draw production rules
from graphlearn.utils import draw
draw.draw_grammar(sampler.lsgg.productions,n_productions=20,n_graphs_per_production=5,
                     n_graphs_per_line=6, size=10, contract=False,
                     colormap='Paired', invert_colormap=False,node_border=1,
                     vertex_alpha=0.6, edge_alpha=0.5, node_size=250, abstract_interface=True)


interface id: 494871 [40 options]
interface id: 1017963 [35 options]
interface id: 294383 [33 options]
interface id: 710023 [28 options]
interface id: 807828 [27 options]
interface id: 256695 [26 options]
interface id: 63609 [25 options]
interface id: 985271 [23 options]
interface id: 783831 [23 options]
interface id: 741497 [23 options]
interface id: 567547 [21 options]
interface id: 463528 [20 options]
interface id: 1042533 [17 options]
interface id: 192422 [17 options]
interface id: 981113 [16 options]
interface id: 680103 [16 options]
interface id: 596776 [16 options]
interface id: 950967 [14 options]
interface id: 911394 [14 options]
interface id: 398680 [14 options]

In [6]:
%%time
'''
Rna sampling
'''
import os
os.nice(19)
import graphlearn.utils.draw as draw
import graphlearn.abstract_graphs.RNA as rna
from graphlearn.graphlearn import Sampler as GLS
import itertools
#sampler=rna.AbstractSampler(radius_list=[0,1],thickness_list=[2], min_cip_count=1, min_interface_count=2, preprocessor=rna.PreProcessor(), postprocessor=rna.PostProcessor())
#sampler.load('tmp/rna_ubergrammar.ge')


graphs = get_graphs()
id_start=20
id_end=id_start+9
graphs = itertools.islice(graphs,id_start,id_end)
n_steps=50

graphs = sampler.sample(graphs,
                        n_samples=3,
                        batch_size=1,
                        n_steps=n_steps,
                        n_jobs=1,
                        quick_skip_orig_cip=True,
                        probabilistic_core_choice=True,
                        burnin=0,
                        improving_threshold=0.9,
                        improving_linear_start=0.15,
                        max_size_diff=20,
                        accept_min_similarity=0.55,
                        select_cip_max_tries=30,
                        keep_duplicates=False,
                        include_seed=True,
                        backtrack=10,
                        monitor=True)


from eden.modifier.graph.vertex_attributes import colorize   
scores=[]
sequences=[]
ids=range(id_start,id_end)
for i,graphlist in enumerate(graphs):
    print 'Graph id: %d'%(ids[i])
    scores.append(sampler.monitors[i].sampling_info['score_history'])
    
    sequences.append(sampler.monitors[i].sampling_info['notes'])
    
    path_graphs = colorize(graphlist,
                           output_attribute = 'color_level', 
                           labels = ['A','U','G','C'])
    path_graphs= list(path_graphs)
    draw.graphlearn(path_graphs,
                           n_graphs_per_line=3, size=20, 
                           colormap='Paired', invert_colormap=False,node_border=0.5, vertex_color='color_level',
                           vertex_alpha=0.5, edge_alpha=0.7, node_size=450,edge_label='label'
                          )


preprocessing grammar
_sample_notes: None
accept_min_similarity: 0.55
accept_static_penalty: 0.0
batch_size: 1
    burnin: 0
estimatorobject: <graphlearn.estimator.Wrapper instance at 0x7f4b7876c320>
feasibility_checker: <graphlearn.feasibility.FeasibilityChecker instance at 0x7f4b7876c368>
hash_bitmask: 1048575
improving_linear_start: 7
improving_penalty_per_step: 0.0263157894737
improving_threshold: 45
include_seed: True
keep_duplicates: False
      lsgg: <graphlearn.localsubstitutablegraphgrammar.LocalSubstitutableGraphGrammar object at 0x7f4b7871cf90>
max_core_size_diff: 40
maxbacktrack: 10
   monitor: True
  monitors: []
    n_jobs: 1
   n_steps: 50
      nbit: 20
node_entity_check: <function <lambda> at 0x7f4b7876b398>
postprocessor: <graphlearn.abstract_graphs.RNA.PostProcessor object at 0x7f4b7871cf10>
preprocessor: <graphlearn.abstract_graphs.RNA.PreProcessor object at 0x7f4b7aaf3d90>
probabilistic_core_choice: True
proposal_probability: False
quick_skip_orig_cip: True
radius_list: [0, 2]
random_state: None
sample_path: None
sampling_interval: 16
score_core_choice: False
select_cip_max_tries: 30
similarity: -1
      step: None
target_orig_cip: False
thickness_list: [4]
vectorizer: graph.Vectorizer( r = 3, d = 3, n = 1, min_r = 0, min_d = 0, min_n = 2,                          label_size = 1, nbits = 20, status = None, normalization = True,                          inner_normalization = True, triangular_decomposition = False )
_propose_graph: iteration 0 ; core 0 of 11 ; original_cips tried  0 ; size 165
_propose_graph: iteration 1 ; core 0 of 4 ; original_cips tried  0 ; size 165
_propose_graph: iteration 2 ; core 0 of 1 ; original_cips tried  0 ; size 165
_propose_graph: iteration 3 ; core 0 of 7 ; original_cips tried  0 ; size 169
_propose_graph: iteration 4 ; core 0 of 1 ; original_cips tried  0 ; size 174
_propose_graph: iteration 5 ; core 0 of 11 ; original_cips tried  1 ; size 174
_propose_graph: iteration 6 ; core 0 of 4 ; original_cips tried  0 ; size 177
_propose_graph: iteration 7 ; core 0 of 20 ; original_cips tried  0 ; size 171
_propose_graph: iteration 8 ; core 0 of 3 ; original_cips tried  0 ; size 171
_propose_graph: iteration 9 ; core 0 of 3 ; original_cips tried  0 ; size 171
_propose_graph: iteration 10 ; core 0 of 5 ; original_cips tried  0 ; size 176
_propose_graph: iteration 11 ; core 0 of 20 ; original_cips tried  0 ; size 172
_propose_graph: iteration 12 ; core 0 of 11 ; original_cips tried  0 ; size 172
_propose_graph: iteration 13 ; core 0 of 20 ; original_cips tried  0 ; size 171
_propose_graph: iteration 14 ; core 0 of 1 ; original_cips tried  0 ; size 171
_propose_graph: iteration 15 ; core 0 of 20 ; original_cips tried  0 ; size 171
_propose_graph: iteration 16 ; core 0 of 1 ; original_cips tried  0 ; size 173
_propose_graph: iteration 17 ; core 0 of 3 ; original_cips tried  0 ; size 173
_propose_graph: iteration 18 ; core 0 of 3 ; original_cips tried  0 ; size 173
_propose_graph: iteration 19 ; core 0 of 27 ; original_cips tried  1 ; size 169
_propose_graph: iteration 20 ; core 0 of 1 ; original_cips tried  3 ; size 169
_propose_graph: iteration 21 ; core 0 of 20 ; original_cips tried  0 ; size 169
_propose_graph: iteration 22 ; core 0 of 3 ; original_cips tried  1 ; size 167
_propose_graph: iteration 23 ; core 0 of 3 ; original_cips tried  0 ; size 167
_propose_graph: iteration 24 ; core 0 of 4 ; original_cips tried  1 ; size 167
_propose_graph: iteration 25 ; core 0 of 4 ; original_cips tried  0 ; size 167
_propose_graph: iteration 26 ; core 0 of 11 ; original_cips tried  0 ; size 167
_propose_graph: iteration 27 ; core 0 of 5 ; original_cips tried  1 ; size 163
_propose_graph: iteration 28 ; core 0 of 4 ; original_cips tried  0 ; size 167
_propose_graph: iteration 29 ; core 0 of 1 ; original_cips tried  0 ; size 167
_propose_graph: iteration 30 ; core 0 of 1 ; original_cips tried  1 ; size 167
_propose_graph: iteration 31 ; core 0 of 1 ; original_cips tried  0 ; size 167
_propose_graph: iteration 32 ; core 0 of 5 ; original_cips tried  0 ; size 167
_propose_graph: iteration 33 ; core 0 of 5 ; original_cips tried  0 ; size 167
_propose_graph: iteration 34 ; core 0 of 4 ; original_cips tried  0 ; size 167
_propose_graph: iteration 35 ; core 0 of 16 ; original_cips tried  0 ; size 167
_propose_graph: iteration 36 ; core 0 of 7 ; original_cips tried  0 ; size 171
_propose_graph: iteration 37 ; core 0 of 2 ; original_cips tried  0 ; size 171
_propose_graph: iteration 38 ; core 0 of 11 ; original_cips tried  0 ; size 171
_propose_graph: iteration 39 ; core 0 of 1 ; original_cips tried  0 ; size 171
_propose_graph: iteration 40 ; core 0 of 8 ; original_cips tried  0 ; size 171
faster iso check failed
_propose_graph: iteration 41 ; core 0 of 1 ; original_cips tried  2 ; size 171
_propose_graph: iteration 42 ; core 0 of 2 ; original_cips tried  1 ; size 171
_propose_graph: iteration 43 ; core 0 of 8 ; original_cips tried  0 ; size 171
_propose_graph: iteration 44 ; core 0 of 2 ; original_cips tried  0 ; size 171
_propose_graph: iteration 45 ; core 0 of 8 ; original_cips tried  0 ; size 171
_propose_graph: iteration 46 ; core 0 of 2 ; original_cips tried  1 ; size 171
_propose_graph: iteration 47 ; core 0 of 1 ; original_cips tried  0 ; size 171
_propose_graph: iteration 48 ; core 0 of 5 ; original_cips tried  1 ; size 171
_propose_graph: iteration 49 ; core 0 of 2 ; original_cips tried  0 ; size 171
Graph id: 20
/home/ikea/.local/lib/python2.7/site-packages/matplotlib/text.py:52: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if rotation in ('horizontal', None):
/home/ikea/.local/lib/python2.7/site-packages/matplotlib/text.py:54: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif rotation == 'vertical':
_propose_graph: iteration 0 ; core 0 of 1 ; original_cips tried  0 ; size 163
_propose_graph: iteration 1 ; core 0 of 15 ; original_cips tried  0 ; size 163
_propose_graph: iteration 2 ; core 0 of 1 ; original_cips tried  0 ; size 163
faster iso check failed
_propose_graph: iteration 3 ; core 0 of 2 ; original_cips tried  1 ; size 163
_propose_graph: iteration 4 ; core 0 of 2 ; original_cips tried  0 ; size 163
_propose_graph: iteration 5 ; core 0 of 15 ; original_cips tried  0 ; size 163
_propose_graph: iteration 6 ; core 0 of 4 ; original_cips tried  0 ; size 164
_propose_graph: iteration 7 ; core 0 of 1 ; original_cips tried  0 ; size 164
_propose_graph: iteration 8 ; core 0 of 1 ; original_cips tried  0 ; size 164
_propose_graph: iteration 9 ; core 0 of 1 ; original_cips tried  0 ; size 164
_propose_graph: iteration 10 ; core 0 of 2 ; original_cips tried  0 ; size 163
_propose_graph: iteration 11 ; core 0 of 1 ; original_cips tried  0 ; size 163
_propose_graph: iteration 12 ; core 0 of 1 ; original_cips tried  0 ; size 163
_propose_graph: iteration 13 ; core 0 of 12 ; original_cips tried  1 ; size 163
_propose_graph: iteration 14 ; core 0 of 9 ; original_cips tried  0 ; size 165
_propose_graph: iteration 15 ; core 0 of 10 ; original_cips tried  0 ; size 169
_propose_graph: iteration 16 ; core 0 of 15 ; original_cips tried  0 ; size 169
_propose_graph: iteration 17 ; core 0 of 10 ; original_cips tried  0 ; size 169
_propose_graph: iteration 18 ; core 0 of 3 ; original_cips tried  0 ; size 170
_propose_graph: iteration 19 ; core 0 of 1 ; original_cips tried  0 ; size 170
_propose_graph: iteration 20 ; core 0 of 15 ; original_cips tried  0 ; size 170
_propose_graph: iteration 21 ; core 0 of 22 ; original_cips tried  0 ; size 179
_propose_graph: iteration 22 ; core 0 of 1 ; original_cips tried  0 ; size 177
_propose_graph: iteration 23 ; core 0 of 3 ; original_cips tried  0 ; size 179
_propose_graph: iteration 24 ; core 0 of 22 ; original_cips tried  0 ; size 179
_propose_graph: iteration 25 ; core 0 of 8 ; original_cips tried  0 ; size 179
_propose_graph: iteration 26 ; core 0 of 10 ; original_cips tried  1 ; size 174
_propose_graph: iteration 27 ; core 0 of 1 ; original_cips tried  0 ; size 174
_propose_graph: iteration 28 ; core 0 of 7 ; original_cips tried  0 ; size 174
_propose_graph: iteration 29 ; core 0 of 1 ; original_cips tried  0 ; size 178
_propose_graph: iteration 30 ; core 0 of 11 ; original_cips tried  0 ; size 178
_propose_graph: iteration 31 ; core 0 of 3 ; original_cips tried  0 ; size 173
_propose_graph: iteration 32 ; core 0 of 1 ; original_cips tried  2 ; size 173
_propose_graph: iteration 33 ; core 0 of 1 ; original_cips tried  1 ; size 173
_propose_graph: iteration 34 ; core 0 of 7 ; original_cips tried  0 ; size 173
_propose_graph: iteration 35 ; core 0 of 9 ; original_cips tried  4 ; size 173
_propose_graph: iteration 36 ; core 0 of 5 ; original_cips tried  0 ; size 173
_propose_graph: iteration 37 ; core 0 of 1 ; original_cips tried  1 ; size 173
_propose_graph: iteration 38 ; core 0 of 9 ; original_cips tried  3 ; size 173
_propose_graph: iteration 39 ; core 0 of 7 ; original_cips tried  1 ; size 173
_propose_graph: iteration 40 ; core 0 of 4 ; original_cips tried  0 ; size 173
_propose_graph: iteration 41 ; core 0 of 3 ; original_cips tried  0 ; size 173
_propose_graph: iteration 42 ; core 0 of 2 ; original_cips tried  0 ; size 173
_propose_graph: iteration 43 ; core 0 of 4 ; original_cips tried  0 ; size 173
_propose_graph: iteration 44 ; core 0 of 3 ; original_cips tried  0 ; size 173
_propose_graph: iteration 45 ; core 0 of 4 ; original_cips tried  0 ; size 173
_propose_graph: iteration 46 ; core 0 of 11 ; original_cips tried  0 ; size 173
_propose_graph: iteration 47 ; core 0 of 7 ; original_cips tried  0 ; size 173
_propose_graph: iteration 48 ; core 0 of 8 ; original_cips tried  0 ; size 173
_propose_graph: iteration 49 ; core 0 of 1 ; original_cips tried  3 ; size 173
Graph id: 21
_propose_graph: iteration 0 ; core 0 of 3 ; original_cips tried  0 ; size 154
faster iso check failed
faster iso check failed
_propose_graph: iteration 1 ; core 0 of 16 ; original_cips tried  2 ; size 154
_propose_graph: iteration 2 ; core 0 of 34 ; original_cips tried  0 ; size 163
_propose_graph: iteration 3 ; core 0 of 1 ; original_cips tried  0 ; size 170
_propose_graph: iteration 4 ; core 0 of 3 ; original_cips tried  0 ; size 170
_propose_graph: iteration 5 ; core 0 of 1 ; original_cips tried  0 ; size 170
_propose_graph: iteration 6 ; core 0 of 1 ; original_cips tried  0 ; size 170
_propose_graph: iteration 7 ; core 0 of 1 ; original_cips tried  0 ; size 170
faster iso check failed
_propose_graph: iteration 8 ; core 0 of 16 ; original_cips tried  1 ; size 170
_propose_graph: iteration 9 ; core 0 of 1 ; original_cips tried  0 ; size 170
_propose_graph: iteration 10 ; core 0 of 1 ; original_cips tried  0 ; size 170
_propose_graph: iteration 11 ; core 0 of 1 ; original_cips tried  0 ; size 170
_propose_graph: iteration 12 ; core 0 of 16 ; original_cips tried  0 ; size 170
_propose_graph: iteration 13 ; core 0 of 20 ; original_cips tried  0 ; size 172
_propose_graph: iteration 14 ; core 0 of 1 ; original_cips tried  0 ; size 172
_propose_graph: iteration 15 ; core 0 of 2 ; original_cips tried  0 ; size 172
_propose_graph: iteration 16 ; core 0 of 9 ; original_cips tried  0 ; size 172
_propose_graph: iteration 17 ; core 0 of 1 ; original_cips tried  0 ; size 172
_propose_graph: iteration 18 ; core 0 of 16 ; original_cips tried  0 ; size 165
_propose_graph: iteration 19 ; core 0 of 3 ; original_cips tried  0 ; size 165
faster iso check failed
_propose_graph: iteration 20 ; core 0 of 34 ; original_cips tried  1 ; size 165
_propose_graph: iteration 21 ; core 0 of 9 ; original_cips tried  0 ; size 172
_propose_graph: iteration 22 ; core 0 of 3 ; original_cips tried  0 ; size 172
_propose_graph: iteration 23 ; core 0 of 3 ; original_cips tried  1 ; size 172
_propose_graph: iteration 24 ; core 0 of 20 ; original_cips tried  0 ; size 172
_propose_graph: iteration 25 ; core 0 of 1 ; original_cips tried  0 ; size 172
_propose_graph: iteration 26 ; core 0 of 3 ; original_cips tried  0 ; size 172
_propose_graph: iteration 27 ; core 0 of 7 ; original_cips tried  1 ; size 168
_propose_graph: iteration 28 ; core 0 of 3 ; original_cips tried  2 ; size 168
_propose_graph: iteration 29 ; core 0 of 1 ; original_cips tried  1 ; size 168
_propose_graph: iteration 30 ; core 0 of 5 ; original_cips tried  1 ; size 168
_propose_graph: iteration 31 ; core 0 of 1 ; original_cips tried  0 ; size 168
_propose_graph: iteration 32 ; core 0 of 6 ; original_cips tried  1 ; size 168
_propose_graph: iteration 33 ; core 0 of 9 ; original_cips tried  3 ; size 168
_propose_graph: iteration 34 ; core 0 of 1 ; original_cips tried  0 ; size 168
_propose_graph: iteration 35 ; core 0 of 2 ; original_cips tried  1 ; size 168
_propose_graph: iteration 36 ; core 0 of 1 ; original_cips tried  1 ; size 168
_propose_graph: iteration 37 ; core 0 of 10 ; original_cips tried  0 ; size 168
_propose_graph: iteration 38 ; core 0 of 11 ; original_cips tried  2 ; size 168
_propose_graph: iteration 39 ; core 0 of 1 ; original_cips tried  0 ; size 169
_propose_graph: iteration 40 ; core 0 of 10 ; original_cips tried  0 ; size 169
_propose_graph: iteration 41 ; core 0 of 10 ; original_cips tried  3 ; size 169
_propose_graph: iteration 42 ; core 0 of 1 ; original_cips tried  3 ; size 169
_propose_graph: iteration 43 ; core 0 of 11 ; original_cips tried  1 ; size 169
_propose_graph: iteration 44 ; core 0 of 1 ; original_cips tried  0 ; size 169
_propose_graph: iteration 45 ; core 0 of 9 ; original_cips tried  1 ; size 169
_propose_graph: iteration 46 ; core 0 of 5 ; original_cips tried  0 ; size 172
_propose_graph: iteration 47 ; core 0 of 10 ; original_cips tried  2 ; size 172
_propose_graph: iteration 48 ; core 0 of 1 ; original_cips tried  0 ; size 172
_propose_graph: iteration 49 ; core 0 of 1 ; original_cips tried  1 ; size 172
Graph id: 22
_propose_graph: iteration 0 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 1 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 2 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 3 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 4 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 5 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 6 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 7 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 8 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 9 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 10 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 11 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 12 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 13 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 14 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 15 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 16 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 17 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 18 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 19 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 20 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 21 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 22 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 23 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 24 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 25 ; core 0 of 2 ; original_cips tried  0 ; size 143
_propose_graph: iteration 26 ; core 0 of 3 ; original_cips tried  0 ; size 148
_propose_graph: iteration 27 ; core 0 of 3 ; original_cips tried  0 ; size 148
_propose_graph: iteration 28 ; core 0 of 2 ; original_cips tried  0 ; size 148
_propose_graph: iteration 29 ; core 0 of 1 ; original_cips tried  0 ; size 148
_propose_graph: iteration 30 ; core 0 of 1 ; original_cips tried  0 ; size 148
_propose_graph: iteration 31 ; core 0 of 2 ; original_cips tried  0 ; size 148
_propose_graph: iteration 32 ; core 0 of 4 ; original_cips tried  0 ; size 148
_propose_graph: iteration 33 ; core 0 of 1 ; original_cips tried  0 ; size 148
_propose_graph: iteration 34 ; core 0 of 2 ; original_cips tried  0 ; size 148
_propose_graph: iteration 35 ; core 0 of 1 ; original_cips tried  0 ; size 148
_propose_graph: iteration 36 ; core 0 of 1 ; original_cips tried  0 ; size 148
_propose_graph: iteration 37 ; core 0 of 3 ; original_cips tried  0 ; size 148
_propose_graph: iteration 38 ; core 0 of 1 ; original_cips tried  1 ; size 148
_propose_graph: iteration 39 ; core 0 of 1 ; original_cips tried  0 ; size 148
_propose_graph: iteration 40 ; core 0 of 1 ; original_cips tried  0 ; size 148
_propose_graph: iteration 41 ; core 0 of 1 ; original_cips tried  0 ; size 148
_propose_graph: iteration 42 ; core 0 of 1 ; original_cips tried  0 ; size 148
_propose_graph: iteration 43 ; core 0 of 1 ; original_cips tried  0 ; size 148
_propose_graph: iteration 44 ; core 0 of 1 ; original_cips tried  0 ; size 148
_propose_graph: iteration 45 ; core 0 of 1 ; original_cips tried  0 ; size 148
_propose_graph: iteration 46 ; core 0 of 1 ; original_cips tried  0 ; size 148
_propose_graph: iteration 47 ; core 0 of 2 ; original_cips tried  0 ; size 148
_propose_graph: iteration 48 ; core 0 of 1 ; original_cips tried  0 ; size 148
_propose_graph: iteration 49 ; core 0 of 1 ; original_cips tried  0 ; size 148
Graph id: 23
_propose_graph: iteration 0 ; core 0 of 1 ; original_cips tried  0 ; size 165
_propose_graph: iteration 1 ; core 0 of 2 ; original_cips tried  1 ; size 166
_propose_graph: iteration 2 ; core 0 of 1 ; original_cips tried  0 ; size 166
_propose_graph: iteration 3 ; core 0 of 1 ; original_cips tried  0 ; size 166
_propose_graph: iteration 4 ; core 0 of 39 ; original_cips tried  0 ; size 165
_propose_graph: iteration 5 ; core 0 of 1 ; original_cips tried  0 ; size 165
_propose_graph: iteration 6 ; core 0 of 3 ; original_cips tried  0 ; size 165
_propose_graph: iteration 7 ; core 0 of 1 ; original_cips tried  0 ; size 165
_propose_graph: iteration 8 ; core 0 of 1 ; original_cips tried  0 ; size 165
_propose_graph: iteration 9 ; core 0 of 1 ; original_cips tried  2 ; size 165
_propose_graph: iteration 10 ; core 0 of 1 ; original_cips tried  0 ; size 165
_propose_graph: iteration 11 ; core 0 of 1 ; original_cips tried  0 ; size 165
_propose_graph: iteration 12 ; core 0 of 1 ; original_cips tried  0 ; size 165
_propose_graph: iteration 13 ; core 0 of 39 ; original_cips tried  0 ; size 165
_propose_graph: iteration 14 ; core 0 of 2 ; original_cips tried  0 ; size 163
_propose_graph: iteration 15 ; core 0 of 1 ; original_cips tried  1 ; size 163
_propose_graph: iteration 16 ; core 0 of 1 ; original_cips tried  1 ; size 163
_propose_graph: iteration 17 ; core 0 of 1 ; original_cips tried  0 ; size 163
_propose_graph: iteration 18 ; core 0 of 1 ; original_cips tried  0 ; size 165
_propose_graph: iteration 19 ; core 0 of 1 ; original_cips tried  1 ; size 165
_propose_graph: iteration 20 ; core 0 of 39 ; original_cips tried  0 ; size 165
_propose_graph: iteration 21 ; core 0 of 5 ; original_cips tried  0 ; size 163
_propose_graph: iteration 22 ; core 0 of 1 ; original_cips tried  0 ; size 163
_propose_graph: iteration 23 ; core 0 of 1 ; original_cips tried  0 ; size 163
_propose_graph: iteration 24 ; core 0 of 1 ; original_cips tried  0 ; size 163
_propose_graph: iteration 25 ; core 0 of 1 ; original_cips tried  1 ; size 165
_propose_graph: iteration 26 ; core 0 of 3 ; original_cips tried  0 ; size 161
faster iso check failed
_propose_graph: iteration 27 ; core 0 of 12 ; original_cips tried  2 ; size 161
_propose_graph: iteration 28 ; core 0 of 1 ; original_cips tried  0 ; size 161
_propose_graph: iteration 29 ; core 0 of 2 ; original_cips tried  0 ; size 161
_propose_graph: iteration 30 ; core 0 of 1 ; original_cips tried  0 ; size 157
_propose_graph: iteration 31 ; core 0 of 1 ; original_cips tried  0 ; size 157
_propose_graph: iteration 32 ; core 0 of 1 ; original_cips tried  0 ; size 157
_propose_graph: iteration 33 ; core 0 of 10 ; original_cips tried  1 ; size 157
_propose_graph: iteration 34 ; core 0 of 3 ; original_cips tried  0 ; size 157
_propose_graph: iteration 35 ; core 0 of 1 ; original_cips tried  0 ; size 157
_propose_graph: iteration 36 ; core 0 of 1 ; original_cips tried  1 ; size 157
faster iso check failed
_propose_graph: iteration 37 ; core 0 of 4 ; original_cips tried  1 ; size 157
_propose_graph: iteration 38 ; core 0 of 3 ; original_cips tried  0 ; size 157
_propose_graph: iteration 39 ; core 0 of 5 ; original_cips tried  0 ; size 157
_propose_graph: iteration 40 ; core 0 of 3 ; original_cips tried  0 ; size 157
_propose_graph: iteration 41 ; core 0 of 1 ; original_cips tried  0 ; size 157
_propose_graph: iteration 42 ; core 0 of 1 ; original_cips tried  0 ; size 157
_propose_graph: iteration 43 ; core 0 of 3 ; original_cips tried  1 ; size 157
_propose_graph: iteration 44 ; core 0 of 6 ; original_cips tried  1 ; size 157
_propose_graph: iteration 45 ; core 0 of 3 ; original_cips tried  0 ; size 157
_propose_graph: iteration 46 ; core 0 of 1 ; original_cips tried  0 ; size 157
_propose_graph: iteration 47 ; core 0 of 1 ; original_cips tried  1 ; size 153
_propose_graph: iteration 48 ; core 0 of 6 ; original_cips tried  0 ; size 153
_propose_graph: iteration 49 ; core 0 of 2 ; original_cips tried  0 ; size 153
Graph id: 24
_propose_graph: iteration 0 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 1 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 2 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 3 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 4 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 5 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 6 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 7 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 8 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 9 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 10 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 11 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 12 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 13 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 14 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 15 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 16 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 17 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 18 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 19 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 20 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 21 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 22 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 23 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 24 ; core 0 of 2 ; original_cips tried  0 ; size 153
select_cip_for_substitution failed because no suiting interface was found,             extract failed 29 times; cip found but unacceptable:1 
_propose_graph: iteration 24 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 25 ; core 0 of 2 ; original_cips tried  0 ; size 153
select_cip_for_substitution failed because no suiting interface was found,             extract failed 30 times; cip found but unacceptable:5 
select_cip_for_substitution failed because no suiting interface was found,             extract failed 29 times; cip found but unacceptable:1 
propose failed.. usualy the problem is propose_single_cip
Traceback (most recent call last):
  File "/home/ikea/GraphLearn/graphlearn/graphlearn.py", line 407, in _sample
    candidate_graph_manager = self._propose(graph_manager)
  File "/home/ikea/GraphLearn/graphlearn/graphlearn.py", line 618, in _propose
    raise Exception("propose failed.. usualy the problem is propose_single_cip")
Exception: propose failed.. usualy the problem is propose_single_cip

_sample stopped at 25 out of 50 n_steps
Graph id: 25
_propose_graph: iteration 0 ; core 0 of 1 ; original_cips tried  0 ; size 155
_propose_graph: iteration 1 ; core 0 of 4 ; original_cips tried  0 ; size 155
_propose_graph: iteration 2 ; core 0 of 13 ; original_cips tried  1 ; size 155
_propose_graph: iteration 3 ; core 0 of 1 ; original_cips tried  0 ; size 155
_propose_graph: iteration 4 ; core 0 of 2 ; original_cips tried  1 ; size 155
_propose_graph: iteration 5 ; core 0 of 34 ; original_cips tried  0 ; size 155
_propose_graph: iteration 6 ; core 0 of 12 ; original_cips tried  0 ; size 155
_propose_graph: iteration 7 ; core 0 of 34 ; original_cips tried  0 ; size 155
_propose_graph: iteration 8 ; core 0 of 8 ; original_cips tried  0 ; size 153
_propose_graph: iteration 9 ; core 0 of 34 ; original_cips tried  0 ; size 153
_propose_graph: iteration 10 ; core 0 of 12 ; original_cips tried  0 ; size 153
_propose_graph: iteration 11 ; core 0 of 16 ; original_cips tried  0 ; size 153
_propose_graph: iteration 12 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 13 ; core 0 of 27 ; original_cips tried  0 ; size 153
_propose_graph: iteration 14 ; core 0 of 12 ; original_cips tried  0 ; size 153
_propose_graph: iteration 15 ; core 0 of 1 ; original_cips tried  0 ; size 153
_propose_graph: iteration 16 ; core 0 of 4 ; original_cips tried  0 ; size 153
_propose_graph: iteration 17 ; core 0 of 24 ; original_cips tried  1 ; size 153
_propose_graph: iteration 18 ; core 0 of 13 ; original_cips tried  0 ; size 153
_propose_graph: iteration 19 ; core 0 of 13 ; original_cips tried  0 ; size 153
_propose_graph: iteration 20 ; core 0 of 11 ; original_cips tried  0 ; size 153
_propose_graph: iteration 21 ; core 0 of 4 ; original_cips tried  0 ; size 153
_propose_graph: iteration 22 ; core 0 of 34 ; original_cips tried  0 ; size 153
_propose_graph: iteration 23 ; core 0 of 3 ; original_cips tried  0 ; size 153
_propose_graph: iteration 24 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 25 ; core 0 of 5 ; original_cips tried  1 ; size 153
_propose_graph: iteration 26 ; core 0 of 2 ; original_cips tried  0 ; size 153
_propose_graph: iteration 27 ; core 0 of 3 ; original_cips tried  0 ; size 153
_propose_graph: iteration 28 ; core 0 of 1 ; original_cips tried  0 ; size 150
_propose_graph: iteration 29 ; core 0 of 10 ; original_cips tried  0 ; size 150
_propose_graph: iteration 30 ; core 0 of 1 ; original_cips tried  0 ; size 150
faster iso check failed
_propose_graph: iteration 31 ; core 0 of 4 ; original_cips tried  1 ; size 150
_propose_graph: iteration 32 ; core 0 of 1 ; original_cips tried  0 ; size 150
_propose_graph: iteration 33 ; core 0 of 2 ; original_cips tried  0 ; size 150
_propose_graph: iteration 34 ; core 0 of 2 ; original_cips tried  1 ; size 150
_propose_graph: iteration 35 ; core 0 of 2 ; original_cips tried  2 ; size 150
_propose_graph: iteration 36 ; core 0 of 1 ; original_cips tried  0 ; size 150
_propose_graph: iteration 37 ; core 0 of 9 ; original_cips tried  0 ; size 150
_propose_graph: iteration 38 ; core 0 of 2 ; original_cips tried  2 ; size 150
_propose_graph: iteration 39 ; core 0 of 1 ; original_cips tried  0 ; size 150
_propose_graph: iteration 40 ; core 0 of 6 ; original_cips tried  1 ; size 150
_propose_graph: iteration 41 ; core 0 of 1 ; original_cips tried  0 ; size 150
_propose_graph: iteration 42 ; core 0 of 6 ; original_cips tried  0 ; size 150
_propose_graph: iteration 43 ; core 0 of 9 ; original_cips tried  1 ; size 150
_propose_graph: iteration 44 ; core 0 of 11 ; original_cips tried  1 ; size 150
_propose_graph: iteration 45 ; core 0 of 2 ; original_cips tried  0 ; size 150
_propose_graph: iteration 46 ; core 0 of 4 ; original_cips tried  1 ; size 150
_propose_graph: iteration 47 ; core 0 of 1 ; original_cips tried  0 ; size 150
_propose_graph: iteration 48 ; core 0 of 1 ; original_cips tried  3 ; size 150
_propose_graph: iteration 49 ; core 0 of 4 ; original_cips tried  0 ; size 150
Graph id: 26
select_cip_for_substitution failed because no suiting interface was found,             extract failed 30 times; cip found but unacceptable:27 
'NoneType' object has no attribute '_score'
Traceback (most recent call last):
  File "/home/ikea/GraphLearn/graphlearn/graphlearn.py", line 407, in _sample
    candidate_graph_manager = self._propose(graph_manager)
  File "/home/ikea/GraphLearn/graphlearn/graphlearn.py", line 612, in _propose
    self.monitorobject.info('backtrack to (score)',self.backtrack_graphman._score)
AttributeError: 'NoneType' object has no attribute '_score'

_sample stopped at -1 out of 50 n_steps
Graph id: 27
_propose_graph: iteration 0 ; core 0 of 1 ; original_cips tried  0 ; size 180
_propose_graph: iteration 1 ; core 0 of 2 ; original_cips tried  0 ; size 180
_propose_graph: iteration 2 ; core 0 of 3 ; original_cips tried  0 ; size 204
_propose_graph: iteration 3 ; core 0 of 3 ; original_cips tried  0 ; size 204
_propose_graph: iteration 4 ; core 0 of 3 ; original_cips tried  0 ; size 204
_propose_graph: iteration 5 ; core 0 of 3 ; original_cips tried  0 ; size 204
_propose_graph: iteration 6 ; core 0 of 1 ; original_cips tried  0 ; size 204
_propose_graph: iteration 7 ; core 0 of 39 ; original_cips tried  0 ; size 204
_propose_graph: iteration 8 ; core 0 of 3 ; original_cips tried  0 ; size 204
_propose_graph: iteration 9 ; core 0 of 1 ; original_cips tried  0 ; size 204
_propose_graph: iteration 10 ; core 0 of 1 ; original_cips tried  0 ; size 204
_propose_graph: iteration 11 ; core 0 of 20 ; original_cips tried  0 ; size 204
_propose_graph: iteration 12 ; core 0 of 3 ; original_cips tried  0 ; size 204
_propose_graph: iteration 13 ; core 0 of 2 ; original_cips tried  0 ; size 204
_propose_graph: iteration 14 ; core 0 of 2 ; original_cips tried  0 ; size 180
_propose_graph: iteration 15 ; core 0 of 20 ; original_cips tried  0 ; size 203
_propose_graph: iteration 16 ; core 0 of 3 ; original_cips tried  0 ; size 203
_propose_graph: iteration 17 ; core 0 of 1 ; original_cips tried  0 ; size 203
_propose_graph: iteration 18 ; core 0 of 1 ; original_cips tried  0 ; size 203
_propose_graph: iteration 19 ; core 0 of 1 ; original_cips tried  0 ; size 203
_propose_graph: iteration 20 ; core 0 of 20 ; original_cips tried  1 ; size 203
_propose_graph: iteration 21 ; core 0 of 3 ; original_cips tried  0 ; size 203
_propose_graph: iteration 22 ; core 0 of 3 ; original_cips tried  0 ; size 203
_propose_graph: iteration 23 ; core 0 of 3 ; original_cips tried  0 ; size 203
_propose_graph: iteration 24 ; core 0 of 3 ; original_cips tried  0 ; size 203
_propose_graph: iteration 25 ; core 0 of 1 ; original_cips tried  0 ; size 203
_propose_graph: iteration 26 ; core 0 of 3 ; original_cips tried  0 ; size 203
faster iso check failed
_propose_graph: iteration 27 ; core 0 of 3 ; original_cips tried  1 ; size 200
_propose_graph: iteration 28 ; core 0 of 1 ; original_cips tried  0 ; size 200
_propose_graph: iteration 29 ; core 0 of 5 ; original_cips tried  1 ; size 200
_propose_graph: iteration 30 ; core 0 of 1 ; original_cips tried  0 ; size 204
_propose_graph: iteration 31 ; core 0 of 4 ; original_cips tried  0 ; size 204
_propose_graph: iteration 32 ; core 0 of 7 ; original_cips tried  1 ; size 204
_propose_graph: iteration 33 ; core 0 of 1 ; original_cips tried  1 ; size 204
_propose_graph: iteration 34 ; core 0 of 1 ; original_cips tried  0 ; size 204
_propose_graph: iteration 35 ; core 0 of 19 ; original_cips tried  0 ; size 204
_propose_graph: iteration 36 ; core 0 of 1 ; original_cips tried  0 ; size 208
_propose_graph: iteration 37 ; core 0 of 3 ; original_cips tried  1 ; size 208
_propose_graph: iteration 38 ; core 0 of 5 ; original_cips tried  0 ; size 208
_propose_graph: iteration 39 ; core 0 of 1 ; original_cips tried  0 ; size 208
_propose_graph: iteration 40 ; core 0 of 6 ; original_cips tried  0 ; size 206
_propose_graph: iteration 41 ; core 0 of 7 ; original_cips tried  0 ; size 206
_propose_graph: iteration 42 ; core 0 of 5 ; original_cips tried  0 ; size 206
_propose_graph: iteration 43 ; core 0 of 5 ; original_cips tried  0 ; size 206
_propose_graph: iteration 44 ; core 0 of 5 ; original_cips tried  0 ; size 206
_propose_graph: iteration 45 ; core 0 of 19 ; original_cips tried  1 ; size 206
_propose_graph: iteration 46 ; core 0 of 3 ; original_cips tried  0 ; size 206
_propose_graph: iteration 47 ; core 0 of 10 ; original_cips tried  1 ; size 206
_propose_graph: iteration 48 ; core 0 of 3 ; original_cips tried  0 ; size 206
_propose_graph: iteration 49 ; core 0 of 2 ; original_cips tried  0 ; size 206
Graph id: 28
CPU times: user 1min 44s, sys: 55.2 s, total: 2min 39s
Wall time: 3min 42s

In [7]:
'''
%matplotlib inline
from itertools import islice
import numpy as np
import matplotlib.pyplot as plt

step=1
num_graphs_per_plot=3
num_plots=np.ceil([len(scores)/num_graphs_per_plot])
for i in range(num_plots):
    plt.figure(figsize=(10,5))
    for j,score in enumerate(scores[i*num_graphs_per_plot:i*num_graphs_per_plot+num_graphs_per_plot]):
        data = list(islice(score,None, None, step))
        plt.plot(data, label='graph %d'%(j+i*num_graphs_per_plot+id_start))
    plt.legend(loc='lower right')
    plt.grid()
    plt.ylim(-0.1,1.1)
    plt.show()
    
'''


Out[7]:
"\n%matplotlib inline\nfrom itertools import islice\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nstep=1\nnum_graphs_per_plot=3\nnum_plots=np.ceil([len(scores)/num_graphs_per_plot])\nfor i in range(num_plots):\n    plt.figure(figsize=(10,5))\n    for j,score in enumerate(scores[i*num_graphs_per_plot:i*num_graphs_per_plot+num_graphs_per_plot]):\n        data = list(islice(score,None, None, step))\n        plt.plot(data, label='graph %d'%(j+i*num_graphs_per_plot+id_start))\n    plt.legend(loc='lower right')\n    plt.grid()\n    plt.ylim(-0.1,1.1)\n    plt.show()\n    \n"

In [8]:
'''
draw the score history for each of the graphs
'''
colors=['b','g','r','c','m','y','k','w']

%matplotlib inline
from itertools import islice
import matplotlib.pyplot as plt
import numpy as np
step=1
num_graphs_per_plot=3
num_plots=np.ceil([len(scores)/num_graphs_per_plot])
for i in range(num_plots):
    plt.figure(figsize=(10,5))
    for j,score in enumerate(scores[i*num_graphs_per_plot:i*num_graphs_per_plot+num_graphs_per_plot]):
        data = list(islice(score,None, None, step))
        plt.plot(data,ls='-',color=colors[j], label='graph %d'%(j+i*num_graphs_per_plot+id_start))

        # okok now we need to add the infernal evaluation
        seqs=sequences[i*num_graphs_per_plot+j]
        seqs=seqs.split('n')
        
        # SEQUENCES STILL CONTAIN F, ALSO THERE ARE ERRORMESSAGES AT THE END OF INFO
        #seqs=seqs[:-1]
    
        #print seqs
        data2= rna.infernal_checker(seqs,cmfile='../rf00005.cm')
        #print data2,seqs
        plt.plot(data2,ls='--',color=colors[j], label='graph %d infernal score'%(j+i*num_graphs_per_plot+id_start))
    
    plt.legend(loc='lower right')
    plt.grid()
    plt.ylim(-0.1,1.1)
    plt.show()



In [ ]:
import graphlearn.abstract_graphs.RNA as rna
import graphlearn.utils.draw as draw
def showmon(d):
    for k,v in d.items():
        print "%s : %s" % (k,str(v))
    print '\n'
    
showmon(sampler.monitors[17][12])
g=sampler.monitors[17][12]['graphwrapper']
draw.graphlearn(g.base_graph())
print g.structure
print g.sequence

if False:
    for text,graphs in sampler.monitors[17].show(start=0):
        print text
        draw.graphlearn(graphs, size=15)

In [ ]:
g=sampler.monitors[1][-1]['graphwrapper']

print g.__dict__

In [ ]:
import networkx as nx
import graphlearn.utils.draw as draw
from eden.graph import Vectorizer

v=Vectorizer()
def getpathgraph(labels):
    nlabels= len(labels)
    G=nx.path_graph(nlabels)
    for e in range(nlabels):
        G.node[e]['label']=labels[e]
    for e in range(nlabels-1):
        G.edge[e][e+1]['label']='.'
    return G

g=getpathgraph("ABC")

g= v._edge_to_vertex_transform(g)

draw.graphlearn_draw(g,contract=False,show_direction=True)

g2=nx.DiGraph(g)
#draw.display(g2,contract=False,vertex_label='id')

for n,d in g2.nodes(data=True):
    if 'edge' in d:
        if d['label']=='.':
            ns=g2.neighbors(n)
            g2.remove_edge(ns[1],n)
            g2.remove_edge(n,ns[0])
          
       
#g2 = g2.to_undirected()
draw.graphlearn(g2,contract=False,vertex_label='id',show_direction=True)
g2.edges()
for n in g2.nodes():
    print n,g2.neighbors(n)
print isinstance(g2, nx.DiGraph)

In [ ]:
g2.edges(0,data=True)

In [ ]:
asd = g2.subgraph(range(2)).copy()

In [ ]:


In [ ]:
class A(object):
    def __init__(self,a=123):
        self.a=a
        
        
class B(A):
    def __init__(self,b=122):
        super(B,self).__init__(b)
        
        

class C(A):
    def __init__(self,c=121):
        super(C,self).__init__(c)
        
        
c=C()
c.a

In [ ]:
# testin cycle stuff
import networkx as nx
import graphlearn.utils.draw as draw
import graphlearn.feasibility as feas
from eden.graph import Vectorizer
v=Vectorizer()
%matplotlib inline


def find_all_cycles(G, source=None, cycle_length_limit=None):
    """forked from networkx dfs_edges function. Assumes nodes are integers, or at least
    types which work with min() and > ."""
    if source is None:
        # produce edges for all components
        nodes=[i[0] for i in nx.connected_components(G)]
    else:
        # produce edges for components with source
        nodes=[source]
    # extra variables for cycle detection:
    cycle_stack = []
    output_cycles = set()
    
    def get_hashable_cycle(cycle):
        """cycle as a tuple in a deterministic order."""
        m = min(cycle)
        mi = cycle.index(m)
        mi_plus_1 = mi + 1 if mi < len(cycle) - 1 else 0
        if cycle[mi-1] > cycle[mi_plus_1]:
            result = cycle[mi:] + cycle[:mi]
        else:
            result = list(reversed(cycle[:mi_plus_1])) + list(reversed(cycle[mi_plus_1:]))
        return tuple(result)
    
    for start in nodes:
        if start in cycle_stack:
            continue
        cycle_stack.append(start)
        
        stack = [(start,iter(G[start]))]
        while stack:
            parent,children = stack[-1]
            try:
                child = next(children)
                
                if child not in cycle_stack:
                    cycle_stack.append(child)
                    stack.append((child,iter(G[child])))
                else:
                    i = cycle_stack.index(child)
                    if i < len(cycle_stack) - 2: 
                      output_cycles.add(get_hashable_cycle(cycle_stack[i:]))
                
            except StopIteration:
                stack.pop()
                cycle_stack.pop()
    
    return [list(i) for i in output_cycles]


def getpathgraph(labels):
    nlabels= len(labels)
    G=nx.path_graph(nlabels)
    for e in range(nlabels):
        G.node[e]['label']=labels[e]
    for e in range(nlabels-1):
        G.edge[e][e+1]['label']='.'
    return G

#g=getpathgraph("ABC")

#g= v._edge_to_vertex_transform(g)

#draw.graphlearn_draw(g,contract=False,show_direction=True)


#draw.display(g2,contract=False,vertex_label='id')

g=nx.cycle_graph(10)
g.add_edge(2,7)
g.add_edge(10,0)

draw.graphlearn_draw(g, vertex_label='id')


feas.rooted_problem_cycle(g,2,4)

In [ ]:
print g.graph

In [ ]:


In [ ]:


In [ ]:


In [ ]:
stru,stri='(.((...))...)', 'aFaaaaaaaaaaa'



def pairs(s):
    "give me a bond dict"
    unpaired=[]
    pairs={}
    for i,c in enumerate(s):
        if c=='(':
            unpaired.append(i)
        if c==')':
            partner=unpaired.pop()
            pairs[i]=partner
            pairs[partner]=i
    return pairs



def fix_structure( stru,stri ):
    '''
    the problem is to check every (( and )) . 
    if the bonding partners are not next to each other we know that we need to act.
    '''
    p=pairs(stru)
    lastchar="."
    problems=[]
    for i,c in enumerate(stru):
        # checking for )) and ((
        if c==lastchar and c!='.':
            if abs(p[i]-p[i-1])!=1: #the partners are not next to each other
                problems.append(i)
        # )( provlem
        elif c=='(':
            if lastchar==')':
                problems.append(i)          
        lastchar=c
            
    problems.sort(reverse=True)
    for i in problems:
        stru=stru[:i]+'.'+stru[i:]
        stri=stri[:i]+'F'+stri[i:]

    return stru,stri
    

    
fix_structure(stru,stri)

In [ ]:
l=[[4,5],[3,4]]
l.sort()
l

In [ ]:


In [ ]:
import graphlearn.abstract_graphs.RnaWrap as RW
from eden.converter.fasta import fasta_to_sequence   
seq = [ b for (a,b) in fasta_to_sequence("RF00005.fa") ] 
        
folder=RW.NearestNeighborFolding(seq,4)

folder.fold("GGGGCCUUAGCUCAGCUGGGAGAGCGCCUGCUUUGCACGCAGGAGGUCAGCGGUUCGAUGGCGCUAGGCUCCA")
a,b=folder.call_folder()

In [ ]:
import textwrap
textwrap.wrap("asdasdasdasdasdasd", width=3)

In [ ]:
print a,b

In [ ]:
s="asdasdasdasd"
s.get(z,123)

In [ ]:
z=[1,2,3]
z.reverse()
z

In [ ]:
def lol():
    print "a"
    return False

if True or lol():
    pass

In [ ]: