def poll_events(): event_list = [] for h in handlers: event_list.extend(h.controller.log) h.controller.log = [] ship_output = {} bullet_output = {} for e in event_list: if e[0] == 'ship': if not ship_output.has_key('normal'): ship_output['normal'] = [] ship_output['normal'].append((Serialize.serializeShip(e[1]), e[2], e[3], e[4], e[5])) elif e[0] == 'bullet': if not bullet_output.has_key('normal'): bullet_output['normal'] = [] bullet_output['normal'].append((Serialize.serializeBullet(e[1]), e[2])) for e in event_log.ship_deaths: if not ship_output.has_key('death'): ship_output['death'] = [] ship_output['death'].append((Serialize.serializeShip(e[0]), e[1], False, False, False)) event_log.ship_deaths = [] for e in event_log.ship_reflects: if not ship_output.has_key('reflect'): ship_output['reflect'] = [] ship_output['reflect'].append((Serialize.serializeShip(e[0]), e[2])) ship_output['reflect'].append((Serialize.serializeShip(e[1]), e[2])) event_log.ship_reflects = [] for e in event_log.wall_reflects: if not ship_output.has_key('reflect'): ship_output['reflect'] = [] ship_output['reflect'].append((Serialize.serializeShip(e[0]), e[2])) event_log.wall_reflects = [] for e in event_log.bullet_deaths: if not bullet_output.has_key('death'): bullet_output['death'] = [] bullet_output['death'].append((Serialize.serializeBullet(e[0]), Serialize.serializeRect(e[1]), e[2])) event_log.bullet_deaths = [] for e in event_log.bullet_timeouts: if not bullet_output.has_key('timeout'): bullet_output['timeout'] = [] bullet_output['timeout'].append((Serialize.serializeBullet(e[0]), e[1])) event_log.bullet_timeouts = [] full_output = {} if len(ship_output)>0: full_output['ship'] = ship_output if len(bullet_output)>0: full_output['bullet'] = bullet_output if len(full_output)>0: msg = { 'update' : full_output } for h in handlers: h.do_send(msg)
def save(self): """ Save information about library in text file. Args: filename(str): Set name of the file which is used to upload information about library. """ specifier = "wb" if self.serialization_type == srz.pickle_type else "w" with open(self.filename, specifier) as target_file: srz.save([self.__users_list, self.__books_list], target_file, self.serialization_type) last_session_data_save(self.serialization_type)
def on_open(self): # Grouped together to handle multiple players (new connection) player_ship = Ship((320, 240), (15, 15), SHOOT_DELAY, SPEED, VELOCITY_CAP, ANGULAR_VELOCITY, random_respawn(min_respawn, max_respawn)) logic.ship_list.append(player_ship) self.controller = ServerSideController(player_ship, logic, BULLET_SIZE, BULLET_SPEED, BULLET_DURATION, SHOOT_DELAY, SHIELD_SIZE) logic.onLogicUpdate += self.controller.update self.do_send({ 'start': { 'walls': [Serialize.serializeRect(wall) for wall in logic.wall_list], 'ticks': TICKS, 'speed': SPEED, 'bspeed': BULLET_SPEED, 'maxvelo': VELOCITY_CAP, 'angular': ANGULAR_VELOCITY, 'current': logic.current_tick, 'id': player_ship.id } }) #logic.onLogicUpdate+=self.onLogicUpdate handlers.append(self)
def fit_p(): read_positions_fn = '/home/jah/projects/arlen/experiments/ingolia_science/mRNA-rich-1/results/mRNA-rich-1_read_positions.txt' #read_positions_fn = '/home/jah/projects/arlen/experiments/ingolia_science/mRNA-rich-2/results/mRNA-rich-2_read_positions.txt' #read_positions_fn = '/home/jah/projects/arlen/experiments/nagalakshmi_science/RH_ori/results/RH_ori_read_positions.txt' genes = Serialize.read_file(read_positions_fn, 'read_positions') min_length = 5000 p_lsq = leastsq(residuals, 7.8e-5, args=(genes, min_length), full_output=True) print p_lsq return p_lsq
def total_counts_given_p(): mRNA_experiments = [ ('Ingolia_mRNA_1', '/home/jah/projects/arlen/experiments/ingolia_science/mRNA-rich-1/results/mRNA-rich-1_read_positions.txt'), #('Ingolia_mRNA_2', '/home/jah/projects/arlen/experiments/ingolia_science/mRNA-rich-2/results/mRNA-rich-2_read_positions.txt'), #('Nagalakshmi_RH_ori', '/home/jah/projects/arlen/experiments/nagalakshmi_science/RH_ori/results/RH_ori_read_positions.txt'), #('Nagalakshmi_RH_bio', '/home/jah/projects/arlen/experiments/nagalakshmi_science/RH_bio/results/RH_bio_read_positions.txt'), #('Nagalakshmi_dT_ori', '/home/jah/projects/arlen/experiments/nagalakshmi_science/dT_ori/results/dT_ori_read_positions.txt'), #('Nagalakshmi_dT_bio', '/home/jah/projects/arlen/experiments/nagalakshmi_science/dT_bio/results/dT_bio_read_positions.txt'), ] experiments = [(name, counts_from_genes(Serialize.read_file(fn, 'read_positions'))) for name, fn in mRNA_experiments] min_length = 0000 max_length = 10000 plot_to = 2000 fig_cumulative, ax_cumulative = plt.subplots() xs = np.arange(0, -plot_to, -1) for name, counts_generator in experiments: print name total_uniform_counts = np.zeros(100000) total_geometric_counts = np.zeros(100000) total_actual_counts = np.zeros(100000) for counts in counts_generator: l_g = len(counts) if not (min_length < l_g < max_length): continue r_g = counts.sum() uniform_counts = np.ones(l_g) / l_g * r_g # Some weirdness about whether to include 0 or not in make_P_distribution #geometric_counts = make_P_distribution(l_g, 4e-4)[1:] * r_g geometric_counts = make_P_distribution(l_g, 7.8e-5)[1:] * r_g #geometric_counts = make_P_distribution(l_g, 4.6e-5)[1:] * r_g counts = counts[::-1] total_actual_counts[:l_g] += counts total_uniform_counts[:l_g] += uniform_counts total_geometric_counts[:l_g] += geometric_counts print total_actual_counts.sum() print total_uniform_counts.sum() print total_geometric_counts.sum() ax_cumulative.plot(xs, smoothed(total_actual_counts[:plot_to], 5), '-', label=name + '_actual_smoothed') ax_cumulative.plot(xs, total_uniform_counts[:plot_to], '-', linewidth=2, label=name + '_uniform') ax_cumulative.plot(xs, total_geometric_counts[:plot_to], '-', linewidth=2, label=name + '_geometric') ax_cumulative.legend() xlabel = 'Position relative to end' ax_cumulative.set_xlabel(xlabel) ax_cumulative.set_ylabel('Mapped read counts')
def counts_from_read_positions_fn(read_positions_fn, from_end): gene_infos = Serialize.read_file(read_positions_fn, 'read_positions') for gene_name in gene_infos: #if gene_name == 'YLR256W': # continue if from_end: counts = gene_infos[gene_name]['all'].relative_to_end else: counts = gene_infos[gene_name]['all'] yield gene_name, counts
def on_open(self): # Grouped together to handle multiple players (new connection) player_ship = Ship((320, 240), (15, 15), SHOOT_DELAY, SPEED, VELOCITY_CAP, ANGULAR_VELOCITY, random_respawn(min_respawn, max_respawn)) logic.ship_list.append(player_ship) self.controller = ServerSideController(player_ship, logic, BULLET_SIZE, BULLET_SPEED, BULLET_DURATION, SHOOT_DELAY, SHIELD_SIZE) logic.onLogicUpdate+=self.controller.update self.do_send({'start': { 'walls': [Serialize.serializeRect(wall) for wall in logic.wall_list], 'ticks': TICKS, 'speed' : SPEED, 'bspeed' : BULLET_SPEED, 'maxvelo' : VELOCITY_CAP, 'angular' : ANGULAR_VELOCITY, 'current' : logic.current_tick, 'id' : player_ship.id}}) #logic.onLogicUpdate+=self.onLogicUpdate handlers.append(self)
def load(self): """ Load information about library users and books Args: filename(str): Set name of the file which is used to upload information about library. """ load_type = last_session_save_type() specifier = "rb" if load_type == srz.pickle_type else "r" try: with open(self.filename, specifier) as source: self.__users_list, self.__books_list = srz.load( source, load_type) except OSError: self.__users_list = [] self.__books_list = []
def work(): modellist = [] for item in Serialize.Reader().deserialized: model = Model.Model(item) modellist.append(model) return modellist
def poll_events(): event_list = [] for h in handlers: event_list.extend(h.controller.log) h.controller.log = [] ship_output = {} bullet_output = {} for e in event_list: if e[0] == 'ship': if not ship_output.has_key('normal'): ship_output['normal'] = [] ship_output['normal'].append( (Serialize.serializeShip(e[1]), e[2], e[3], e[4], e[5])) elif e[0] == 'bullet': if not bullet_output.has_key('normal'): bullet_output['normal'] = [] bullet_output['normal'].append( (Serialize.serializeBullet(e[1]), e[2])) for e in event_log.ship_deaths: if not ship_output.has_key('death'): ship_output['death'] = [] ship_output['death'].append( (Serialize.serializeShip(e[0]), e[1], False, False, False)) event_log.ship_deaths = [] for e in event_log.ship_reflects: if not ship_output.has_key('reflect'): ship_output['reflect'] = [] ship_output['reflect'].append((Serialize.serializeShip(e[0]), e[2])) ship_output['reflect'].append((Serialize.serializeShip(e[1]), e[2])) event_log.ship_reflects = [] for e in event_log.wall_reflects: if not ship_output.has_key('reflect'): ship_output['reflect'] = [] ship_output['reflect'].append((Serialize.serializeShip(e[0]), e[2])) event_log.wall_reflects = [] for e in event_log.bullet_deaths: if not bullet_output.has_key('death'): bullet_output['death'] = [] bullet_output['death'].append((Serialize.serializeBullet(e[0]), Serialize.serializeRect(e[1]), e[2])) event_log.bullet_deaths = [] for e in event_log.bullet_timeouts: if not bullet_output.has_key('timeout'): bullet_output['timeout'] = [] bullet_output['timeout'].append( (Serialize.serializeBullet(e[0]), e[1])) event_log.bullet_timeouts = [] full_output = {} if len(ship_output) > 0: full_output['ship'] = ship_output if len(bullet_output) > 0: full_output['bullet'] = bullet_output if len(full_output) > 0: msg = {'update': full_output} for h in handlers: h.do_send(msg)
def HTTP_request(): global option, threads_list, max_threads, delay, os, dt threads_list = [] requests = file_string.split('<item>') requests.pop(0) payloadstype = option PayloadGenerator.setType(option) payloadslist = PayloadGenerator.payloadslist(option) for request in requests: path = find_between(request, '<url><![CDATA[', ']]></url>') raw_request = find_between(request, '"false"><![CDATA[', ']]></request>') raw_header, data = raw_request.split('\r\n\r\n', 1) lines = raw_header.split('\r\n') method = '' if 'POST' in lines[0]: method = 'POST' else: if 'GET' in lines[0]: method = 'GET' headers = {} i = 1 while i < len(lines): info = lines[i].split(': ', 1) if 'Content-Length' not in info[0]: headers.update({info[0]: info[1]}) i = i + 1 try: if method == 'POST': original_request = post_call(path, data, headers) if 'multipart/form-data' in headers.get('Content-Type'): boundaries = data.split('\n\n') if payloadstype == 'pp': ParameterPollution.multi_post_call(path, headers, payloadslist, boundaries, original_request) if payloadstype == 'si': SOAPInjection.multi_post_call(path, headers, payloadslist, boundaries, original_request) if payloadstype == 'ti': TemplateInjection.multi_post_call(path, headers, payloadslist, boundaries, original_request) if payloadstype == 'sr': Serialize.multi_post_call(path, headers, payloadslist, boundaries, original_request) if payloadstype == 'op': OraclePadding.multi_post_call(path, headers, payloadslist, boundaries, original_request) if payloadstype == 'xxe': XXE.multi_post_call(path, headers, payloadslist, boundaries, original_request) else: post_params = data.split('&') if payloadstype == 'pp': ParameterPollution.common_post_call(path, headers, payloadslist, post_params, original_request) if payloadstype == 'si': SOAPInjection.common_post_call(path, headers, payloadslist, post_params, original_request) if payloadstype == 'ti': TemplateInjection.common_post_call(path, headers, payloadslist, post_params, original_request) if payloadstype == 'sr': Serialize.common_post_call(path, headers, payloadslist, post_params, original_request) if payloadstype == 'op': OraclePadding.common_post_call(path, headers, payloadslist, post_params, original_request) if payloadstype == 'xxe': XXE.common_post_call(path, headers, payloadslist, post_params, original_request) if method == 'GET': if '?' in path: original_request = get_call(path, headers) if payloadstype == 'pp': ParameterPollution.get_call(path, headers, data, payloadslist, original_request) if payloadstype == 'si': SOAPInjection.get_call(path, headers, data, payloadslist, original_request) if payloadstype == 'ti': TemplateInjection.get_call(path, headers, data, payloadslist, original_request) if payloadstype == 'sr': Serialize.get_call(path, headers, data, payloadslist, original_request) if payloadstype == 'op': OraclePadding.get_call(path, headers, data, payloadslist, original_request) if payloadstype == 'xxe': XXE.get_call(path, headers, data, payloadslist, original_request) else: #no params to test pass except urllib2.HTTPError as err: print err
def total_counts_given_p(): mRNA_experiments = [ ('Ingolia_mRNA_1', '/home/jah/projects/arlen/experiments/ingolia_science/mRNA-rich-1/results/mRNA-rich-1_read_positions.txt' ), #('Ingolia_mRNA_2', '/home/jah/projects/arlen/experiments/ingolia_science/mRNA-rich-2/results/mRNA-rich-2_read_positions.txt'), #('Nagalakshmi_RH_ori', '/home/jah/projects/arlen/experiments/nagalakshmi_science/RH_ori/results/RH_ori_read_positions.txt'), #('Nagalakshmi_RH_bio', '/home/jah/projects/arlen/experiments/nagalakshmi_science/RH_bio/results/RH_bio_read_positions.txt'), #('Nagalakshmi_dT_ori', '/home/jah/projects/arlen/experiments/nagalakshmi_science/dT_ori/results/dT_ori_read_positions.txt'), #('Nagalakshmi_dT_bio', '/home/jah/projects/arlen/experiments/nagalakshmi_science/dT_bio/results/dT_bio_read_positions.txt'), ] experiments = [ (name, counts_from_genes(Serialize.read_file(fn, 'read_positions'))) for name, fn in mRNA_experiments ] min_length = 0000 max_length = 10000 plot_to = 2000 fig_cumulative, ax_cumulative = plt.subplots() xs = np.arange(0, -plot_to, -1) for name, counts_generator in experiments: print name total_uniform_counts = np.zeros(100000) total_geometric_counts = np.zeros(100000) total_actual_counts = np.zeros(100000) for counts in counts_generator: l_g = len(counts) if not (min_length < l_g < max_length): continue r_g = counts.sum() uniform_counts = np.ones(l_g) / l_g * r_g # Some weirdness about whether to include 0 or not in make_P_distribution #geometric_counts = make_P_distribution(l_g, 4e-4)[1:] * r_g geometric_counts = make_P_distribution(l_g, 7.8e-5)[1:] * r_g #geometric_counts = make_P_distribution(l_g, 4.6e-5)[1:] * r_g counts = counts[::-1] total_actual_counts[:l_g] += counts total_uniform_counts[:l_g] += uniform_counts total_geometric_counts[:l_g] += geometric_counts print total_actual_counts.sum() print total_uniform_counts.sum() print total_geometric_counts.sum() ax_cumulative.plot(xs, smoothed(total_actual_counts[:plot_to], 5), '-', label=name + '_actual_smoothed') ax_cumulative.plot(xs, total_uniform_counts[:plot_to], '-', linewidth=2, label=name + '_uniform') ax_cumulative.plot(xs, total_geometric_counts[:plot_to], '-', linewidth=2, label=name + '_geometric') ax_cumulative.legend() xlabel = 'Position relative to end' ax_cumulative.set_xlabel(xlabel) ax_cumulative.set_ylabel('Mapped read counts')
def on_msg(self, msg): if 'start' in msg: global SERVER_TICKS, SPEED, BULLET_SPEED, VELOCITY_CAP, ANGULAR_VELOCITY, current SERVER_TICKS = msg['start']['ticks'] SPEED = msg['start']['speed'] BULLET_SPEED = msg['start']['bspeed'] VELOCITY_CAP = msg['start']['maxvelo'] ANGULAR_VELOCITY = msg['start']['angular'] server_current = current = msg['start']['current'] self.ship_id = msg['start']['id'] for wall in msg['start']['walls']: self.view.wall_list.append(Serialize.deserializeRect(wall)) elif 'update' in msg: msginput = msg['update'] if 'ship' in msginput: if 'normal' in msginput['ship']: for n in msginput['ship']['normal']: ship = Serialize.deserializeShip(n[0]) isMoving = n[2] isLefting = n[3] isRighting = n[4] if ship.id in ship_dict: found_ship = ship_dict[ship.id] found_ship.__dict__ = ship.__dict__.copy() else: ship_dict[ship.id] = ship self.view.ship_list.append(ship) flags_dict[ship.id] = (isMoving, isLefting, isRighting) if 'death' in msginput['ship']: for n in msginput['ship']['death']: ship = Serialize.deserializeShip(n[0]) isMoving = n[2] isLefting = n[3] isRighting = n[4] if ship.id in ship_dict: found_ship = ship_dict[ship.id] found_ship.__dict__ = ship.__dict__.copy() else: ship_dict[ship.id] = ship self.view.ship_list.append(ship) flags_dict[ship.id] = (isMoving, isLefting, isRighting) self.controller.onShipDeath.fire(ship) if 'reflect' in msginput['ship']: for n in msginput['ship']['reflect']: ship = Serialize.deserializeShip(n[0]) if ship.id in ship_dict: found_ship = ship_dict[ship.id] found_ship.__dict__ = ship.__dict__.copy() else: ship_dict[ship.id] = ship self.view.ship_list.append(ship) if 'bullet' in msginput: if 'normal' in msginput['bullet']: for n in msginput['bullet']['normal']: bullet = Serialize.deserializeBullet(n[0]) if bullet.id in bullet_dict: found_bullet = bullet_dict[bullet.id] found_bullet.__dict__ = bullet.__dict__.copy() else: bullet_dict[bullet.id] = bullet self.view.bullet_list.append(bullet) if 'death' in msginput['bullet']: for n in msginput['bullet']['death']: bullet = Serialize.deserializeBullet(n[0]) wall = Serialize.deserializeRect(n[1]) self.controller.onBulletDeath.fire(bullet, wall) if 'timeout' in msginput['bullet']: for n in msginput['bullet']['timeout']: bullet = Serialize.deserializeBullet(n[0]) if bullet.id in bullet_dict: self.view.bullet_list.remove( bullet_dict[bullet.id]) del bullet_dict[bullet.id]
def test_json(self): """ test for serialization with json """ output = json.dumps(self.data, default=jns.js_default) self.output = StringIO(output) users, books = srz.load(self.output, 'json') self.assertEqual(self.data, [users, books])
def on_msg(self, msg): if 'start' in msg: global SERVER_TICKS, SPEED, BULLET_SPEED, VELOCITY_CAP, ANGULAR_VELOCITY, current SERVER_TICKS = msg['start']['ticks'] SPEED = msg['start']['speed'] BULLET_SPEED = msg['start']['bspeed'] VELOCITY_CAP = msg['start']['maxvelo'] ANGULAR_VELOCITY = msg['start']['angular'] server_current = current = msg['start']['current'] self.ship_id = msg['start']['id'] for wall in msg['start']['walls']: self.view.wall_list.append(Serialize.deserializeRect(wall)) elif 'update' in msg: msginput = msg['update'] if 'ship' in msginput: if 'normal' in msginput['ship']: for n in msginput['ship']['normal']: ship = Serialize.deserializeShip(n[0]) isMoving = n[2] isLefting = n[3] isRighting = n[4] if ship.id in ship_dict: found_ship = ship_dict[ship.id] found_ship.__dict__ = ship.__dict__.copy() else: ship_dict[ship.id] = ship self.view.ship_list.append(ship) flags_dict[ship.id] = (isMoving, isLefting, isRighting) if 'death' in msginput['ship']: for n in msginput['ship']['death']: ship = Serialize.deserializeShip(n[0]) isMoving = n[2] isLefting = n[3] isRighting = n[4] if ship.id in ship_dict: found_ship = ship_dict[ship.id] found_ship.__dict__ = ship.__dict__.copy() else: ship_dict[ship.id] = ship self.view.ship_list.append(ship) flags_dict[ship.id] = (isMoving, isLefting, isRighting) self.controller.onShipDeath.fire(ship) if 'reflect' in msginput['ship']: for n in msginput['ship']['reflect']: ship = Serialize.deserializeShip(n[0]) if ship.id in ship_dict: found_ship = ship_dict[ship.id] found_ship.__dict__ = ship.__dict__.copy() else: ship_dict[ship.id] = ship self.view.ship_list.append(ship) if 'bullet' in msginput: if 'normal' in msginput['bullet']: for n in msginput['bullet']['normal']: bullet = Serialize.deserializeBullet(n[0]) if bullet.id in bullet_dict: found_bullet = bullet_dict[bullet.id] found_bullet.__dict__ = bullet.__dict__.copy() else: bullet_dict[bullet.id] = bullet self.view.bullet_list.append(bullet) if 'death' in msginput['bullet']: for n in msginput['bullet']['death']: bullet = Serialize.deserializeBullet(n[0]) wall = Serialize.deserializeRect(n[1]) self.controller.onBulletDeath.fire(bullet, wall) if 'timeout' in msginput['bullet']: for n in msginput['bullet']['timeout']: bullet = Serialize.deserializeBullet(n[0]) if bullet.id in bullet_dict: self.view.bullet_list.remove(bullet_dict[bullet.id]) del bullet_dict[bullet.id]