10
|
1 import sys
|
|
2
|
11
|
3 def identify_variants_with_genes(input_file_path, output_file_path, simple_name):
|
10
|
4 # Define the genes of interest
|
|
5 genes_of_interest = ['LMO0737', 'ORF2110', 'ORF2819']
|
|
6
|
|
7 # Open the input file and read its lines
|
|
8 with open(input_file_path, 'r') as file:
|
|
9 lines = file.readlines()
|
|
10
|
|
11 # Check if the file has more than just the header
|
|
12 if len(lines) <= 1:
|
|
13 print("Input file does not contain enough data.")
|
|
14 return
|
|
15
|
|
16 # Extract the column headers and find the indices of the genes of interest
|
|
17 headers = lines[0].strip().split('\t')
|
|
18 gene_indices = [headers.index(gene) for gene in genes_of_interest]
|
|
19 serotype_index = headers.index('SEROTYPE')
|
|
20
|
11
|
21 # Modify the header to include the new first column
|
|
22 modified_header = f"FileName\t{lines[0]}"
|
|
23
|
|
24 # Initialize a list to hold the modified lines, starting with the modified header
|
|
25 modified_lines = [modified_header]
|
10
|
26
|
|
27 # Process each data line in the input file
|
|
28 for line in lines[1:]:
|
|
29 data = line.strip().split('\t')
|
|
30 # Check if the genes of interest are all present (marked as "FULL")
|
|
31 if all(data[index] == 'FULL' for index in gene_indices):
|
|
32 # Modify the SEROTYPE column to "4b variant"
|
|
33 data[serotype_index] = "4b variant"
|
11
|
34 # Prepend the simple name to the line
|
|
35 modified_line = f"{simple_name}\t" + '\t'.join(data) + '\n'
|
|
36 # Add the modified line to the list
|
|
37 modified_lines.append(modified_line)
|
10
|
38
|
|
39 # Write the modified lines to the output file
|
|
40 with open(output_file_path, 'w') as file:
|
|
41 file.writelines(modified_lines)
|
|
42
|
|
43 print(f'Results written to {output_file_path}')
|
|
44
|
|
45 if __name__ == "__main__":
|
11
|
46 if len(sys.argv) != 4:
|
|
47 print("Usage: python script.py <input_file_path> <output_file_path> <simple_name>")
|
10
|
48 sys.exit(1)
|
|
49
|
|
50 input_file_path = sys.argv[1]
|
|
51 output_file_path = sys.argv[2]
|
11
|
52 simple_name = sys.argv[3]
|
|
53 identify_variants_with_genes(input_file_path, output_file_path, simple_name)
|
10
|
54
|