コード例 #1
0
def biosystem_update_cache(biosystem, record):
    """
    This function will check and update the biosystem
    :param record - The record of simulation  :
    """
    # Auto cache size control.
    if not os.path.exists("../cache"):
        os.mkdir("../cache")
    # There may be IO-async Error, rare but once happened
    try:
        cache_files = os.listdir('../cache')
        dir_size = sum(map(os.path.getsize, cache_files))
        cache_files_size = map(os.path.getsize, cache_files)
        sdict = dict([[cache_files[i], cache_files_size[i]] for i in range(len(cache_files))])
        if DEBUG:
            print debug_info('size of cache'), dir_size
        cache_files.sort(cache_files, key=lambda x:sdict[x])
        while dir_size > 100 * 1000 * 1000:
            os.remove(cache_files[0])
            del cache_files[0]
    except OSError:
        pass
    # our algorithm
    network_hash = BioSystemNetwork(biosystem).network_hash
    f_name = '../cache/%d.json' % network_hash
    if not os.path.exists(f_name):
        fp = open(f_name, 'w+')
        json.dump(record, fp)
        fp.close()
コード例 #2
0
def compare_biosystem(biosystem1, biosystem2):
    """
    Compare two biosystem. If same return True otherwise False
    """
    if biosystem1['system_parameter']['time'] != biosystem2['system_parameter']['time']:
        return False
    list1, list2 = map(hash_gates_and_simulation, (biosystem1, biosystem2))
    if DEBUG:
        print debug_info(), list1, list2
    if sorted(list1) != sorted(list2):
        return False
    net1, net2 = map(BioSystemNetwork, (biosystem1, biosystem2))
    return sorted(net1.reaction_lines_hash) == sorted(net2.reaction_lines_hash)
コード例 #3
0
 def __init__(self, biosystem):
     self.vertex = self.reconstruct_arcs(biosystem)
     if DEBUG:
         print debug_info('reconstructed_arcs'), self.vertex
     self.reaction_lines = []
     self.resolve_biosystem_net(self.vertex)
     if DEBUG:
         print debug_info('BioNetwork_lines'), self.reaction_lines
     self.reaction_lines_hash = hash_list(self.reaction_lines)
     if DEBUG:
         print debug_info('BioNetwork_lines_hash'), self.reaction_lines_hash
     self.network_hash = hash(dump_ord(sorted(self.reaction_lines_hash))) + biosystem['system_parameter']['time']
     if DEBUG:
         print debug_info('BioNetwork_hash'), self.network_hash
コード例 #4
0
 def test_reaction(self):
     print debug_info('Test self')
     print hash_list([{'a': 43.5}, {46: '77y'}, {65.6: 7}])
     hash_string_list(['zhang hao', 'cuitianyi', 'zhuangsiyuan'])
     self.assertEqual(hash_dict({1: 2, 3: 4}), hash_dict({3: 4, 1: 2}))