def run(Parameters, Verbose=0): for key in Parameters: if not key in keywords: print ' ** Unknown parameter: "%s"' % key print ' Parameters must belong to:', ','.join(keywords) raise Exception Db_name = Parameters['Db_name'] Components = Parameters['Components'] Interactions = Parameters['Interactions'] Constraint = Parameters['Constraint'] Model = Models.Interface(Components, Interactions) if Verbose > -1: print print '---CP Enumeration by Initial Constraints' print 'Created database: ', "'" + Db_name + "'" Model.info() if os.path.isfile(Db_name): if Verbose > -1: print 'Database', Db_name, 'exists already. File replaced.' os.remove(Db_name) Database.New(Db_name, Model) cps = Parser.Interface(Model) cps.parse(Constraint) if Verbose > -1: print print 'Constraint:' print Constraint print print 'Enumerating, please wait..' db = Database.Interface(Db_name) count = 0 for param in cps.solutions(Verbose): db.insert_row(param) count += 1 db.close() if Verbose > -1: print 'Solutions: ', count
def run(): # specify input: name_database = 'perturbation_example.sqlite' ID_model = 30 # all inputs specified db = Database.Analysis(name_database) model = db.readModel() partargets = db.export(ID_model)[0] db.close() #print partargets print 'Model ', ID_model, ' from ', name_database, ' represented by logical expressions for all pairs of component and target value:' for comp in model.components: localpars = [] for par in model.parameters: if par.owner.name == comp.name: localpars.append(par) localvars = [c[0].name for c in localpars[0].context.items()] localmax = [c[0].max for c in localpars[0].context.items()] localindex = dict( zip([c[0] for c in localpars[0].context.items()], range(len(localvars)))) LF = Logicfun(localvars, localmax) # a list with truthtables for all values for all components (all empty now): ttbls = [[] for c in xrange(comp.max + 1)] # now check for every state (cmpltt contains all) which parameters are active for i, bstate in enumerate(LF.cmpltt): for lpar in localpars: for r in lpar.context.items( ): # check the context, r[0] is the regulator, # r[1] the values, where it is active # if one regulator is not active, parameter cant be neither, so break if not ((i // LF.levprod[localindex[r[0]]]) % LF.nlevs[localindex[r[0]]]) in r[1]: break else: # if instead all regulators are active this state is #added to the truthtable of the parameter ttbls[partargets[lpar]].append(bstate) #print LF.cmpltt #print TTbls print '\nTarget values of ', comp.name, ' and their conditions:' for j, v in enumerate(ttbls): # now the truthtables are translated to minimal DNFs primecov = LF.minimise(v) #get a prime cover expr = LF.writeexpr2( primecov, 'brackets') # get a explicit expression of the minimal DNF print comp.name, '-> %d : ' % j, expr
def run(Parameters): Db_name = Parameters['Db_name'] Restriction = Parameters['Restriction'] Property_name = Parameters['Property_name'] Specification = Parameters['Specification'] Description = Parameters['Description'] db = Database.Interface(Db_name) Model = db.get_model() if Property_name in db.property_names: print 'Property', Property_name, 'is reset.' db.reset_column(Property_name) else: db.add_column(Property_name, 'int', Description) annotation_condition = '"' + Property_name + '"' + ' IS NULL' if Restriction: annotation_condition += ' and ' + Restriction print print '---Annotation by a predicates' print 'Database name: ', "'" + Db_name + "'" print 'Restriction: ', "'" + Restriction + "'" print 'Models in database: ', db.count(annotation_condition), '/', db.size cps = Parser.Interface(Model) cps.parse(Specification) sql = cps.toSQL() db.set_labels(sql, {Property_name: '1'}) db.set_labels('not (%s)' % sql, {Property_name: '0'}) T = db.count(Property_name + '=1') F = db.count(Property_name + '=0') selected = db.count(Restriction) db.close() print 'Models selected: ', selected, '/', db.size print 'Name: ', "'" + Property_name + "'" print 'Description: ', Description print 'Specfication: ', "'" + Specification + "'" print "Label '1': ", T print "Label '0': ", F
def run( Parameters ): for key in Parameters: if not key in keywords: print ' ** Unknown parameter: "%s"'%key print ' Parameters must belong to:',','.join(keywords) raise Exception Db_name = Parameters['Db_name'] Restriction = Parameters['Restriction'] FileName = Parameters['FileName'] db = Database.Interface( Db_name ) selected = db.count( Restriction ) Model =db.get_model() if not selected: print 'No parametrizations selected.' return print print '---Export as text file' print 'Database name: ', "'"+Db_name+"'" print 'Restriction: ', "'"+Restriction+"'" print 'Models selected: ', selected,'/',db.size param, labels, rowid = db.get_row( Restriction ) eqs = PrimeImplicants.Equations.FromTomClass( Model, param ) eqs.minimize() eqs.save net.save( FileName, verbose=2 ) db.close()
def run(): Db_name = 'Carbon.sqlite' Restriction = '' db = Database.Analysis(Db_name) db.select(Restriction) selected = db.count() print print 'Analysis of parameter values' print ' -finds values common to all parametrizations' print ' -finds value ranges of all parameters' print model = db.readModel() model.info() print print 'Database name: ', "'" + Db_name + "'" print 'Restriction: ', "'" + Restriction + "'" print 'Models in database: ', db.size print 'Models selected: ', selected cps = Parser.Interface(model) print print 'Ranges of parameter values:' for comp in model.components: print comp for p in comp.parameters: sql = 'SELECT DISTINCT ' + str( p ) + ' FROM Parametrizations WHERE ' + Database.SELECTION + '=1' db.cur.execute(sql) values = sorted([str(row[str(p)]) for row in db.cur]) print(' %s:' % p).ljust(15) + ','.join(values) db.close()
def run(Parameters): for key in Parameters: if not key in keywords: print ' ** Unknown parameter: "%s"' % key print ' Parameters must belong to:', ','.join(keywords) raise Exception Db_name = Parameters['Db_name'] Restriction = Parameters['Restriction'] Property_name = Parameters['Property_name'] Description = Parameters['Description'] Formula = Parameters['Formula'] Initial_states = Parameters['Initial_states'] Verification_type = Parameters['Verification_type'] Fix = Parameters['Fix'] db = Database.Interface(Db_name) selected = db.count(Restriction) init = Initial_states if not Initial_states: init = 'All' print print '---Annotation by LTL model checking' print 'Restriction: ', "'" + Restriction + "'" print 'Models selected: ', selected, '/', db.size print 'Property name: ', Property_name print 'LTL formula: ', Formula print 'Formula description: ', Description print 'Initial states: ', init print 'Verification type: ', Verification_type if Fix: print 'Fixed components: ', ', '.join( [n + '=' + str(v) for n, v in Fix.items()]) if Property_name in db.property_names: print 'Property', Property_name, 'is reset.' db.reset_column(Property_name) else: db.add_column(Property_name, 'INT', Description) for name in Fix: if name in Initial_states: print 'Component', name, 'is fixed and seems to appear in initial states spec. Please check this is correct.' annotation_condition = '"' + Property_name + '"' + ' IS NULL' if Restriction: annotation_condition += ' and ' + Restriction Model = db.get_model() mc = ModelChecking.LTL(Model, Formula, Initial_states, Verification_type, Fix) print print 'Starting annotations, please wait..' freqs = {0: 0, 1: 0} count = 0 param, labels, rowid = db.get_row(annotation_condition) while param: count += 1 label = 0 if mc.check(param): label = 1 db.set_labels('rowid=%i' % rowid, {Property_name: label}) freqs[label] += 1 param, labels, rowid = db.get_row(annotation_condition) print '\rProgress: %2.3f%%' % (100. * count / selected), sys.stdout.flush() db.close() print print "Label '1': ", freqs[1] print "Label '0': ", freqs[0]
def run( Parameters ): for key in Parameters: if not key in keywords: print ' ** Unknown parameter: "%s"'%key print ' Parameters must belong to:',','.join(keywords) raise Exception Db_name = Parameters['Db_name'] Restriction = Parameters['Restriction'] db = Database.Interface( Db_name ) selected = db.count( Restriction ) Model = db.get_model() print print '---Annotation by Number of Prime Implicants' print 'Restriction: ', "'"+Restriction+"'" print 'Models selected: ', selected,'/',db.size print 'Description: Adds a column "PIC_v" for each component v that records the number of PIs of f_v' print ' and a column "PIC" which is the total complexity.' flag = False names = ['PIC_%s'%v.name for v in Model.components]+['PIC'] for name in names: if name in db.property_names: flag = True db.reset_column( name ) else: if name=='PIC': desc='The total number of prime implicants.' else: desc='The number of prime implicants of %s'%(name[5:-2]) db.add_column( name, 'INT', desc ) if flag: print ' Columns reset.' annotation_condition = ' or '.join(['PIC_%s IS NULL'%v.name for v in Model.components]) if Restriction: annotation_condition+= ' and '+Restriction print print 'Starting annotations, please wait..' freqs = {} param, labels, rowid = db.get_row( annotation_condition ) while param: eqs = PrimeImplicants.Equations.FromTomClass( Model, param ) primes = eqs.compute_primes() for v in Model.components: sql = ' and '.join(['%s=%i'%(p,k) for p,k in param.items() if p.owner.name==v.name]) column = 'PIC_%s'%v.name label = 0 for a in primes[v.name]: label+=len(primes[v.name][a]) ID = v.name+'_PIC='+str(label) if not ID in freqs: freqs[ID] = 0 freqs[ID]+=1 db.set_labels(sql, {column: label}) param, labels, rowid = db.get_row( annotation_condition ) count = db.count( annotation_condition ) print '\rProgress: %2.3f%%'%(100.*(1-1.*count/selected)), sys.stdout.flush() sql = ' + '.join(['"PIC_%s"'%v.name for v in Model.components]) db.cur.execute('UPDATE Parametrizations SET PIC = '+sql) db.cur.execute('SELECT Min(PIC) FROM Parametrizations') MinPIC = db.cur.fetchone()['Min(PIC)'] db.cur.execute('SELECT Max(PIC) FROM Parametrizations') MaxPIC = db.cur.fetchone()['Max(PIC)'] print print ' Complexities PIC_v' for label in sorted(freqs.keys()): print (" '%s':"%label).ljust(22),freqs[label] for i in range(MinPIC,MaxPIC+1): print ' PIC=',i,'#=',db.count('PIC=%i'%i) db.close()
def run(Parameters): Db_name = Parameters['Db_name'] Restriction = Parameters['Restriction'] Property_name = Parameters['Property_name'] Property_type = Parameters['Property_type'] Description = Parameters['Description'] TimeSeries = Parameters['TimeSeries'] Monotony = Parameters['Monotony'] print print 'Annotation by Saschas A*-graph traversal' print ' -checks a time series with monotony spec' print db = Database.Modification(Db_name) if Property_name in db.property_names: print 'Property', Property_name, 'is reset.' db.reset(Property_name) db.close() db = Database.Analysis(Db_name) db.select(Restriction) selected = db.count() Model = db.readModel() db.close() Model.info() print print 'Database name: ', "'" + Db_name + "'" print 'Restriction: ', "'" + Restriction + "'" print 'Models in database: ', db.size print 'Models selected: ', selected print 'Property name: ', Property_name print 'Time Series: ' for row in TimeSeries: print row print 'Monotony' for row in Monotony: print row db = Database.Annotation(Db_name) db.newProperty(Property_name, Property_type, Description) db.select(Property_name, Restriction) print print 'Starting annotations, please wait..' freqs = {'F': 0, 'T': 0} count = 0 walker = Walker(Model) walker.set_timeseries(TimeSeries, Monotony) param, labels, rowid = db.next() while param: count += 1 label = 'F' walker.set_parameterset(param) if walker.is_compatible(): label = 'T' db.label('rowid=%i' % rowid, label) freqs[label] += 1 param, labels, rowid = db.next() print '\rProgress: %2.3f%%' % (100. * count / selected), sys.stdout.flush() db.close() print print "Label 'T': ", freqs['T'] print "Label 'F': ", freqs['F'] print
def run(Parameters): for key in Parameters: if not key in keywords: print ' ** Unknown parameter: "%s"' % key print ' Parameters must belong to:', ','.join(keywords) raise Exception Db_name = Parameters['Db_name'] Interactions = Parameters['Interactions'] Restriction = Parameters['Restriction'] db = Database.Interface(Db_name) selected = db.count(Restriction) model = db.get_model() print print '---Strictest edge labels' print 'Database name: ', "'" + Db_name + "'" print 'Restriction: ', "'" + Restriction + "'" print 'Models selected: ', selected, '/', db.size print 'Interactions selected: ', if not Interactions: print 'All' for a, b, trs in model.interactions: for t in trs: Interactions.append((a, b, t)) else: print ','.join( [a + '-' + str(i) + '->' + b for a, b, i in Interactions]) # encoding + - SEL_mapping = { '00': 'not observable', '01': 'inhibiting only', '10': 'activating only', '11': 'dual', '0001': 'not activating', '0010': 'not inhibiting', '0011': 'dual xor not observable', '0110': 'monotonous', '0111': 'inhibiting', '1011': 'activating', '000110': 'not dual', '000111': 'not activating only', '001011': 'not inhibiting only', '011011': 'observable', '00011011': 'free' } cps = Parser.Interface(model) print print 'Strictest edge labels:' for a, b, t in Interactions: signature = '' cps.parse('NotActivating(%s,%s,%i) and NotInhibiting(%s,%s,%i)' % (a, b, t, a, b, t)) condition = cps.toSQL() if Restriction: condition += ' and ' + Restriction sql = 'SELECT rowid FROM Parametrizations WHERE ' + condition + ' LIMIT 1' db.cur.execute(sql) row = db.cur.fetchone() if row: signature += '00' cps.parse('NotActivating(%s,%s,%i) and Inhibiting(%s,%s,%i)' % (a, b, t, a, b, t)) condition = cps.toSQL() if Restriction: condition += ' and ' + Restriction sql = 'SELECT rowid FROM Parametrizations WHERE ' + condition + ' LIMIT 1' db.cur.execute(sql) row = db.cur.fetchone() if row: signature += '01' cps.parse('Activating(%s,%s,%i) and NotInhibiting(%s,%s,%i)' % (a, b, t, a, b, t)) condition = cps.toSQL() if Restriction: condition += ' and ' + Restriction sql = 'SELECT rowid FROM Parametrizations WHERE ' + condition + ' LIMIT 1' db.cur.execute(sql) row = db.cur.fetchone() if row: signature += '10' cps.parse('Activating(%s,%s,%i) and Inhibiting(%s,%s,%i)' % (a, b, t, a, b, t)) condition = cps.toSQL() if Restriction: condition += ' and ' + Restriction sql = 'SELECT rowid FROM Parametrizations WHERE ' + condition + ' LIMIT 1' db.cur.execute(sql) row = db.cur.fetchone() if row: signature += '11' if signature: print a.rjust(10) + '-(%i)->' % t + b.ljust( 10) + SEL_mapping[signature] else: print 'Error for', a, b, t db.close()
def run(): Db_name = 'Carbon.sqlite' Property = 'SuperCoiling' Correlation_set = [] Restriction = '' Minimal = True print print print 'Analysis of Correlations' print ' -finds correlations between a property and a given correlation superset' print db = Database.Analysis(Db_name) if not db.property_names: print "No properties in DB '" + Db_name + "'", "please add annotations." db.close() return if not Property: print 'Please name the property you are interested in.' db.close() return if not Property in db.property_names: print 'Property ' + "'" + Property + "'", 'is not in', Db_name print 'Choose one of', ','.join(db.property_names) db.close() return for p in Correlation_set: if not p in db.property_names: print 'Property', p, "is not in '" + Db_name + "', it is automatically removed from the analysis." Correlation_set = [ p for p in Correlation_set if p in db.property_names and p != Property ] if not Correlation_set: Correlation_set = list(db.property_names) Correlation_set.remove(Property) if len(Correlation_set) < 2: print 'Correlation set, currently', Correlation_set, 'must contain at least two properties, please add some.' db.close() return db.select(Restriction) selected = db.count() model = db.readModel() model.info() print print 'Database name: ', "'" + Db_name + "'" print 'Restriction: ', "'" + Restriction + "'" print 'Models in database: ', db.size print 'Models selected: ', selected print 'Properties in DB: ', ','.join([n for n in db.property_names]) print 'Property: ', Property print 'Correlation superset: ', ','.join(Correlation_set) print 'Find minimal sets: ', Minimal print print 'Label coverage' for p in Correlation_set + [Property]: sql = p + ' IS NOT NULL' count = db.count(sql) print '%s %i (%2.1f%%)' % ( (' ' + p + ':').ljust(19), count, 100. * count / selected) #labels = db.labels(Properties1.union(Properties2), Selection=True) correlations = [] hit = False for r in range(2, len(Correlation_set) + 1): if hit and Minimal: break func = {} for C in IT.combinations(Correlation_set, r): props = C + (Property, ) sql = 'SELECT DISTINCT ' + ','.join( props ) + ' FROM Parametrizations WHERE ' + Database.SELECTION + '=1' db.cur.execute(sql) for row in db.cur: key = tuple([row[p] for p in C]) if key in func: if func[key] != row[Property]: func = {} break func[key] = row[Property] if func: hit = True correlations.append(sorted(C)) db.close() if correlations: print print 'Correlations:' for c in correlations: print ' ', Property, 'correlates with', '{' + ','.join(c) + '}' else: print print 'Found no correlations for', Property, 'in', Correlation_set print
def run(): if create: parameters = { 'Db_name': DBNAME, 'Components': [('v1', 1), ('v2', 2), ('v3', 3)], 'Interactions': [('v1', 'v2', (1, )), ('v2', 'v1', (1, )), ('v2', 'v3', (2, )), ('v3', 'v1', (1, )), ('v3', 'v2', (2, )), ('v3', 'v3', (3, ))] } clauses = [ 'Some(v1>=0,v1,=,0)', 'Some(v1>=0,v1,=,1)', 'Some(v1>=0,v2,=,0)', 'Some(v1>=0,v2,=,1)', 'Some(v1>=0,v2,=,2)', 'Some(v1>=0,v3,=,0)', 'Some(v1>=0,v3,=,1)', 'Some(v1>=0,v3,=,2)', 'Some(v1>=0,v3,=,3)', ] parameters['Constraint'] = ' and '.join(clauses) Instantiation.CPEnumeration.run(parameters) if not create: db = Database.Interface(DBNAME) model = db.get_model() model.info() db.close() if annotate_compatible: parameters = { 'Db_name': DBNAME, 'Restriction': RESTRICTION, 'Property_name': "ALL_ACTIVE", 'Description': "Exists a path a state 111", 'Formula': "EF(v1 & v2 & v3)", 'Initial_states': "TRUE", 'Verification_type': 'forsome', 'Fix': {} } Annotation.CTL.run(parameters) if analyse_classes: parameters = { 'Db_name': DBNAME, 'Properties': CLASSES, 'Restriction': RESTRICTION } if export_csv: parameters['FileName'] = FNAMECSV Analysis.Classes.run(parameters) if analyse_relationships: parameters = { 'Db_name': DBNAME, 'Properties1': RELATIONSHIPS1, 'Properties2': RELATIONSHIPS2, 'Restriction': RESTRICTION } Analysis.Relationships.run(parameters) if analyse_strictestlabel: parameters = { 'Db_name': DBNAME, 'Interactions': [], 'Restriction': RESTRICTION } Analysis.StrictestEdgeLabels.run(parameters)
def run( Parameters, CustomAlgorithm ): for key in Parameters: if not key in keywords: print ' ** Unknown parameter: "%s"'%key print ' Parameters must belong to:',','.join(keywords) raise Exception Db_name = Parameters['Db_name'] Restriction = Parameters['Restriction'] Property_name = Parameters['Property_name'] Property_type = Parameters['Property_type'] Description = Parameters['Description'] InitialStates = '' if 'InitialStates' in Parameters: InitialStates = Parameters['InitialStates'] db = Database.Interface( Db_name ) Model = db.get_model() states=[] if InitialStates: states=Parser.InitialStates(Model,InitialStates) selected = db.count( Restriction ) if Property_name in db.property_names: print 'Property',Property_name,'is reset.' db.reset_column(Property_name) else: db.add_column( Property_name, 'INT', Description ) annotation_condition = '"'+Property_name+'"'+' IS NULL' if Restriction: annotation_condition+= ' and '+Restriction print print '---Custom Algorithm' print 'Restriction: ', "'"+Restriction+"'" print 'Models selected: ', selected, '/', db.size print 'Property name: ', Property_name print 'Property description: ', Description if states: print 'Initial states: ', InitialStates[:min(20,len(InitialStates))],'(',len(states),')' print print 'Starting annotations, please wait..' freqs = {} count = 0 param, labels, rowid = db.get_row( annotation_condition ) while param: count+=1 labels = CustomAlgorithm( Model, param, labels, states ) ID = ','.join(['%s=%s'%item for item in sorted(labels.items())]) if not ID in freqs: freqs[ID] = 0 freqs[ID]+=1 db.set_labels('rowid=%i'%rowid, labels) param, labels, rowid = db.get_row( annotation_condition ) print '\rProgress: %2.3f%%'%(100.*count/selected), sys.stdout.flush() db.close() print for label in sorted(freqs.keys()): print ("Label '%s':"%label).ljust(22),freqs[label]
def run(Parameters, Verbose=0): for key in Parameters: if not key in keywords: print ' ** Unknown parameter: "%s"' % key print ' Parameters must belong to:', ','.join(keywords) raise Exception Db_name = Parameters['Db_name'] Restriction = Parameters['Restriction'] Components = Parameters['Components'] Display = Parameters['Display'] db = Database.Interface(Db_name) model = db.get_model() d = [] for name in Components: hit = False for comp in model.components: if comp.name == name: d.append(comp) hit = True break if not hit: print ' Component', name, 'is not part of the model, please check.' if not d: Components = model.components else: Components = d selected = db.count(Restriction) print print '---Annotation by component types' print 'Database name: ', "'" + Db_name + "'" print 'Restriction: ', "'" + Restriction + "'" print 'Models selected: ', selected, '/', db.size print 'Components selected: ', ','.join([str(c) for c in Components]) localpars = {} for comp in Components: localnames = tuple([str(p) for p in comp.parameters]) localpars[localnames] = [] sql = 'SELECT DISTINCT ' + ','.join( localnames) + ' FROM Parametrizations' if Restriction: sql += ' WHERE ' + Restriction db.cur.execute(sql) for row in db.cur: localpars[localnames].append(tuple([row[n] for n in localnames])) for comp in Components: if comp.name in db.property_names: print 'Property', comp.name, 'is reset.' db.reset_column(comp.name) else: db.add_column(comp.name, 'int', 'Local functions of %s' % comp.name) for comp in Components: localnames = tuple([str(p) for p in comp.parameters]) for i, localp in enumerate(localpars[localnames]): sql = ' and '.join( [n + '=' + str(v) for n, v in zip(localnames, localp)]) if Restriction: sql += ' and ' + Restriction db.set_labels(sql, {comp.name: i}) print print 'Number of different controls by component:' if Verbose > -1: for comp in Components: localnames = tuple([str(p) for p in comp.parameters]) print if Display.lower() == 'parameters': print 'Component:', comp, 'Parameters:', localnames[ 0], '..', localnames[-1] else: print 'Component:', comp for i, localp in enumerate(localpars[localnames]): sql = ' and '.join( [n + '=' + str(v) for n, v in zip(localnames, localp)]) if Restriction: sql += ' and ' + Restriction param, labels, rowid = db.get_row(sql) if Display.lower() == 'parameters': print ' '.join([str(v) for v in localp]), ' :', print db.count(comp.name + '=' + str(i)) else: eqs = PrimeImplicants.Equations.FromTomClass(model, param) m = eqs.minimize() for val in m[comp.name]: if val > 0: if val > 1: print val, ':', print m[comp.name][val].ljust(50), '(%i)' % ( db.count(comp.name + '=' + str(i))) else: for comp in Components: sql = 'SELECT Count(DISTINCT ' + comp.name + ') FROM Parametrizations' db.cur.execute(sql) row = db.cur.fetchone() count = row['Count(DISTINCT ' + comp.name + ')'] print ' ', (comp.name + ':').ljust(22), count db.close()
def run( Parameters ): for key in Parameters: if not key in keywords: print ' ** Unknown parameter: "%s"'%key print ' Parameters must belong to:',','.join(keywords) raise Exception Db_name = Parameters['Db_name'] Properties1 = Parameters['Properties1'] Properties2 = Parameters['Properties2'] Restriction = Parameters['Restriction'] print print print 'Analysis of [H]ypotheses, [I]mplications, [I]ndependence' print ' -finds relationships between two given sets of properties' print db = Database.Interface(Db_name) if not db.property_names: print "No properties in DB '"+Db_name+"'", "please add annotations." db.close() return for p in [Properties1, Properties2]: for n in p: if not n in db.property_names: print 'Property',n,"is not in '"+Db_name+"', it is automatically removed from the analysis." if not p: p = db.property_names Properties1 = set([p for p in Properties1 if p in db.property_names]) Properties2 = set([p for p in Properties2 if p in db.property_names]) if not Properties1: Properties1 = set(list(db.property_names)) if not Properties2: Properties2 = set(list(db.property_names)) #db.select(Restriction) selected = db.count(Restriction) print 'Database name: ',"'"+Db_name+"'" print 'Restriction: ', "'"+Restriction+"'" print 'Models in database: ', db.size print 'Models selected: ', selected print 'Properties in DB: ',','.join([n for n in db.property_names]) print 'Properties1: ',','.join(Properties1) print 'Properties2: ',','.join(Properties2) print print 'Label coverage' for p in Properties1.union(Properties2): sql = p+' IS NOT NULL' count = db.count(sql) print '%s %i (%2.1f%%)'%((' '+p+':').ljust(19),count,100.*count/selected) labels = db.get_property_labels(Properties1.union(Properties2), SQLSelection=sql) #labels = db.labels(Properties1.union(Properties2), Selection=True) hypotheses = [] for p,v in labels.items(): if len(v)==1: hypotheses.append( p+'='+str(v[0]) ) labels.pop(p) independences = dict([(p,{}) for p in labels]) implications = [] for p1 in labels: for p2 in labels: if p1!=p2: for label in labels[p1]: sql = 'SELECT DISTINCT '+p2+' FROM Parametrizations WHERE '+p1+'="'+str(label)+'" and '+Database.SELECTION+'=1' db.cur.execute(sql) rows = db.cur.fetchall() if len(rows)==1: implications.append( (p1+'='+str(label), p2+'='+str(rows[0][p2])) ) if len(rows)==len(labels[p2]): if not independences[p2].has_key(p1): independences[p2][p1] = [] independences[p2][p1].append( str(label) ) db.close() equivalences = [] for index, (a,b) in enumerate(implications): for c,d in implications[index:]: if a==d and b==c: equivalences.append( (a,b) ) for a,b in equivalences: implications.remove( (a,b) ) implications.remove( (b,a) ) if hypotheses: print print 'Hypotheses:' for h in hypotheses: print ' ',h if implications: print print 'Implications:' for i in implications: print ' ',' => '.join(i) if equivalences: print print 'Equivalences:' for e in equivalences: print ' ',' <=> '.join(e) indeps = [] for p1,v in independences.items(): if not v: independences.pop(p1) for p2 in v: if len(independences[p1][p2])==len(labels[p2]): indeps.append( (p1, p2) ) else: pass#print 'parial independence:',p1,'of values',independences[p1][p2],'of',p2 if indeps: print print 'Independences:' while indeps: a,b = indeps.pop() if (b,a) in indeps: print ' ',a,'and',b,'are mutually independent.' indeps.remove((b,a)) else: print ' ',a,'is independent of',b return
def run(Parameters, verbose=-1): print "unstable, revise" raise Exception for key in Parameters: if not key in keywords: print ' ** Unknown parameter: "%s"' % key print ' Parameters must belong to:', ','.join(keywords) raise Exception Db_name = Parameters['Db_name'] Components = Parameters['Components'] Interactions = Parameters['Interactions'] Constraint = Parameters['Constraint'] Model = Models.Interface(Components, Interactions) if verbose > -1: Model.info() if os.path.isfile(Db_name): if 1: os.remove(Db_name) Database.New(Db_name, Model) else: Database.New(Db_name, Model) cps = Parser.Interface(Model) cps.parse(Constraint) db = Database.Instantiation(Db_name) db.newProperty(Property_name, 'int') roots = 0 for params in cps.solutions(): roots += 1 db.insert(params, {Property_name: 0}) for depth in range(1, Perturbation_depth + 1): for perturbed in itertools.combinations(Model.parameters, depth): options = [] for p in perturbed: options.append( [i for i in p.range if abs(i - params[p]) == 1]) for choice in itertools.product(*options): items = zip(perturbed, choice) new_params = dict(params.items() + items) db.insert(new_params, {Property_name: depth}) db.close() db = Database.Analysis(Db_name) size = db.size - roots db.close() if verbose > -1: print print '---Perturbations of a pool defined by CP' print 'Created database: ', "'" + Db_name + "'" print 'Perturbation depth: ', Perturbation_depth print 'Perturbation name in DB: ', "'" + Property_name + "'" print 'Constraint: ', "'" + Constraint + "'" print 'Initial parametrizations: ', roots print 'Perturbed parametrizations: ', size
def run(): if create: # Model defintion, first components and number of states (1 for Boolean) parameters = { 'Db_name': DBNAME, 'Components': [('EGF', 1), ('EGFR', 1), ('IGF', 1), ('IGFR', 1), ('Sora', 1), ('Raf', 1), ('Erk', 1), ('PI3K', 1), ('Akt', 1), ('mTor', 1)], # definition of interactions with threshold 'Interactions': [ ('EGF', 'EGF', (1, )), ('EGF', 'EGFR', (1, )), ('IGF', 'IGF', (1, )), ('IGF', 'IGFR', (1, )), ('Sora', 'Sora', (1, )), ('EGFR', 'Raf', (1, )), ('Raf', 'Erk', (1, )), ('Erk', 'EGFR', (1, )), ('IGFR', 'PI3K', (1, )), ('PI3K', 'Akt', (1, )), ('Akt', 'mTor', (1, )), # Crosstalk ('mTor', 'IGFR', (1, )), ('PI3K', 'Raf', (1, )), ('Sora', 'Raf', (1, )), ('Sora', 'EGFR', (1, )), ('Sora', 'IGFR', (1, )), ('EGFR', 'PI3K', (1, )), ('Erk', 'mTor', (1, )) ] } # Defintion of edge labels and logical functions: # Boolean(A=1,B) states that B has only A as regulator and becomes active for A=1 # ActivatingOnly and InhibitingOnly defines essential edges, but does not define the logical function # NotActivating and NotInhibiting creates optional edge labels clauses = [ 'Boolean(EGF=1, EGF)', 'Boolean(IGF=1, IGF)', 'Boolean(Sora=1, Sora)', 'Boolean(Raf=1, Erk)', 'Boolean(PI3K=1, Akt)', 'ActivatingOnly(IGF,IGFR,1)', 'ActivatingOnly(EGF,EGFR,1)', 'ActivatingOnly(EGFR,Raf,1)', 'ActivatingOnly(IGFR,PI3K,1)', 'InhibitingOnly(Erk,EGFR,1)', 'ActivatingOnly(Akt,mTor,1)', # Crosstalk 'NotActivating(mTor,IGFR,1)', 'NotActivating(Sora,EGFR,1)', 'NotActivating(Sora,IGFR,1)', 'NotActivating(Sora,Raf,1)', 'NotInhibiting(EGFR,PI3K,1)', 'NotInhibiting(Erk,mTor,1)', 'NotInhibiting(PI3K,Raf,1)' ] parameters['Constraint'] = ' and '.join(clauses) Instantiation.CPEnumeration.run(parameters) if not create: db = Database.Interface(DBNAME) model = db.get_model() model.info() db.close() if annotate_compatible: # this function performs model checking for CTL formulas on the model pool # for detailed description, see Manual # annotate steady-state data ------------------------------------------- parameters = { 'Db_name': DBNAME, 'Restriction': RESTRICTION, 'Property_name': 'WBDMSO', 'Description': 'mTor measurement for DMSO.', 'Formula': 'EF( Delta=0& mTor=1)', 'Initial_states': 'Sora=0', 'Verification_type': 'forsome', 'Fix': {} } Annotation.CTL.run(parameters) parameters = { 'Db_name': DBNAME, 'Restriction': RESTRICTION, 'Property_name': 'WB1851Sora', 'Description': 'mTor measurement for 1851 Sora.', 'Formula': 'EF( Delta=0&mTor=1)', 'Initial_states': 'Sora=1', 'Verification_type': 'forsome', 'Fix': {} } Annotation.CTL.run(parameters) parameters = { 'Db_name': DBNAME, 'Restriction': RESTRICTION, 'Property_name': 'WB1257Sora', 'Description': 'mTor measurement for 1257 Sora.', 'Formula': 'EF( Delta=0& mTor=0)', 'Initial_states': 'Sora=1', 'Verification_type': 'forsome', 'Fix': {} } Annotation.CTL.run(parameters) parameters = { 'Db_name': DBNAME, 'Restriction': RESTRICTION, 'Property_name': 'Bp1257DMSO', 'Description': 'Bioplex measurement for 1257 DMSO.', 'Formula': 'EF( Delta=0&mTor=1&Akt=1&EGFR=1&Erk=1)', 'Initial_states': 'Sora=0', 'Verification_type': 'forsome', 'Fix': {} } Annotation.CTL.run(parameters) # annotate time-series data ------------------------------------------- # 1851 Experiment 1 names = ['Erk', 'EGFR', 'mTor', 'Akt', 'IGFR'] measurements = [ [1, 1, 1, 1, 1], [1, 1, 1, 1, 0], [1, 1, 1, 0, 0], [0, 0, 0, 0, 0], ] init, formula = BooleanTSformula(names, measurements, Fixpoint=False) print init, formula parameters = { 'Db_name': DBNAME, 'Restriction': RESTRICTION, 'Property_name': 'Bp1851DMSO', 'Description': 'Bioplex measurement for 1851 DMSO.', 'Formula': formula, 'Initial_states': init, 'Verification_type': 'forsome', 'Fix': { 'Sora': 0 } } Annotation.CTL.run(parameters) names = ['Erk', 'EGFR', 'mTor', 'Akt', 'IGFR'] measurements = [ [0, 0, 1, 0, 1], [1, 1, 1, 1, 1], [0, 0, 0, 0, 1], ] init, formula = BooleanTSformula(names, measurements, Fixpoint=False) print init, formula parameters = { 'Db_name': DBNAME, 'Restriction': RESTRICTION, 'Property_name': 'Bp1851Sora', 'Description': 'Bioplex measurement for 1851 Sora.', 'Formula': formula, 'Initial_states': init, 'Verification_type': 'forsome', 'Fix': { 'Sora': 1 } } Annotation.CTL.run(parameters) # 1851 Experiment 2 names = ['Erk', 'EGFR', 'mTor', 'Akt', 'IGFR'] measurements = [ [1, 1, 1, 1, 0], [1, 0, 0, 1, 0], [1, 0, 0, 0, 0], [1, 1, 1, 1, 0], [0, 0, 0, 0, 0], [1, 1, 0, 0, 0], [1, 1, 1, 1, 0], ] init, formula = BooleanTSformula(names, measurements, Fixpoint=False) print init, formula parameters = { 'Db_name': DBNAME, 'Restriction': RESTRICTION, 'Property_name': 'Bp1851DMSO2', 'Description': 'Bioplex measurement for 1851 DMSO.', 'Formula': formula, 'Initial_states': init, 'Verification_type': 'forsome', 'Fix': { 'Sora': 0 } } Annotation.CTL.run(parameters) names = ['Erk', 'EGFR', 'mTor', 'Akt', 'IGFR'] measurements = [ [1, 1, 1, 1, 1], [1, 1, 0, 1, 0], [1, 1, 1, 1, 0], [0, 0, 1, 0, 0], [1, 1, 0, 0, 0], [1, 1, 1, 0, 1], ] init, formula = BooleanTSformula(names, measurements, Fixpoint=False) print init, formula parameters = { 'Db_name': DBNAME, 'Restriction': RESTRICTION, 'Property_name': 'Bp1851Sora2', 'Description': 'Bioplex measurement for 1851 Sora.', 'Formula': formula, 'Initial_states': init, 'Verification_type': 'forsome', 'Fix': { 'Sora': 1 } } Annotation.CTL.run(parameters) # 1257 Experiment 1 names = ['Erk', 'EGFR', 'mTor', 'Akt'] measurements = [ [1, 1, 1, 1], [0, 0, 0, 0], [0, 1, 0, 0], [1, 1, 1, 1], [0, 1, 0, 0], [1, 1, 1, 0], ] init, formula = BooleanTSformula(names, measurements, Fixpoint=False) print init, formula parameters = { 'Db_name': DBNAME, 'Restriction': RESTRICTION, 'Property_name': 'Bp1257Sora', 'Description': 'Bioplex measurement for 1257 Sora.', 'Formula': formula, 'Initial_states': init, 'Verification_type': 'forsome', 'Fix': { 'Sora': 1 } } Annotation.CTL.run(parameters) # 1257 Experiment 2 names = ['Erk', 'EGFR', 'mTor', 'Akt'] measurements = [ [1, 1, 0, 0], [0, 1, 1, 0], [1, 1, 1, 1], [0, 0, 0, 0], [0, 1, 0, 0], [1, 1, 1, 1], ] init, formula = BooleanTSformula(names, measurements, Fixpoint=False) print init, formula parameters = { 'Db_name': DBNAME, 'Restriction': RESTRICTION, 'Property_name': 'Bp1257DMSO2', 'Description': 'Bioplex measurement for 1257 DMSO.', 'Formula': formula, 'Initial_states': init, 'Verification_type': 'forsome', 'Fix': { 'Sora': 0 } } Annotation.CTL.run(parameters) names = ['Erk', 'EGFR', 'mTor', 'Akt'] measurements = [[0, 0, 0, 0], [0, 0, 0, 1], [1, 1, 1, 1], [0, 1, 1, 1], [1, 1, 1, 1]] init, formula = BooleanTSformula(names, measurements, Fixpoint=False) print init, formula parameters = { 'Db_name': DBNAME, 'Restriction': RESTRICTION, 'Property_name': 'Bp1257Sora2', 'Description': 'Bioplex measurement for 1257 Sora.', 'Formula': formula, 'Initial_states': init, 'Verification_type': 'forsome', 'Fix': { 'Sora': 1 } } Annotation.CTL.run(parameters) # Annotate presence and absence of optional egdes to models if annotate_crosstalk: db = Database.Interface(DBNAME) model = db.get_model() db.close() constraints = [] # here, the optional edges need to be entered in the form of [('A','B'), ...] for crosstalk in [('Sora', 'Raf'), ('Sora', 'EGFR'), ('Sora', 'IGFR'), ('EGFR', 'PI3K'), ('PI3K', 'Raf'), ('Erk', 'mTor'), ('mTor', 'IGFR')]: con = Engine.Constraints.Parser.PredicateFormula.parseString( 'Observable(%s,%s,1)' % crosstalk, parseAll=True)[0] con.initialize(model) constraints.append(con) def custom_algorithm(Model, Parametrization, Labels, States): return { 'Crosstalk': len([1 for con in constraints if con(Parametrization)]) } parameters = { 'Db_name': DBNAME, 'Property_name': 'Crosstalk', 'Property_type': 'int', 'Description': 'Number of observable crosstalk interactions between the MAPK and mTor pathways.', 'Restriction': '' } Annotation.CustomLoop.run(parameters, custom_algorithm) # here, the optional edges need to be entered in the form of [('A','B'), ...], must be identical to the one above for crosstalk in [('Sora', 'Raf'), ('Sora', 'EGFR'), ('Sora', 'IGFR'), ('EGFR', 'PI3K'), ('PI3K', 'Raf'), ('Erk', 'mTor'), ('mTor', 'IGFR')]: parameters = { 'Db_name': DBNAME, 'Restriction': '', 'Property_name': 'Ct_%s_%s' % crosstalk, 'Specification': 'Observable(%s,%s,1)' % crosstalk, 'Description': 'Determines whether the crosstalk "%s,%s" is observable.' % crosstalk } Annotation.Predicate.run(parameters) if analyse_classes: # this function performs the classification parameters = { 'Db_name': DBNAME, 'Properties': CLASSES, 'Restriction': RESTRICTION } if export_csv: parameters['FileName'] = FNAMECSV Analysis.Classes.run(parameters)
def run(Parameters): for key in Parameters: if not key in keywords: print ' ** Unknown parameter: "%s"' % key print ' Parameters must belong to:', ','.join(keywords) raise Exception Db_name = Parameters['Db_name'] Properties = Parameters['Properties'] Restriction = Parameters['Restriction'] db = Database.Interface(Db_name) selected = db.count(Restriction) print print '---Analysis of property classes' if not selected: print 'No parametrizations selected.' db.close() return if not Properties: Properties = list(db.property_names) if not Properties: print "No properties in DB '" + Db_name + "'", "please add annotations." db.close() return if Restriction: print 'Restriction: ', "'" + Restriction + "'" print 'Models selected: ', selected, '/', db.size print 'Properties selected: ', ','.join([n for n in Properties]) print 'Label coverage' for prop in Properties: sql = prop + ' IS NOT NULL' if Restriction: sql += ' AND ' + Restriction count = db.count(sql) print '%s %i (%2.1f%%)' % ( (' ' + prop + ':').ljust(19), count, 100. * count / selected) table = [] table.append(tuple(Properties[:] + ['Size', ''])) width = max([len(str(t)) for row in table for t in row]) sql = 'SELECT DISTINCT ' + ','.join(Properties) + ' FROM Parametrizations' if Restriction: sql += ' WHERE ' + Restriction db.cur.execute(sql) classes = [] for row in db.cur: classes.append([(p, row[p]) for p in Properties]) for Class in classes: table_row = [] sqls = [] for p, value in Class: width = max([len(str(value)), width]) if value == None: sqls.append(p + ' IS NULL') table_row.append('-') else: sqls.append(p + '="' + str(value) + '"') table_row.append(str(value)) sql = ' and '.join(sqls) size = db.count(sql) table_row.append(size) table_row.append('%2.1f%%' % (100. * size / selected)) table.append(tuple(table_row)) width = max([len(str(size)), width]) db.close() if 'FileName' in Parameters: with open(Parameters['FileName'], 'w') as f: writer = csv.writer(f) writer.writerows(table) print 'created', Parameters['FileName'] return key_func = lambda x: int(x[-1].split('.')[0]) table = [table[0]] + sorted(table[1:], key=key_func, reverse=True) print print 'Classes' for row in table: for value in row: print str(value).ljust(width), print
def run(Parameters): Db_name = Parameters['Db_name'] Interactions = Parameters['Interactions'] Restriction = Parameters['Restriction'] db = Database.Interface(Db_name) Model = db.get_model() if not Interactions: Interactions = Model.interactions print print 'Annotation by interaction signs' print 'Restriction: ', "'" + Restriction + "'" print 'Interactions: ', Interactions Properties = [] cps = Parser.Interface(Model) for a, b, ts in Interactions: for t in ts: Property_type = 'text' if len(ts) == 1: Property_name = 'sign_%s_%s' % (a, b) else: Property_name = 'sign_%s_%s_%i' % (a, b, t) Properties.append(Property_name) if Property_name in db.property_names: print 'Property', Property_name, 'is reset.' db.reset_column(Property_name) else: db.add_column(Property_name, 'TEXT', 'Sign of %s %i %s' % (a, t, b)) annotation_condition = Property_name + ' IS NULL' if Restriction: annotation_condition += ' and ' + Restriction cps.parse('ActivatingOnly(%s,%s,%i)' % (a, b, t)) sql = cps.toSQL() db.set_labels(annotation_condition + ' and ' + sql, {Property_name: '"+"'}) cps.parse('InhibitingOnly(%s,%s,%i)' % (a, b, t)) sql = cps.toSQL() db.set_labels(annotation_condition + ' and ' + sql, {Property_name: '"-"'}) cps.parse('NotObservable(%s,%s,%i)' % (a, b, t)) sql = cps.toSQL() db.set_labels(annotation_condition + ' and ' + sql, {Property_name: '"None"'}) cps.parse('Activating(%s,%s,%i) and Inhibiting(%s,%s,%i)' % (a, b, t, a, b, t)) sql = cps.toSQL() db.set_labels(annotation_condition + ' and ' + sql, {Property_name: '"+-"'}) selected = db.count(Restriction) for prop in Properties: sql = prop + ' IS NOT NULL' count = db.count(sql) print '%s %i (%2.1f%%)' % ( (' ' + prop + ':').ljust(19), count, 100. * count / selected) db.close()