Convert beagle to TPED user Kantale

From PyPedia
Jump to: navigation, search

Contents

[edit] Documentation

Convert from beagle to plink's TPED and TFAM.

[edit] Parameters

<inputs>
</inputs>


[edit] Return

[edit] See also

[edit] Code

def Convert_beagle_to_TPED_user_Kantale(
	input_beagle_filename = None,
	input_markers_filename = None,
	output_TPED_filename = None,
	output_TFAM_filename = None,
	chromosome = None,
):

	output_TPED_file = open(output_TPED_filename, "w")
	output_TFAM_file = open(output_TFAM_filename, "w")
	input_markers_file = open(input_markers_filename)
	chromosome = str(chromosome)

	lc = 0
	for line in open(input_beagle_filename):
		ls = line.replace("\n", "").split()

		if ls[0] == "I":
			samples = [ls[2+x] for x in range(len(ls[2:])) if x % 2 == 0]
			output_TFAM_file.write(str.join("\n", [str.join(" ", [s, s, "0", "0", "0", "1"]) for s in samples]) + "\n")
			continue

		if ls[0] == "M":
			lc += 1
			if lc % 10000 == 0:
				print "Lines: ", lc
			markers_line = input_markers_file.readline()
			if not markers_line:
				raise Exception("Markers file has fewer file than beagle")

			markers_ls = markers_line.replace("\n", "").split()

			tped_line = [chromosome, markers_ls[0], "0", markers_ls[1]] + ls[2:]
			output_TPED_file.write(str.join(" ", tped_line) + "\n")


	output_TPED_file.close()
	output_TFAM_file.close()

[edit] Unit Tests

def uni1():
	return True

[edit] Development Code

def Convert_beagle_to_TPED_user_Kantale():
	pass

[edit] Permissions

[edit] Documentation Permissions

Kantale

[edit] Code Permissions

Kantale

[edit] Unit Tests Permissions

Kantale

[edit] Permissions Permissions

Kantale

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox