Skip to content

Instantly share code, notes, and snippets.

@caner-ercan
Last active January 5, 2025 23:16
Show Gist options
  • Select an option

  • Save caner-ercan/0036fa52f0a688abfc10bf9af0972f3d to your computer and use it in GitHub Desktop.

Select an option

Save caner-ercan/0036fa52f0a688abfc10bf9af0972f3d to your computer and use it in GitHub Desktop.
QuPath data access via json
#!/bin/bash
# Define the base directory
BASE_DIR="/Users/cercan/Desktop/BE/NU_wholeDataset_qupath/data" # Change this to your target directory
OUTPUT_CSV="/Users/cercan/Desktop/BE/NU_wholeDataset_qupath/annotationData.csv"
# Write the header to the CSV file
echo "Name,Unclassified,Biopsy,Flow" > "$OUTPUT_CSV"
# Find all subdirectories and process the JSON files
find "$BASE_DIR" -type d | while read -r dir; do
# Read server.json
SERVER_JSON="$dir/server.json"
if [[ -f "$SERVER_JSON" ]]; then
NAME=$(jq -r '.metadata.name // "N/A"' "$SERVER_JSON")
else
NAME="N/A"
fi
# Read summary.json
SUMMARY_JSON="$dir/summary.json"
if [[ -f "$SUMMARY_JSON" ]]; then
UNCLASSIFIED=$(jq -r '.hierarchy.annotationClassificationCounts.Unclassified // "0"' "$SUMMARY_JSON")
BIOPSY=$(jq -r '.hierarchy.annotationClassificationCounts.biopsy // "0"' "$SUMMARY_JSON")
FLOW=$(jq -r '.hierarchy.annotationClassificationCounts.flow // "0"' "$SUMMARY_JSON")
else
UNCLASSIFIED="0"
BIOPSY="0"
FLOW="0"
fi
# Append the data to the CSV file
echo "$NAME,$UNCLASSIFIED,$BIOPSY,$FLOW" >> "$OUTPUT_CSV"
done
echo "Data has been written to $OUTPUT_CSV"
#!/bin/bash
# Directory to start from
dir="/Volumes/rsrch6/home/trans_mol_path/yuan_lab/TIER2/barrett/roi/flow/NU/QuPath_240813/data"
# Loop through all subdirectories
for subdir in "$dir"/*; do
if [ -d "$subdir" ]; then
# Check if summary.json exists and contains "flow_new"
if grep -q "flow_new" "$subdir/summary.json"; then
# Extract the value of "uri" from server.json
uri=$(jq -r '.uri' "$subdir/server.json")
# Print the value of "uri"
echo "URI in $subdir: $uri"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment