예제 #1
0
def write_block(out, line, phase):
	fields = line.strip().split()
	metadata = parse_metadata(fields[3])
	metadata['TR'] = 0.992 # empirical average

	out.write('\t'.join(fields[0:3]))
	out.write('\t' + metadata_to_str(metadata))

	for f in fields[4:]:
		fi = f.split(':')

		pos = int(fi[0])
		p0 = (int(fi[1]) + phase) % 2
		p1 = (int(fi[2]) + phase) % 2

		out.write('\t%d:%d:%d' % (pos, p0, p1))

	out.write('\n')
예제 #2
0
		fields = line.split()
		chrom = fields[0]
		pos = int(fields[1])
		ph = int(fields[2])

		true_phase[(chrom, pos)] = ph

num_switches = 0
num_long_switches = 0
num_transitions = 0
with open(args.blocks) as blocks:
	for line in blocks:
		pattern = ""
		fields = line.split()
		chrom = fields[0]
		md = parse_metadata(fields[3])

		for f in fields[4:]:
			fi = f.split(':')
			pos = int(fi[0])
			p0 = int(fi[1])

			if (chrom, pos) in true_phase:
				pattern += str(int(p0 == true_phase[(chrom, pos)]))

		# print md['ID'], '\t', pattern

		if len(pattern) > 1:
			corrected_pattern = correct_pattern(pattern)
			num_block_switches = sum([1 for i in xrange(1,len(pattern)) if pattern[i] != pattern[i-1]])
			num_long_block_switches = sum([1 for i in xrange(1,len(corrected_pattern))