Addition Information for Python insiders

This additional information on the class and its functions and not needed if you completed the previous step in the tutorial.

Step-by-step Python tutorial

For you to call and use the ProcessMRXS Python class via Python script, this is the step-by-step tutorial:

  1. Clone or download this repository to your local machine/laptop.

  2. Import the processMRXSData class into your Python script.

from process_mrxs_data import ProcessMRXSData
  1. Create an instance of the ProcessMRXSData class by providing paths to your MRXS files in a specific directory and inventory file, as well as the other files necessary to launch the call.

mrxs_directory = "path/to/your/mrxs_files"
inventory_file = "path/to/your/inventory.csv"
output_path = "path/to/your/directory/to/outputs"
output_extension="xlsx/csv" 
#(should choose one of the extension)

processor = ProcessMRXSData.process_directory(mrxs_directory, inventory_file, output_path, output_extension)
  1. Call the other functions for the rate calculation and relative images:

#Remember to define the output_filename as ENV 
# EXPORT output_filename="whatever/name"
rate = ProcessMRXSData.process_rate(output_path, output_filename)

for file in rate:
    ProcessMRXSData.process_heatmaps(rate)
    ProcessMRXSData.process_scatterplots(rate)
  1. Check the output images in the output_path


Example of workflow_template script:

In a new file with the extension .py, you should write:

import argparse
from process_mrxs_data import ProcessMRXSData

def main():
    parser = argparse.ArgumentParser(description="Run MRXS data processing workflow")
    parser.add_argument("directory_path", help="Path to the directory containing .mrxs files")
    parser.add_argument("inventory_file", help="Path to the inventory file")
    parser.add_argument("output_path", help="Path to the directory containing output files")
    parser.add_argument("output_extension", help="Extension of the final file")
    

    args = parser.parse_args()

    directory_path = args.directory_path
    inventory_file = args.inventory_file
    output_path = args.output_path
    output_ex = args.output_extension
    
    final_data_filename = "final_data" + f".{output_ex}"
    print ("Final data filename", final_data_filename)

    final_data = ProcessMRXSData.process_directory(directory_path, inventory_file, output_path, output_ex)
    final_files = ProcessMRXSData.process_rate(output_path, final_data_filename)

 
    for file in final_files:
        ProcessMRXSData.process_heatmaps(file)
        ProcessMRXSData.process_scatterplots(file)

    # Print the final DataFrame
    #print(f"Final DataFrame saved to {output_filename}")
    print(f"Final Immunopositivity DataFrame saved to {final_data_filename}")
    print(f"Processing complete.")

if __name__ == "__main__":
    main()

Using this standard file and calling via command line, you should haver in the same directory the resulting file and scatterplots.

Just in case:

You can call your Python script template.py on the terminal with this command:

python workflow_template.py path/to/directory/with/mrxs/files /path/to/inventory/file
/path/to/directory/for/output/files xlsx/csv (should choose one of the extension)

Or:

python3 workflow_template.py /path/to/directory/with/mrxs/files /path/to/inventory/file /path/to/directory/for/output/files xlsx/csv (should choose one of the extension)

Last updated