Is there a way to tell the program to automatically generate a new mapping file that is set to append after each run?
For context, I am generating mapping files for protocols that involves cherry picking. The data handling step is within a loop since I am also using STAR channel optimization tool (for those who knows how the tool works). Since the data handling step is inside the loop, I have to set the mode to “append” in order to map all of the sequences after each loop.
The problem of using the append mode occurs when you doing multiple runs. For example, on the first run, it will automatically generate the mapping file with the file name given in the method (for example, “file_name.csv”). Of course, it will generate the file only if the file_name.csv was never created before. So, if you do not manually delete file_name.csv before the second run, the new sequences will be added to the preexisting file name instead of putting it in a separate file.
Manually deleting file_name.csv between each run is not a huge problem but heavily relies on human inputs. Therefore, if someone forgets to delete the previous file_name.csv then it will be difficult and confusing to trace back to their sequences.
I also can’t use “” to generate the mapping file by number because the program will literally tell you that the placeholder is not compatible with append mode.
Apologies for the long explanation but is there a way to work around this issue by any chance?
Any help appreciated as always,
@Nat - If your mapping file code is already functional per your requirements, I would either change the name of the file used in each run to be unique and run-specific, or delete the file programmatically as part of the method prior to the code that generates the mapping report.
To delete the file prior to it being re-created, you can use a couple functions of the File library within the HSLExtensions suite of libraries. First, check to see if the file path of interest exists using the ‘Exists’ function:
This will return hslTrue (1) if the file exists, and hslFalse (0) if not. If it exists, then call the ‘Delete’ function to delete the file.
At this point, your code will work as intended without having to rely on somebody having to consistently delete a file manually.
The other option, which may be preferential as it would retain all generated run data without being deleted would be to use a unique file path name with each run, as opposed to a hardcoded value. There are many options here, but a common one would be to incorporate a date and time stamp as part of the file name. This can be done using the HSLTimLib library (installs with VENUS), which has functions that return the current date and time as formatted strings.
These date and time sub strings can then be incorporated into a string variable for the file path using one of the ‘StrConcatX’ functions of the HSLStrLib.
You can even generate unique folders for each run using the ‘Directory’ library of HSLExtensions, which contains several functions for creation and management of folders and subfolders.
Hope this helps.
Thank you for providing multiple solutions based on the need. Yes, my mapping file code works fine, the only issue was exporting it on different file names. I used the HSLTimLib Library to incorporate the date and time into file name and it works like a charm for each run!