File size: 2,573 Bytes
d47d089
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import pandas as pd

import os
import shutil

def split_csv(input_file, train_file, validate_file, test_file, train_size, validate_size, test_size):
    # Read the input CSV file
    data = pd.read_csv(input_file)

    # Split the data into train, validate, and test subsets
    train_data = data.iloc[:train_size]
    validate_data = data.iloc[train_size:train_size + validate_size]
    test_data = data.iloc[train_size + validate_size:train_size + validate_size + test_size]

    # Save the subsets to separate CSV files
    train_data.to_csv(train_file, index=False)
    validate_data.to_csv(validate_file, index=False)
    test_data.to_csv(test_file, index=False)

def copy_ecg_files(csv_file, destination_folder, src_folder):
    # Read the CSV file
    data = pd.read_csv(csv_file)

    # Create the destination folder if it doesn't exist
    if not os.path.exists(destination_folder):
        os.makedirs(destination_folder)

    # Copy the corresponding ECG files to the destination folder
    for index, row in data.iterrows():
        ecg_file = str(row['patid']) + ".asc"  # Replace 'ecg_filename' with the appropriate column name containing the ECG file names
        src_path = os.path.join(src_folder, ecg_file)
        dst_path = os.path.join(destination_folder, ecg_file)
        shutil.copy(src_path, dst_path)

if __name__ == '__main__':

    # Set the input CSV file and the source folder
    dst_dir = '/work/vajira/data/deepfake_ecg_full_train_validation_test'
    input_file = '/work/vajira/data/Deepfake-ecg/filtered_all_normals_121977_ground_truth.csv'  # Change this to the name of your CSV file
    train_file = f'{dst_dir}/train.csv'
    validate_file = f'{dst_dir}/validate.csv'
    test_file = f'{dst_dir}/test.csv'
    src_folder = '/work/vajira/data/Deepfake-ecg/filtered_all_normals_121977/from_006_chck_2500_150k_filtered_all_normals_121977'  # Change this to the name of the folder containing the ECG files
    
    # Set the sizes of the train, validate, and test subsets from full size of the dataset 121977
    train_size = 97581 # 80% of 121977=97581
    validate_size = 12198 # 10% of 121977=12198
    test_size = 12198 # 10% of 121977=12198

    split_csv(input_file, train_file, validate_file, test_file, train_size, validate_size, test_size)

     # Call the copy_ecg_files function to copy the ECG files into the corresponding folders
    copy_ecg_files(train_file, f'{dst_dir}/train', src_folder)
    copy_ecg_files(validate_file, f'{dst_dir}/validation', src_folder)
    copy_ecg_files(test_file, f'{dst_dir}/test', src_folder)