Skip to content

Commit 45cdb7a

Browse files
committed
Line counting was wrong for files with more than 50 lines
1 parent fd5fb28 commit 45cdb7a

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

src/cryoemservices/pipeliner_plugins/combine_star_files.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ def combine_star_files(files_to_process: List[Path], output_dir: Path):
3838

3939
# Make a temporary star file to get the table headings from
4040
reference_optics = None
41-
with open(files_to_process[0], "r") as full_starfile, open(
42-
output_dir / ".particles_tmp.star", "w"
43-
) as tmp_starfile:
41+
with (
42+
open(files_to_process[0], "r") as full_starfile,
43+
open(output_dir / ".particles_tmp.star", "w") as tmp_starfile,
44+
):
4445
for line_counter in range(50):
4546
line = full_starfile.readline()
4647
if line.startswith("opticsGroup"):
@@ -95,9 +96,10 @@ def combine_star_files(files_to_process: List[Path], output_dir: Path):
9596

9697
# Add the particles lines to the final star file
9798
file_particles_count = 0
98-
with open(split_file, "r") as added_starfile, open(
99-
output_dir / ".particles_all_tmp.star", "a"
100-
) as particles_file:
99+
with (
100+
open(split_file, "r") as added_starfile,
101+
open(output_dir / ".particles_all_tmp.star", "a") as particles_file,
102+
):
101103
while True:
102104
particle_line = added_starfile.readline()
103105
if not particle_line:
@@ -131,20 +133,22 @@ def split_star_file(
131133
"""
132134

133135
# Make a temporary star file to get the table headings from
134-
with open(file_to_process, "r") as full_starfile, open(
135-
output_dir / ".particles_tmp.star", "w"
136-
) as tmp_starfile:
136+
with (
137+
open(file_to_process, "r") as full_starfile,
138+
open(output_dir / ".particles_tmp.star", "w") as tmp_starfile,
139+
):
137140
for line_counter in range(50):
138141
line = full_starfile.readline()
139142
if not line:
143+
line_counter -= 1
140144
break
141145
tmp_starfile.write(line)
142146

143147
star_dictionary = starfile.read(output_dir / ".particles_tmp.star")
144148
(output_dir / ".particles_tmp.star").unlink()
145149

146150
# Find the number of lines in the full file
147-
starfile_starter_lines = line_counter - star_dictionary["particles"].shape[0]
151+
starfile_starter_lines = line_counter + 1 - star_dictionary["particles"].shape[0]
148152
count = 0
149153
with open(file_to_process, "r") as full_starfile:
150154
for count, line in enumerate(full_starfile):

0 commit comments

Comments
 (0)