77 lines
2.7 KiB
Plaintext
77 lines
2.7 KiB
Plaintext
#!/usr/bin/env nextflow
|
|
|
|
nextflow.enable.dsl=2
|
|
|
|
// Default parameters
|
|
params.disease_name = "Diabetes" // Default disease name
|
|
params.output_dir = "output" // Output directory
|
|
params.modules_dir = "modules" // Directory for module files
|
|
|
|
// Process to generate synthetic patients
|
|
process generatePatients {
|
|
publishDir "${params.output_dir}/${params.disease_name.toLowerCase().replaceAll(' ', '_')}", mode: 'copy'
|
|
|
|
input:
|
|
path moduleFile
|
|
|
|
output:
|
|
path "**"
|
|
|
|
script:
|
|
"""
|
|
echo "Module file: ${moduleFile}"
|
|
echo "Disease: ${params.disease_name}"
|
|
|
|
# Check if Docker is available
|
|
if command -v docker &>/dev/null; then
|
|
echo "Docker is available, looking for Synthea container..."
|
|
|
|
# Find the Synthea container
|
|
container_id=\$(docker ps --format '{{.ID}}' --filter "name=synthea" | head -1)
|
|
|
|
if [ -n "\$container_id" ]; then
|
|
echo "Using Synthea container \$container_id"
|
|
|
|
# Copy module to container
|
|
docker exec \$container_id mkdir -p /app/modules
|
|
docker cp "${moduleFile}" \$container_id:/app/modules/
|
|
|
|
# Run Synthea with minimal parameters
|
|
docker exec \$container_id bash -c "cd /app && ./run_synthea -p 1 -m ${params.disease_name.toLowerCase().replaceAll(' ', '_')}"
|
|
|
|
# Copy output from container
|
|
docker cp \$container_id:/app/output/fhir ./ || mkdir -p ./fhir
|
|
docker cp \$container_id:/app/output/metadata ./ || mkdir -p ./metadata
|
|
|
|
echo "Completed patient generation"
|
|
else
|
|
echo "No Synthea container found, creating mock output for testing"
|
|
mkdir -p ./fhir ./metadata
|
|
echo "Mock FHIR data for ${params.disease_name}" > ./fhir/mock_patient.json
|
|
echo "Mock metadata for ${params.disease_name}" > ./metadata/mock_stats.json
|
|
fi
|
|
else
|
|
echo "Docker not available, creating mock output for testing"
|
|
mkdir -p ./fhir ./metadata
|
|
echo "Mock FHIR data for ${params.disease_name}" > ./fhir/mock_patient.json
|
|
echo "Mock metadata for ${params.disease_name}" > ./metadata/mock_stats.json
|
|
fi
|
|
"""
|
|
}
|
|
|
|
// Define workflow
|
|
workflow {
|
|
// Prepare module file
|
|
moduleFilename = params.disease_name.toLowerCase().replaceAll(' ', '_') + '.json'
|
|
moduleFile = file("${params.modules_dir}/${moduleFilename}")
|
|
|
|
if (!moduleFile.exists()) {
|
|
error "Module file not found: ${moduleFile}"
|
|
}
|
|
|
|
// Create a channel with the module file
|
|
moduleChannel = Channel.fromPath(moduleFile)
|
|
|
|
// Generate patients
|
|
generatePatients(moduleChannel)
|
|
} |