-
-
Save DavidStirling/2cf59745319baad7b283fcb897a7a143 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"This script will annotate CellProfiler object datasheets with image information" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import pandas as pd" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Provide paths to the objects and images CSV files.\n", | |
"object_csv = \"/example/path/to/nuclei.csv\"\n", | |
"image_csv = \"/example/path/to/images.csv\"\n", | |
"\n", | |
"# Specify column names from the images sheet that you want to annotate the objects with, examples provided.\n", | |
"# ImageNumber is required for merging, please don't remove this.\n", | |
"columns_to_merge = ['ImageNumber', 'Image_Metadata_ColNameHere', 'Image_Metadata_AnotherColNameHere']\n", | |
"\n", | |
"# Provide an export file name and directory.\n", | |
"target_file = \"/example/results/output.csv\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# This will construct the data frames we want to merge.\n", | |
"main_df = pd.read_csv(object_csv, engine='python')\n", | |
"\n", | |
"image_df = pd.read_csv(image_csv, engine='python')\n", | |
"\n", | |
"meta_df = image_df[columns_to_merge]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Perform merging and display a preview of the resulting table.\n", | |
"main_df = main_df.merge(meta_df, on=\"ImageNumber\")\n", | |
"main_df" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Save the resulting table\n", | |
"main_df.to_csv(target_file)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.8.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment