QuPath H-DAB Project
  • ๐Ÿ“ŠQuPath guide for H-DAB Cell Counting Docs
  • ๐Ÿ’กPipeline
    • ๐Ÿ’กSimple Pipeline
  • Fundamentals
    • ๐Ÿ› ๏ธGetting Set Up
  • QuPath H-Dab Docs
    • ๐Ÿ’กQuPath H-DAB Tutorial
      • Creating and Opening of Projects
      • Estimating Stain Vectors
      • Training Image Creation
      • Cell Detection
      • Object Classifier
      • Tissue Detection
        • 1๏ธโƒฃAutomatic General Tissue Detection
        • 2๏ธโƒฃManual Specific Tissue Detection
    • ๐ŸงพQuPath Script
      • Batch Processing
    • ๐Ÿ“‚Output
  • Result Analysis Docs
    • ๐Ÿ’กProcessing Package Tutorial
      • Addition Information for Python insiders
      • In-Depth Python usage
    • ๐Ÿ—„๏ธFinal Spreadsheet creation
    • ๐Ÿ†˜Out-of-memory error
  • non-expert docs
    • ๐Ÿ”ŽQuPath Installation
    • ๐Ÿ’ปGit Bash Installation
    • ๐Ÿ–ฅ๏ธPython Installation & Packages
    • Git Bash installation
Powered by GitBook
On this page
  • Step-by-step Python tutorial
  • Example of workflow_template script:
  1. Result Analysis Docs
  2. Processing Package Tutorial

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.

Last updated 1 year ago

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 downloadrepository 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)
๐Ÿ’ก
this