-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateInput.py
More file actions
36 lines (29 loc) · 1.42 KB
/
createInput.py
File metadata and controls
36 lines (29 loc) · 1.42 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
34
35
36
#Automatically creates input file to store and read Brief Access Task (BAT) data
import os
#Example of file name 0702TG25_pre.ms8.txt
# Function to extract information from the file name
def extract_info(file_name):
# Split the file name by underscore and period
parts = file_name.split('_')
date = "2024/" + parts[0][:2] + "/" + parts[0][2:4] # Extract date (switch year if necessary)
animal = parts[0][4:] # Extract animal identifier
condition, notes = "B" if "pre" in parts[1] else "A", "pre" if "pre" in parts[1] else "post" # Extract condition and notes
return animal, date, condition, notes
# Directory containing the files
directory = "/home/thomas/Desktop/Isaac/Ortho/Ortho" #rewrite to be your directory
# List to store the file information
file_info_list = []
# Iterate over files in the directory
for file_name in os.listdir(directory):
if file_name.endswith(".txt"):
animal, date, condition, notes = extract_info(file_name)
file_info_list.append((animal, date, condition, notes))
# Write the file information to a text file
output_file = "/home/thomas/Desktop/Isaac/Ortho/Ortho/input_file/stink_inputfile.txt" #rewrite to be your directory
with open(output_file, "w") as file:
# Write headers
file.write("Animal\tDate\tCondition\tNotes\n")
# Write data rows
for info in file_info_list:
file.write("\t".join(info) + "\n")
print(f"Output saved to {output_file}")