diff --git a/analyze.py b/analyze.py index bb7a3f8f..7380159a 100644 --- a/analyze.py +++ b/analyze.py @@ -216,20 +216,23 @@ def combineResults(folder: str, output_file: str): # Combine all files s_id = 1 time_offset = 0 + with open(os.path.join(folder, output_file), "w", encoding="utf-8") as f: - f.write("Selection\tView\tChannel\tBegin Path\tBegin Time (s)\tEnd Time (s)\tLow Freq (Hz)\tHigh Freq (Hz)\tSpecies Code\tCommon Name\tConfidence\n") + f.write("Selection\tView\tChannel\tBegin Path\tFile Duration (s)\tBegin Time (s)\tEnd Time (s)\tLow Freq (Hz)\tHigh Freq (Hz)\tSpecies Code\tCommon Name\tConfidence\n") + for rfile in files: with open(rfile, "r", encoding="utf-8") as rf: try: - lines = rf.readlines() + # make sure it's a selection table if not "Selection" in lines[0] or not "File Duration" in lines[0]: continue # skip header and add to file f_duration = float(lines[1].split("\t")[4]) + for line in lines[1:]: # empty line? @@ -250,9 +253,6 @@ def combineResults(folder: str, output_file: str): line[5] = str(float(line[5]) + time_offset) line[6] = str(float(line[6]) + time_offset) - # remove File Duration - del line[4] - # write line f.write("\t".join(line)) diff --git a/segments.py b/segments.py index ffb0465d..f20bf844 100644 --- a/segments.py +++ b/segments.py @@ -153,8 +153,8 @@ def findSegments(afile: str, rfile: str): for i, line in enumerate(lines): if rtype == "table" and i > 0: d = line.split("\t") - start = float(d[4]) - end = float(d[5]) + start = float(d[5]) + end = float(d[6]) species = d[-2] confidence = float(d[-1])