From 729eca9eee9fa23657df13ae60e95e3bc8914636 Mon Sep 17 00:00:00 2001 From: Neha Rao Date: Fri, 6 Dec 2024 02:48:19 -0500 Subject: [PATCH] Update RA_pcs.py --- RA_pcs.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 RA_pcs.py diff --git a/RA_pcs.py b/RA_pcs.py new file mode 100644 index 0000000..0bcf4f2 --- /dev/null +++ b/RA_pcs.py @@ -0,0 +1,28 @@ +# Python code to obtain RA_pcs.txt from ra_pruned.evec + +# Read the input file +input_file = "ra_pruned.evec" +output_file = "RA_pcs.txt" + +with open(input_file, 'r') as f: + lines = f.readlines() + +# Remove the first line +lines.pop(0) + +# Split the first column into two columns and remove the last column +formatted_lines = [] +for line in lines: + split_line = line.split() + split_column = split_line[0].split(":") + formatted_line = split_column + split_line[1:-1] + formatted_lines.append(formatted_line) + +# Add header with consistent spacing +header = "FID IID PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 PC9 PC10\n" + +# Write to the output file +with open(output_file, 'w') as f: + f.write(header) + for line in formatted_lines[1:]: + f.write(' '.join(line) + '\n')