Skip to content
Snippets Groups Projects

new laura folder

Merged Laura Rævsbæk Birch requested to merge au620747-main-patch-86964 into main
1 file
+ 14
0
Compare changes
  • Side-by-side
  • Inline
+ 91
0
from genericpath import exists
import csv
#region Create scoring events .tsv file
def create_scoringFile_tsv(path, scoringFile):
isHeader = True
offset = []
onset = -30
with open(path, 'wt') as out_file:
if (exists(scoringFile) == True):
with open(scoringFile) as file:
tsv_writer = csv.writer(out_file, delimiter='\t', lineterminator='\n')
if isHeader == True:
offset.append('onset')
offset.append('duration')
offset.append('staging')
isHeader = False
tsv_writer.writerow(offset)
offset.clear()
for line in file:
if (line[7:12] == '0,000' or line[18:23] == '0,000'):
onset = onset + 30
offset.append(onset)
offset.append(0)
if (line[25:] == 'Wake\n' or line[14:] == 'Wake\n'):
offset.append('1')
elif (line[25:] == 'REM\n' or line[14:] == 'REM\n'):
offset.append('2')
elif (line[25:] == 'N1\n' or line[14:] == 'N1\n'):
offset.append('3')
elif (line[25:] == 'N2\n' or line[14:] == 'N2\n'):
offset.append('4')
elif (line[25:] == 'N3\n' or line[14:] == 'N3\n' or line[25:] == 'N4\n' or line[14:] == 'N4\n'):
offset.append('5')
elif (line[25:] == 'A\n' or line[14:] == 'A\n'):
offset.append('6')
elif (line[25:] == 'Movement\n' or line[14:] == 'Movement\n'):
offset.append('7')
elif (line[25:] == 'Artefact\n' or line[14:] == 'Artefact\n'):
offset.append('8')
elif (line[25:] == 'Unscored\n' or line[14:] == 'Unscored\n'):
offset.append('9')
tsv_writer.writerow(offset)
offset.clear()
def create_scoring_file_tsv_david(path, scoringFile):
isHeader = True
offset = []
onset = -30
with open(path, 'wt') as out_file:
if (exists(scoringFile) == True):
with open(scoringFile) as file:
tsv_writer = csv.writer(out_file, delimiter='\t')
if isHeader == True:
offset.append('onset')
offset.append('duration')
offset.append('staging')
isHeader = False
tsv_writer.writerow(offset)
offset.clear()
for line in file:
onset = onset + 30
offset.append(onset)
offset.append(0)
if (line == 'Wake\n'):
offset.append('1')
elif (line == 'REM\n'):
offset.append('2')
elif (line == 'NREM 1\n'):
offset.append('3')
elif (line == 'NREM 2\n'):
offset.append('4')
elif (line == 'NREM 3\n'):
offset.append('5')
elif (line == 'A\n'):
offset.append('6')
elif (line == 'Artefact\n'):
offset.append('7')
elif (line == 'Unscored\n'):
offset.append('8')
tsv_writer.writerow(offset)
offset.clear()
#endregion
\ No newline at end of file
Loading