-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_schemas.sh
More file actions
executable file
·47 lines (33 loc) · 1.57 KB
/
generate_schemas.sh
File metadata and controls
executable file
·47 lines (33 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Exit script if any command fails
set -e
# Define directories
DATA_DIR="data"
OUTPUT_DIR="source_schemas"
RAW_SCHEMA="${OUTPUT_DIR}/raw_patients_schema.yaml"
FINAL_SCHEMA="${OUTPUT_DIR}/patients_schema.yaml"
# Activate the existing linkml environment
source /Users/alabarga/code/environments/linkml-env/bin/activate
# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"
echo "=========================================================="
echo " Generating LinkML Schema for Patients Data "
echo "=========================================================="
echo ""
echo "➡️ Extracting schema from patients.csv..."
# Convert CSV to TSV to guarantee correct LinkML parsing
TMP_TSV="/tmp/patients_$$.tsv"
python3 -c "import csv, sys; csv.writer(sys.stdout, delimiter='\t').writerows(csv.reader(sys.stdin))" < "$DATA_DIR/patients.csv" > "$TMP_TSV"
# Run Schema Automator to infer the LinkML schema just for patients.csv
schemauto generalize-tsv --class-name Patients "$TMP_TSV" > "$RAW_SCHEMA"
rm -f "$TMP_TSV"
echo " ✓ Generated raw schema: $RAW_SCHEMA"
echo ""
echo "➡️ Enriching slots with OMOP-CDM required structure..."
# Run the python script to append description, imported_from, range, identifier, and required fields
python3 enrich_schema.py "$RAW_SCHEMA" "$FINAL_SCHEMA"
echo " ✓ Generated final enriched schema: $FINAL_SCHEMA"
echo ""
echo "=========================================================="
echo " Process completed successfully! "
echo "=========================================================="