{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f22e0117",
   "metadata": {
    "papermill": {
     "duration": 0.001975,
     "end_time": "2025-12-07T04:07:46.750694",
     "exception": false,
     "start_time": "2025-12-07T04:07:46.748719",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# Getting Started with linkml-data-qc\n",
    "\n",
    "This tutorial walks you through using linkml-data-qc to analyze compliance with recommended fields in your LinkML data.\n",
    "\n",
    "## Prerequisites\n",
    "\n",
    "Install linkml-data-qc:\n",
    "\n",
    "```bash\n",
    "pip install linkml-data-qc\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "06da2c90",
   "metadata": {
    "papermill": {
     "duration": 0.001253,
     "end_time": "2025-12-07T04:07:46.753473",
     "exception": false,
     "start_time": "2025-12-07T04:07:46.752220",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Sample Data\n",
    "\n",
    "Let's create a simple LinkML schema and some test data. First, the schema:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f664d58e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-12-07T04:07:46.756991Z",
     "iopub.status.busy": "2025-12-07T04:07:46.756842Z",
     "iopub.status.idle": "2025-12-07T04:07:46.771073Z",
     "shell.execute_reply": "2025-12-07T04:07:46.770707Z"
    },
    "papermill": {
     "duration": 0.016866,
     "end_time": "2025-12-07T04:07:46.771772",
     "exception": false,
     "start_time": "2025-12-07T04:07:46.754906",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Schema created!\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "cat > /tmp/disease_schema.yaml << 'EOF'\n",
    "id: https://example.org/disease\n",
    "name: disease_schema\n",
    "prefixes:\n",
    "  linkml: https://w3id.org/linkml/\n",
    "imports:\n",
    "  - linkml:types\n",
    "default_range: string\n",
    "\n",
    "classes:\n",
    "  Disease:\n",
    "    attributes:\n",
    "      id:\n",
    "        identifier: true\n",
    "      name:\n",
    "        required: true\n",
    "      description:\n",
    "        recommended: true\n",
    "      synonyms:\n",
    "        multivalued: true\n",
    "        recommended: true\n",
    "      ontology_id:\n",
    "        recommended: true\n",
    "EOF\n",
    "echo \"Schema created!\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9fe5bdd2",
   "metadata": {
    "papermill": {
     "duration": 0.001217,
     "end_time": "2025-12-07T04:07:46.774396",
     "exception": false,
     "start_time": "2025-12-07T04:07:46.773179",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Now let's create two data files - one with good compliance and one with poor compliance:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8b0c9534",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-12-07T04:07:46.777596Z",
     "iopub.status.busy": "2025-12-07T04:07:46.777469Z",
     "iopub.status.idle": "2025-12-07T04:07:46.791235Z",
     "shell.execute_reply": "2025-12-07T04:07:46.790940Z"
    },
    "papermill": {
     "duration": 0.016127,
     "end_time": "2025-12-07T04:07:46.791877",
     "exception": false,
     "start_time": "2025-12-07T04:07:46.775750",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Data files created!\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "# Good compliance - all recommended fields populated\n",
    "cat > /tmp/disease_good.yaml << 'EOF'\n",
    "id: DISEASE:001\n",
    "name: Asthma\n",
    "description: A chronic respiratory condition characterized by inflammation of the airways\n",
    "synonyms:\n",
    "  - bronchial asthma\n",
    "  - reactive airway disease\n",
    "ontology_id: MONDO:0004979\n",
    "EOF\n",
    "\n",
    "# Poor compliance - missing recommended fields\n",
    "cat > /tmp/disease_poor.yaml << 'EOF'\n",
    "id: DISEASE:002\n",
    "name: Unknown Disease\n",
    "EOF\n",
    "\n",
    "echo \"Data files created!\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "881dc9d4",
   "metadata": {
    "papermill": {
     "duration": 0.001258,
     "end_time": "2025-12-07T04:07:46.794656",
     "exception": false,
     "start_time": "2025-12-07T04:07:46.793398",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Basic Usage\n",
    "\n",
    "Run linkml-data-qc on a single file to see compliance scores:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c4752b32",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-12-07T04:07:46.798985Z",
     "iopub.status.busy": "2025-12-07T04:07:46.798855Z",
     "iopub.status.idle": "2025-12-07T04:07:47.375679Z",
     "shell.execute_reply": "2025-12-07T04:07:47.375375Z"
    },
    "papermill": {
     "duration": 0.57971,
     "end_time": "2025-12-07T04:07:47.376574",
     "exception": false,
     "start_time": "2025-12-07T04:07:46.796864",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Compliance Report: /tmp/disease_good.yaml\n",
      "Target Class: Disease\n",
      "Global Compliance: 100.0% (3/3)\n",
      "Weig"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hted Compliance: 100.0%\n",
      "\n",
      "Summary by Slot:\n",
      "  description: 100.0%\n",
      "  ontology_id: 100.0%\n",
      "  synonyms: 10"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.0%\n",
      "\n",
      "Detailed Path Scores:\n",
      "  (root) (Disease): 100.0%\n",
      "    - description: OK\n",
      "    - synonyms: OK\n",
      "    "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "- ontology_id: OK\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "linkml-data-qc /tmp/disease_good.yaml \\\n",
    "    -s /tmp/disease_schema.yaml \\\n",
    "    -t Disease"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2e0ebfed",
   "metadata": {
    "papermill": {
     "duration": 0.001531,
     "end_time": "2025-12-07T04:07:47.379922",
     "exception": false,
     "start_time": "2025-12-07T04:07:47.378391",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Now let's check the poor compliance file:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "8d027743",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-12-07T04:07:47.383447Z",
     "iopub.status.busy": "2025-12-07T04:07:47.383310Z",
     "iopub.status.idle": "2025-12-07T04:07:47.673147Z",
     "shell.execute_reply": "2025-12-07T04:07:47.672818Z"
    },
    "papermill": {
     "duration": 0.292624,
     "end_time": "2025-12-07T04:07:47.674011",
     "exception": false,
     "start_time": "2025-12-07T04:07:47.381387",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Compliance Report: /tmp/disease_poor.yaml\n",
      "Target Class: Disease\n",
      "Global Compliance: 0.0% (0/3)\n",
      "Weight"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ed Compliance: 100.0%\n",
      "\n",
      "Summary by Slot:\n",
      "  description: 0.0%\n",
      "  ontology_id: 0.0%\n",
      "  synonyms: 0.0%\n",
      "\n",
      "De"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tailed Path Scores:\n",
      "  (root) (Disease): 0.0%\n",
      "    - description: MISSING\n",
      "    - synonyms: MISSING\n",
      "    "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "- ontology_id: MISSING\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "linkml-data-qc /tmp/disease_poor.yaml \\\n",
    "    -s /tmp/disease_schema.yaml \\\n",
    "    -t Disease"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "25f75efe",
   "metadata": {
    "papermill": {
     "duration": 0.001559,
     "end_time": "2025-12-07T04:07:47.677392",
     "exception": false,
     "start_time": "2025-12-07T04:07:47.675833",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Output Formats\n",
    "\n",
    "### JSON Output\n",
    "\n",
    "Use `-f json` for machine-readable output:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "07297a51",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-12-07T04:07:47.681467Z",
     "iopub.status.busy": "2025-12-07T04:07:47.681312Z",
     "iopub.status.idle": "2025-12-07T04:07:48.008957Z",
     "shell.execute_reply": "2025-12-07T04:07:48.008548Z"
    },
    "papermill": {
     "duration": 0.331066,
     "end_time": "2025-12-07T04:07:48.010088",
     "exception": false,
     "start_time": "2025-12-07T04:07:47.679022",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"file_path\": \"/tmp/disease_good.yaml\",\n",
      "  \"target_class\": \"Disease\",\n",
      "  \"schema_path\": \"/tmp/disea"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "se_schema.yaml\",\n",
      "  \"global_compliance\": 100.0,\n",
      "  \"weighted_compliance\": 100.0,\n",
      "  \"total_checks\": 3,\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  \"total_populated\": 3,\n",
      "  \"path_scores\": [\n",
      "    {\n",
      "      \"path\": \"(root)\",\n",
      "      \"parent_class\": \"Dise"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ase\",\n",
      "      \"item_count\": 1,\n",
      "      \"slot_scores\": [\n",
      "        {\n",
      "          \"path\": \"(root)\",\n",
      "          "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\"slot_name\": \"description\",\n",
      "          \"populated\": 1,\n",
      "          \"total\": 1,\n",
      "          \"percentage\": "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100.0\n",
      "        },\n",
      "        {\n",
      "          \"path\": \"(root)\",\n",
      "          \"slot_name\": \"synonyms\",\n",
      "          "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\"populated\": 1,\n",
      "          \"total\": 1,\n",
      "          \"percentage\": 100.0\n",
      "        },\n",
      "        {\n",
      "          \""
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "path\": \"(root)\",\n",
      "          \"slot_name\": \"ontology_id\",\n",
      "          \"populated\": 1,\n",
      "          \"total\": "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1,\n",
      "          \"percentage\": 100.0\n",
      "        }\n",
      "      ],\n",
      "      \"overall_percentage\": 100.0\n",
      "    }\n",
      "  ],\n",
      "  \""
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "aggregated_scores\": [],\n",
      "  \"threshold_violations\": [],\n",
      "  \"summary_by_slot\": {\n",
      "    \"description\": 100."
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0,\n",
      "    \"synonyms\": 100.0,\n",
      "    \"ontology_id\": 100.0\n",
      "  },\n",
      "  \"recommended_slots\": [\n",
      "    \"synonyms\",\n",
      "   "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " \"description\",\n",
      "    \"ontology_id\"\n",
      "  ],\n",
      "  \"config_path\": null,\n",
      "  \"timestamp\": \"2025-12-06T20:07:47.96"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9074\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "linkml-data-qc /tmp/disease_good.yaml \\\n",
    "    -s /tmp/disease_schema.yaml \\\n",
    "    -t Disease \\\n",
    "    -f json"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f45f17a6",
   "metadata": {
    "papermill": {
     "duration": 0.001915,
     "end_time": "2025-12-07T04:07:48.014202",
     "exception": false,
     "start_time": "2025-12-07T04:07:48.012287",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "### CSV Output\n",
    "\n",
    "Use `-f csv` for spreadsheet-friendly output:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "aa81e8d5",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-12-07T04:07:48.018608Z",
     "iopub.status.busy": "2025-12-07T04:07:48.018466Z",
     "iopub.status.idle": "2025-12-07T04:07:48.309358Z",
     "shell.execute_reply": "2025-12-07T04:07:48.308938Z"
    },
    "papermill": {
     "duration": 0.29437,
     "end_time": "2025-12-07T04:07:48.310423",
     "exception": false,
     "start_time": "2025-12-07T04:07:48.016053",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "file,path,class,slot,populated,total,percentage\r\n",
      "/tmp/disease_good.yaml,(root),Disease,description,1"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ",1,100.0\r\n",
      "/tmp/disease_good.yaml,(root),Disease,synonyms,1,1,100.0\r\n",
      "/tmp/disease_good.yaml,(root),Di"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sease,ontology_id,1,1,100.0\r\n",
      "\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "linkml-data-qc /tmp/disease_good.yaml \\\n",
    "    -s /tmp/disease_schema.yaml \\\n",
    "    -t Disease \\\n",
    "    -f csv"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1cbd412",
   "metadata": {
    "papermill": {
     "duration": 0.003344,
     "end_time": "2025-12-07T04:07:48.316311",
     "exception": false,
     "start_time": "2025-12-07T04:07:48.312967",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Analyzing Multiple Files\n",
    "\n",
    "You can analyze multiple files at once:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "886cc4f6",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-12-07T04:07:48.345555Z",
     "iopub.status.busy": "2025-12-07T04:07:48.345400Z",
     "iopub.status.idle": "2025-12-07T04:07:48.657471Z",
     "shell.execute_reply": "2025-12-07T04:07:48.657105Z"
    },
    "papermill": {
     "duration": 0.319413,
     "end_time": "2025-12-07T04:07:48.658298",
     "exception": false,
     "start_time": "2025-12-07T04:07:48.338885",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Multi-File Compliance Report\n",
      "Files Analyzed: 2\n",
      "Global Compliance: 50.0%\n",
      "Weighted Compliance: 100.0%\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Summary by Slot (across all files):\n",
      "  description: 50.0%\n",
      "  ontology_id: 50.0%\n",
      "  synonyms: 50.0%\n",
      "\n",
      "Su"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "mmary by Path (across all files):\n",
      "  (root).description: 50.0%\n",
      "  (root).ontology_id: 50.0%\n",
      "  (root).s"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ynonyms: 50.0%\n",
      "\n",
      "Per-File Compliance:\n",
      "  /tmp/disease_good.yaml: 100.0%\n",
      "  /tmp/disease_poor.yaml: 0.0%"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "linkml-data-qc /tmp/disease_good.yaml /tmp/disease_poor.yaml \\\n",
    "    -s /tmp/disease_schema.yaml \\\n",
    "    -t Disease"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1871783e",
   "metadata": {
    "papermill": {
     "duration": 0.002263,
     "end_time": "2025-12-07T04:07:48.662940",
     "exception": false,
     "start_time": "2025-12-07T04:07:48.660677",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Analyzing a Directory\n",
    "\n",
    "Use a glob pattern to analyze all matching files in a directory:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b96ad9b0",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-12-07T04:07:48.667765Z",
     "iopub.status.busy": "2025-12-07T04:07:48.667633Z",
     "iopub.status.idle": "2025-12-07T04:07:49.034995Z",
     "shell.execute_reply": "2025-12-07T04:07:49.034546Z"
    },
    "papermill": {
     "duration": 0.371208,
     "end_time": "2025-12-07T04:07:49.036105",
     "exception": false,
     "start_time": "2025-12-07T04:07:48.664897",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Multi-File Compliance Report\n",
      "Files Analyzed: 3\n",
      "Global Compliance: 33.3%\n",
      "Weighted Compliance: 100.0%\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Summary by Slot (across all files):\n",
      "  description: 33.3%\n",
      "  ontology_id: 33.3%\n",
      "  synonyms: 33.3%\n",
      "\n",
      "Su"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "mmary by Path (across all files):\n",
      "  (root).description: 33.3%\n",
      "  (root).ontology_id: 33.3%\n",
      "  (root).s"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ynonyms: 33.3%\n",
      "\n",
      "Per-File Compliance:\n",
      "  /tmp/disease_good.yaml: 100.0%\n",
      "  /tmp/disease_poor.yaml: 0.0%"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "  /tmp/disease_schema.yaml: 0.0%\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "linkml-data-qc /tmp \\\n",
    "    -s /tmp/disease_schema.yaml \\\n",
    "    -t Disease \\\n",
    "    --pattern \"disease_*.yaml\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a8e60b1c",
   "metadata": {
    "papermill": {
     "duration": 0.00243,
     "end_time": "2025-12-07T04:07:49.041076",
     "exception": false,
     "start_time": "2025-12-07T04:07:49.038646",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Setting Compliance Thresholds\n",
    "\n",
    "Use `--min-compliance` to set a minimum acceptable compliance level. The command will exit with code 1 if the data falls below the threshold:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "436bcc73",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-12-07T04:07:49.046774Z",
     "iopub.status.busy": "2025-12-07T04:07:49.046618Z",
     "iopub.status.idle": "2025-12-07T04:07:49.347235Z",
     "shell.execute_reply": "2025-12-07T04:07:49.346932Z"
    },
    "papermill": {
     "duration": 0.304281,
     "end_time": "2025-12-07T04:07:49.347987",
     "exception": false,
     "start_time": "2025-12-07T04:07:49.043706",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Compliance Report: /tmp/disease_good.yaml\n",
      "Target Class: Disease\n",
      "Global Compliance: 100.0% (3/3)\n",
      "Weig"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hted Compliance: 100.0%\n",
      "\n",
      "Summary by Slot:\n",
      "  description: 100.0%\n",
      "  ontology_id: 100.0%\n",
      "  synonyms: 10"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.0%\n",
      "\n",
      "Detailed Path Scores:\n",
      "  (root) (Disease): 100.0%\n",
      "    - description: OK\n",
      "    - synonyms: OK\n",
      "    "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "- ontology_id: OK\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Exit code: 0\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "# This should pass (100% >= 50%)\n",
    "linkml-data-qc /tmp/disease_good.yaml \\\n",
    "    -s /tmp/disease_schema.yaml \\\n",
    "    -t Disease \\\n",
    "    --min-compliance 50\n",
    "\n",
    "echo \"Exit code: $?\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "c8be433d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-12-07T04:07:49.353275Z",
     "iopub.status.busy": "2025-12-07T04:07:49.353155Z",
     "iopub.status.idle": "2025-12-07T04:07:49.654009Z",
     "shell.execute_reply": "2025-12-07T04:07:49.653662Z"
    },
    "papermill": {
     "duration": 0.304247,
     "end_time": "2025-12-07T04:07:49.654724",
     "exception": false,
     "start_time": "2025-12-07T04:07:49.350477",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Compliance Report: /tmp/disease_poor.yaml\n",
      "Target Class: Disease\n",
      "Global Compliance: 0.0% (0/3)\n",
      "Weight"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ed Compliance: 100.0%\n",
      "\n",
      "Summary by Slot:\n",
      "  description: 0.0%\n",
      "  ontology_id: 0.0%\n",
      "  synonyms: 0.0%\n",
      "\n",
      "De"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tailed Path Scores:\n",
      "  (root) (Disease): 0.0%\n",
      "    - description: MISSING\n",
      "    - synonyms: MISSING\n",
      "    "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "- ontology_id: MISSING\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Compliance 0.0% is below threshold 50.0%\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Exit code: 1\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "# This should fail (0% < 50%)\n",
    "linkml-data-qc /tmp/disease_poor.yaml \\\n",
    "    -s /tmp/disease_schema.yaml \\\n",
    "    -t Disease \\\n",
    "    --min-compliance 50 || echo \"Exit code: $?\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3ae5c309",
   "metadata": {
    "papermill": {
     "duration": 0.002528,
     "end_time": "2025-12-07T04:07:49.659983",
     "exception": false,
     "start_time": "2025-12-07T04:07:49.657455",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Saving Output to a File\n",
    "\n",
    "Use `-o` to write the report to a file:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e15c6df5",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-12-07T04:07:49.665593Z",
     "iopub.status.busy": "2025-12-07T04:07:49.665460Z",
     "iopub.status.idle": "2025-12-07T04:07:49.976035Z",
     "shell.execute_reply": "2025-12-07T04:07:49.975693Z"
    },
    "papermill": {
     "duration": 0.314928,
     "end_time": "2025-12-07T04:07:49.977354",
     "exception": false,
     "start_time": "2025-12-07T04:07:49.662426",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Report written to /tmp/compliance_report.json\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Report saved. Contents:\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"file_path\": \"/tmp/disease_good.yaml\",\n",
      "  \"target_class\": \"Disease\",\n",
      "  \"schema_path\": \"/tmp/disea"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "se_schema.yaml\",\n",
      "  \"global_compliance\": 100.0,\n",
      "  \"weighted_compliance\": 100.0,\n",
      "  \"total_checks\": 3,\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  \"total_populated\": 3,\n",
      "  \"path_scores\": [\n",
      "    {\n",
      "      \"path\": \"(root)\",\n",
      "      \"parent_class\": \"Dise"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ase\",\n",
      "      \"item_count\": 1,\n",
      "      \"slot_scores\": [\n",
      "        {\n",
      "          \"path\": \"(root)\",\n",
      "          "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\"slot_name\": \"description\",\n",
      "          \"populated\": 1,\n",
      "          \"total\": 1,\n",
      "          \"percentage\": "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100.0\n",
      "        },\n",
      "        {\n",
      "          \"path\": \"(root)\",\n",
      "          \"slot_name\": \"synonyms\",\n",
      "          "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\"populated\": 1,\n",
      "          \"total\": 1,\n",
      "          \"percentage\": 100.0\n",
      "        },\n",
      "        {\n",
      "          \""
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "path\": \"(root)\",\n",
      "          \"slot_name\": \"ontology_id\",\n",
      "          \"populated\": 1,\n",
      "          \"total\": "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1,\n",
      "          \"percentage\": 100.0\n",
      "        }\n",
      "      ],\n",
      "      \"overall_percentage\": 100.0\n",
      "    }\n",
      "  ],\n",
      "  \""
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "aggregated_scores\": [],\n",
      "  \"threshold_violations\": [],\n",
      "  \"summary_by_slot\": {\n",
      "    \"description\": 100."
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0,\n",
      "    \"synonyms\": 100.0,\n",
      "    \"ontology_id\": 100.0\n",
      "  },\n",
      "  \"recommended_slots\": [\n",
      "    \"description\",\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    \"ontology_id\",\n",
      "    \"synonyms\"\n",
      "  ],\n",
      "  \"config_path\": null,\n",
      "  \"timestamp\": \"2025-12-06T20:07:49.93"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5050\"\n",
      "}"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "linkml-data-qc /tmp/disease_good.yaml \\\n",
    "    -s /tmp/disease_schema.yaml \\\n",
    "    -t Disease \\\n",
    "    -f json \\\n",
    "    -o /tmp/compliance_report.json\n",
    "\n",
    "echo \"Report saved. Contents:\"\n",
    "cat /tmp/compliance_report.json"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b2c0139",
   "metadata": {
    "papermill": {
     "duration": 0.002888,
     "end_time": "2025-12-07T04:07:49.983222",
     "exception": false,
     "start_time": "2025-12-07T04:07:49.980334",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Next Steps\n",
    "\n",
    "- Learn about [configuration files](../how-to/configuration.md) for weights and thresholds\n",
    "- Set up [CI/CD integration](../how-to/ci-integration.md)\n",
    "- Explore the [Python API](02_python_api.ipynb) for programmatic access"
   ]
  }
 ],
 "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.12.9"
  },
  "papermill": {
   "default_parameters": {},
   "duration": 5.213566,
   "end_time": "2025-12-07T04:07:50.101436",
   "environment_variables": {},
   "exception": null,
   "input_path": "docs/notebooks/01_getting_started.ipynb",
   "output_path": "docs/notebooks/01_getting_started.ipynb",
   "parameters": {},
   "start_time": "2025-12-07T04:07:44.887870",
   "version": "2.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}