-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore_alignment.py
More file actions
33 lines (25 loc) · 1.04 KB
/
core_alignment.py
File metadata and controls
33 lines (25 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import argparse
import pandas as pd
def calculate_aligned_percentage(input_file, output_file):
# Read tab-separated file
df = pd.read_csv(input_file, sep='\s+')
# Calculate %_Aligned
df['%_Aligned'] = (df['ALIGNED'] / df['LENGTH']) * 100
# Round to 2 decimal places
df['%_Aligned'] = df['%_Aligned'].round(2)
# Save to output file
df.to_csv(output_file, sep='\t', index=False)
def main():
# Set up argument parser
parser = argparse.ArgumentParser(description='Calculate percentage of aligned sequences')
parser.add_argument('-i', '--input', required=True, help='Input core.txt file')
parser.add_argument('-o', '--output', default='core_aligned.txt', help='Output file name (default: core_aligned.txt)')
# Parse arguments
args = parser.parse_args()
try:
calculate_aligned_percentage(args.input, args.output)
print(f"Analysis complete. Results written to {args.output}")
except Exception as e:
print(f"Error: {e}")
if __name__ == '__main__':
main()