@@ -38,14 +38,28 @@ def main():
3838 lines = input_file .read_text ().splitlines (keepends = True )
3939
4040 fixed_lines = []
41- evm_path = f"{ evm_dir } /"
42- genome_path = evm_dir / "genome.fasta"
4341 for line in lines :
44- # Replace bare EVM/ with the resolved EVM directory; ignore occurrences already inside other paths
45- fixed_line = re .sub (r"(?<![\\w/])EVM/" , evm_path , line )
46- # Ensure genome path is absolute so evm runs inside exec_dir can find it
47- fixed_line = re .sub (r"-G\\s+genome\\.fasta" , f"-G { genome_path } " , fixed_line )
48- fixed_lines .append (fixed_line )
42+ # The evidence_modeler.pl script changes its working directory to the value of --exec_dir.
43+ # This means that any relative paths for input files will be broken.
44+ # This loop finds common input file arguments and converts their paths to be absolute.
45+ # It looks for a flag (e.g., -G), whitespace, and then a path that does *not* start with '/'.
46+ # It assumes file paths do not contain spaces.
47+ updated_line = line
48+ for flag in ["-G" , "-g" , "-e" , "-p" ]:
49+ # Pattern: flag, one or more spaces, a path that is not absolute (doesn't start with /),
50+ # and is followed by a space. We'll capture the flag and path.
51+ pattern = re .compile (f"({ flag } \\ s+)([^/\\ s][^\\ s]*)" )
52+
53+ # Use a function for replacement to handle multiple matches in a line if they were to occur
54+ def repl (match ):
55+ file_path = match .group (2 )
56+ # Prepend the absolute path to the EVM directory
57+ abs_path = evm_dir / file_path
58+ return f"{ match .group (1 )} { abs_path } "
59+
60+ updated_line = pattern .sub (repl , updated_line )
61+
62+ fixed_lines .append (updated_line )
4963
5064 random .shuffle (fixed_lines )
5165
@@ -58,7 +72,8 @@ def main():
5872 lines_to_write = lines_per_file + (1 if file_num < remainder_lines else 0 )
5973 with output_file .open ("w" ) as outfile :
6074 for _ in range (lines_to_write ):
61- outfile .write (fixed_lines .pop ())
75+ if fixed_lines :
76+ outfile .write (fixed_lines .pop ())
6277
6378
6479if __name__ == "__main__" :
0 commit comments