|
| 1 | +#!/usr/bin/env nextflow |
| 2 | + |
| 3 | +/* Squonk Nextflow pipline that runs Docking using rDock, filtering the poses relative to the score from docking the |
| 4 | +* reference ligand. |
| 5 | +* |
| 6 | +* To test this manually run something like this: |
| 7 | +* nextflow -c src/nextflow/nextflow-docker.config run src/nextflow/docking/rdock-filter.nsd.nf --ligands data/nudt7/ligands.data.gz --ligand data/nudt7/ligand.mol --receptor data/nudt7/receptor.mol2 --num_dockings 5 -with-docker informaticsmatters/rdkit_pipelines |
| 8 | +*/ |
| 9 | + |
| 10 | +params.ligand = "$baseDir/ligand.mol" |
| 11 | +params.ligands = "$baseDir/ligands.data.gz" |
| 12 | +params.receptor = "$baseDir/receptor.mol2" |
| 13 | +params.chunk = 25 |
| 14 | +params.num_dockings = 25 |
| 15 | +params.top = 1 |
| 16 | +params.score = null |
| 17 | +params.nscore = null |
| 18 | +params.limit = 0 |
| 19 | +params.digits = 4 |
| 20 | +params.threshold = 0.0 |
| 21 | +params.field = 'SCORE.norm' |
| 22 | + |
| 23 | +ligand = file(params.ligand) |
| 24 | +ligands = file(params.ligands) |
| 25 | +receptor = file(params.receptor) |
| 26 | + |
| 27 | +process create_cavity { |
| 28 | + |
| 29 | + container 'informaticsmatters/rdock-mini:latest' |
| 30 | + beforeScript 'chmod g+w .' |
| 31 | + |
| 32 | + input: |
| 33 | + file ligand |
| 34 | + file receptor |
| 35 | + |
| 36 | + output: |
| 37 | + file 'receptor.prm' into prmfile |
| 38 | + file 'receptor.as' into asfile |
| 39 | + |
| 40 | + """ |
| 41 | + cat << EOF > receptor.prm |
| 42 | +RBT_PARAMETER_FILE_V1.00 |
| 43 | +RECEPTOR_FILE $receptor |
| 44 | +RECEPTOR_FLEX 3.0 |
| 45 | +SECTION MAPPER |
| 46 | + SITE_MAPPER RbtLigandSiteMapper |
| 47 | + REF_MOL $ligand |
| 48 | + RADIUS 3.0 |
| 49 | + SMALL_SPHERE 1.0 |
| 50 | + MIN_VOLUME 100 |
| 51 | + MAX_CAVITIES 1 |
| 52 | + VOL_INCR 0.0 |
| 53 | + GRIDSTEP 0.5 |
| 54 | +END_SECTION |
| 55 | +SECTION CAVITY |
| 56 | + SCORING_FUNCTION RbtCavityGridSF |
| 57 | + WEIGHT 1.0 |
| 58 | +END_SECTION |
| 59 | +EOF |
| 60 | +
|
| 61 | +rbcavity -was -d -r receptor.prm > rbcavity.log |
| 62 | + """ |
| 63 | +} |
| 64 | + |
| 65 | +/* Docks the reference ligand |
| 66 | +*/ |
| 67 | +process dock_reference_ligand { |
| 68 | + |
| 69 | + container 'informaticsmatters/rdock-mini:latest' |
| 70 | + beforeScript 'chmod g+w .' |
| 71 | + |
| 72 | + publishDir "$baseDir/results", mode: 'copy' |
| 73 | + |
| 74 | + input: |
| 75 | + file receptor |
| 76 | + file 'receptor.as' from asfile |
| 77 | + file 'receptor.prm' from prmfile |
| 78 | + file ligand |
| 79 | + |
| 80 | + output: |
| 81 | + file 'best_ligand.sdf' into best_ligand |
| 82 | + |
| 83 | + """ |
| 84 | + rbdock -i ligand.mol -r receptor.prm -p dock.prm -n $params.num_dockings -o docked_ligand > docked_ligand_out.log |
| 85 | + sdsort -n -s -fSCORE docked_ligand.sd | sdfilter -f'\$_COUNT <= 1' > best_ligand.sdf |
| 86 | + """ |
| 87 | +} |
| 88 | + |
| 89 | +/* Splits the input into multiple files of ${params.chunk} records. |
| 90 | +*/ |
| 91 | +process splitter { |
| 92 | + |
| 93 | + //beforeScript 'chmod g+w .' |
| 94 | + container 'informaticsmatters/rdkit_pipelines:latest' |
| 95 | + |
| 96 | + input: |
| 97 | + file ligands |
| 98 | + |
| 99 | + output: |
| 100 | + file 'ligands_part*.sdf' into ligands_parts mode flatten |
| 101 | + file 'ligands_part_metrics.txt' into splitter_metrics |
| 102 | + |
| 103 | + """ |
| 104 | + python -m pipelines_utils_rdkit.filter -i $ligands -c $params.chunk -l $params.limit -d $params.digits -o ligands_part -of sdf --no-gzip --meta |
| 105 | + """ |
| 106 | +} |
| 107 | + |
| 108 | +/* Docks each file from the ligands_parts channel sending each resulting SD file to the results channel |
| 109 | +*/ |
| 110 | +process dock_ligands { |
| 111 | + |
| 112 | + container 'informaticsmatters/rdock-mini:latest' |
| 113 | + // change permissions on the work dir so that the rdock user in the container |
| 114 | + // can write to the directory that is owned by root |
| 115 | + beforeScript 'chmod g+w .' |
| 116 | + |
| 117 | + input: |
| 118 | + file part from ligands_parts |
| 119 | + file receptor |
| 120 | + file 'receptor.as' from asfile |
| 121 | + file 'receptor.prm' from prmfile |
| 122 | + |
| 123 | + output: |
| 124 | + file 'docked_part*.sd' into docked_parts |
| 125 | + |
| 126 | + """ |
| 127 | + rbdock -i $part -r receptor.prm -p dock.prm -n $params.num_dockings -o ${part.name.replace('ligands', 'docked')[0..-5]} > docked_out.log |
| 128 | + """ |
| 129 | +} |
| 130 | + |
| 131 | +/* Filter, combine and publish the results. |
| 132 | +* Poses are only included if they are within ${params.threshold} of the best score obtained from docking the |
| 133 | +* target ligand into the same receptor (output of the dock_ligand process). |
| 134 | +*/ |
| 135 | +process combine_and_filter { |
| 136 | + |
| 137 | + container 'informaticsmatters/rdock-mini:latest' |
| 138 | + beforeScript 'chmod g+w .' |
| 139 | + |
| 140 | + input: |
| 141 | + file parts from docked_parts.collect() |
| 142 | + file best from best_ligand |
| 143 | + |
| 144 | + output: |
| 145 | + file 'rdock_results.sdf' into results |
| 146 | + |
| 147 | + """ |
| 148 | + FSCORE=\$(sdreport -nh -t${params.field} best_ligand.sdf | cut -f 2 | awk '{\$1=\$1};1') |
| 149 | + ASCORE=\$(awk "BEGIN {print \$FSCORE + ${params.threshold}}") |
| 150 | + echo "Processing $parts with normalised score filter of \$ASCORE" |
| 151 | + sdsort -n -s -f${params.field} docked_part*.sd | sdfilter -f"\\\$${params.field} < \$ASCORE" | sdfilter -f'\$_COUNT <= ${params.top}' > rdock_results.sdf |
| 152 | + """ |
| 153 | +} |
| 154 | + |
| 155 | +process results { |
| 156 | + |
| 157 | + beforeScript 'chmod g+w .' |
| 158 | + container 'informaticsmatters/rdkit_pipelines:latest' |
| 159 | + beforeScript 'chmod g+w .' |
| 160 | + |
| 161 | + publishDir "$baseDir/results", mode: 'copy' |
| 162 | + |
| 163 | + input: |
| 164 | + file 'results.sdf' from results |
| 165 | + file 'splitter_metrics.txt' from splitter_metrics |
| 166 | + |
| 167 | + output: |
| 168 | + file 'output.data.gz' |
| 169 | + file 'output.metadata' |
| 170 | + file 'output_metrics.txt' |
| 171 | + |
| 172 | + """ |
| 173 | + python -m pipelines_utils_rdkit.filter -i results.sdf -of json -o output --meta |
| 174 | + mv output_metrics.txt old_metrics.txt |
| 175 | + echo -n 'DockingRDock=' >> output_metrics.txt |
| 176 | + echo \$((`grep '__InputCount__' splitter_metrics.txt | cut -d '=' -f 2` * ${params.num_dockings})) >> output_metrics.txt |
| 177 | + grep '__InputCount__' splitter_metrics.txt >> output_metrics.txt |
| 178 | + grep '__OutputCount__' old_metrics.txt >> output_metrics.txt |
| 179 | + """ |
| 180 | +} |
0 commit comments