{
  "name": "sc26-blast-gene-search",
  "display_name": "SC26 BLAST+ sequence search",
  "summary": "Build a small nucleotide database of 40 synthetic 'gene' sequences, BLAST three mutated reads against it with NCBI BLAST+ in a container, and report the top hits.",
  "containers": [
    "ncbi-blast/2026.09"
  ],
  "steps": [
    {
      "id": "s1",
      "kind": "slurm-cpu",
      "name": "make-data",
      "script": "jobs/s1.sh",
      "after": [],
      "container": "",
      "use_slurm": false,
      "copies": [],
      "shape": {
        "cpus": 2,
        "mem": "4G",
        "nodes": 1
      }
    },
    {
      "id": "s2",
      "kind": "slurm-cpu",
      "name": "blastn",
      "script": "jobs/s2.sh",
      "after": [
        "s1"
      ],
      "container": "ncbi-blast/2026.09",
      "use_slurm": false,
      "copies": [],
      "shape": {
        "cpus": 2,
        "mem": "4G",
        "nodes": 1
      }
    },
    {
      "id": "s3",
      "kind": "slurm-cpu",
      "name": "report",
      "script": "jobs/s3.sh",
      "after": [
        "s2"
      ],
      "container": "",
      "use_slurm": false,
      "copies": [],
      "shape": {
        "cpus": 2,
        "mem": "4G",
        "nodes": 1
      }
    }
  ],
  "spans": [],
  "files": {
    "jobs/s1.sh": "#!/bin/bash\nset -euo pipefail\nmkdir -p results\n# 40 synthetic 600-bp \"genes\" (fixed seed, reproducible) + 3 reads copied from genes 7, 19, 33 with ~3% mutations\nawk 'BEGIN{srand(2026); b=\"ACGT\"; for(g=1;g<=40;g++){s=\"\"; for(i=0;i<600;i++) s=s substr(b,int(rand()*4)+1,1); printf(\">gene_%02d synthetic demo gene %d\\n%s\\n\",g,g,s) > \"genes.fa\"; seq[g]=s}\n  split(\"7 19 33\",pick,\" \"); for(k=1;k<=3;k++){g=pick[k]; r=substr(seq[g],101,300); o=\"\"; for(i=1;i<=300;i++){c=substr(r,i,1); if(rand()<0.03) c=substr(b,int(rand()*4)+1,1); o=o c} printf(\">read_%d from_gene_%02d\\n%s\\n\",k,g,o) > \"reads.fa\"}}'\ngrep -c '>' genes.fa reads.fa\n",
    "jobs/s2.sh": "#!/bin/bash\nset -euo pipefail\napptainer exec /tmp/image.sif blastn -version | head -1\napptainer exec /tmp/image.sif makeblastdb -in genes.fa -dbtype nucl -out genesdb -title \"SC26 demo genes\"\napptainer exec /tmp/image.sif blastn -query reads.fa -db genesdb -evalue 1e-10 -max_target_seqs 3 \\\n  -outfmt \"6 qseqid sseqid pident length mismatch evalue bitscore\" -out blast.tsv\ncat blast.tsv\n",
    "jobs/s3.sh": "#!/bin/bash\nset -euo pipefail\npublish() { d=/vault/projects/sc26genomics/sc26-results/blast/$(date -u +%Y%m%dT%H%M%SZ); mkdir -p \"$d\" 2>/dev/null && cp -r results/. \"$d/\" 2>/dev/null && echo \"published to $d\" || echo \"results kept in $PWD/results\"; }\nmkdir -p results\n{ printf 'query\\tsubject\\tpct_identity\\tlength\\tmismatches\\tevalue\\tbitscore\\n'; cat blast.tsv; } > results/blast_hits.tsv\n{ echo \"SC26 BLAST+ demo: best hit per read\"; sort -k1,1 -k7,7nr blast.tsv | awk '!seen[$1]++{printf \"%s -> %s  %.1f%% identity over %s bp (bitscore %s)\\n\",$1,$2,$3,$4,$7}'; } | tee results/summary.txt\ncp genes.fa reads.fa results/\ntest \"$(awk '!seen[$1]++' blast.tsv | wc -l)\" -eq 3\npublish\n"
  }
}
