| 1 | #!/usr/bin/env perl | ||
| 2 | # PODNAME: yaml-generator-42.pl | ||
| 3 | # ABSTRACT: Interactive or batch generator for 42 YAML config files | ||
| 4 | # CONTRIBUTOR: Mick VAN VLIERBERGHE <mvanvlierberghe@doct.uliege.be> | ||
| 5 | |||
| 6 | # TODO: add support for wordsize (default 3) in BRH phase? | ||
| 7 | # TODO: optimize vertical spacing in output (very tricky) | ||
| 8 | |||
| 9 | use autodie; | ||
| 10 | use Modern::Perl '2011'; | ||
| 11 | |||
| 12 | use Smart::Comments '###'; | ||
| 13 | use Getopt::Euclid qw(:vars); | ||
| 14 | |||
| 15 | use Template; | ||
| 16 | use Path::Class qw(dir file); | ||
| 17 | use Tie::IxHash; | ||
| 18 | use List::AllUtils qw(mesh); | ||
| 19 | use File::Basename; | ||
| 20 | use File::Find::Rule; | ||
| 21 | |||
| 22 | use Bio::MUST::Core; | ||
| 23 | use aliased 'Bio::MUST::Core::IdList'; | ||
| 24 | use aliased 'Bio::MUST::Core::IdMapper'; | ||
| 25 | use aliased 'Bio::MUST::Core::SeqId'; | ||
| 26 | use aliased 'Bio::MUST::Core::Taxonomy'; | ||
| 27 | use Bio::FastParsers::Constants qw(:files); | ||
| 28 | |||
| 29 | use Term::Completion::Path; | ||
| 30 | use IO::Prompter [ | ||
| 31 | -verbatim, | ||
| 32 | -style => 'blue strong ', | ||
| 33 | -must => { 'be a string' => qr{\S+} } | ||
| 34 | ]; | ||
| 35 | # bold => [qw<boldly strong heavy emphasis emphatic highlight highlighted fort forte>], | ||
| 36 | # dark => [qw<darkly dim deep>], | ||
| 37 | # faint => [qw<faintly light soft>], | ||
| 38 | # underline => [qw<underlined underscore underscored italic italics>], | ||
| 39 | # blink => [qw<blinking flicker flickering flash flashing>], | ||
| 40 | # reverse => [qw<reversed inverse inverted>], | ||
| 41 | # concealed => [qw<hidden blank invisible>], | ||
| 42 | # reset => [qw<normal default standard usual ordinary regular>], | ||
| 43 | # bright_ => [qw< bright\s+ vivid\s+ >], | ||
| 44 | # red => [qw< scarlet vermilion crimson ruby cherry cerise cardinal carmine | ||
| 45 | # burgundy claret chestnut copper garnet geranium russet | ||
| 46 | # salmon titian coral cochineal rose cinnamon ginger gules >], | ||
| 47 | # yellow => [qw< gold golden lemon cadmium daffodil mustard primrose tawny | ||
| 48 | # amber aureate canary champagne citrine citron cream goldenrod honey straw >], | ||
| 49 | # green => [qw< olive jade pea emerald lime chartreuse forest sage vert >], | ||
| 50 | # cyan => [qw< aqua aquamarine teal turquoise ultramarine >], | ||
| 51 | # blue => [qw< azure cerulean cobalt indigo navy sapphire >], | ||
| 52 | # magenta => [qw< amaranthine amethyst lavender lilac mauve mulberry orchid periwinkle | ||
| 53 | # plum pomegranate violet purple aubergine cyclamen fuchsia modena puce | ||
| 54 | # purpure >], | ||
| 55 | # black => [qw< charcoal ebon ebony jet obsidian onyx raven sable slate >], | ||
| 56 | # white => [qw< alabaster ash chalk ivory milk pearl silver argent >], | ||
| 57 | |||
| 58 | # TODO: check whether all IF/ELSE directives are needed in template pour tax_ args | ||
| 59 | # TODO: check if ali_* options are needed when aligner_mode=off | ||
| 60 | # TODO: check tax_* options that should be present when megan etc is on | ||
| 61 | |||
| 62 | # define config file template | ||
| 63 | my $tt_str = <<'EOT'; | ||
| 64 | # ===Run mode=== | ||
| 65 | # Two values are available: 'phylogenomic' and 'metagenomic'. | ||
| 66 | # The phylogenomic mode is designed to enrich multiple sequence alignements | ||
| 67 | # (ALIs) with orthologues for subsequent phylogenomic analysis. In contrast, | ||
| 68 | # the metagenomic mode is designed to probe contamination in transcriptomic | ||
| 69 | # data using reference ribosomal protein ALIs; it produces a taxonomic report | ||
| 70 | # per ALI listing the lineage of each identified orthologous sequence. | ||
| 71 | # When not specified, 'run_mode' internally defaults to 'phylogenomic'. | ||
| 72 | run_mode: [% run_mode %] | ||
| 73 | |||
| 74 | # ===Suffix to append to infile basenames for deriving outfile names=== | ||
| 75 | # When not specified 'outsuffix' internally defaults to '-42'. | ||
| 76 | # Use a bare 'out_suffix:' to reuse the ALI name and to preserve the original | ||
| 77 | # file by appending a .bak extension to its name. | ||
| 78 | out_suffix: [% out_suffix %] | ||
| 79 | |||
| 80 | # ===Orgs from where to select BLAST queries=== | ||
| 81 | # Depending on availability at least one query by family and by org will be | ||
| 82 | # picked for the 'homologues' and 'references' BLAST rounds. | ||
| 83 | query_orgs:[% FOREACH org IN query_orgs.sort %] | ||
| 84 | - [% org %][% END %] | ||
| 85 | |||
| 86 | # ===Optional args for each BLAST step=== | ||
| 87 | # Any valid command-line option can be specified (see NCBIBLAST+ docs). | ||
| 88 | # Note the hyphens (-) before option names (departing from API consistency). | ||
| 89 | # -query, -db, -out, -outfmt, -db_gencode, -query_gencode will be ignored as | ||
| 90 | # they are directly handled by forty-two itself. -max_target_seqs may be | ||
| 91 | # specified at step 'homologues' to speed up things. | ||
| 92 | blast_args: | ||
| 93 | # TBLASTN vs banks | ||
| 94 | homologues: | ||
| 95 | -evalue: [% evalue %] | ||
| 96 | [% UNLESS SSUrRNA ~%] | ||
| 97 | -seg: [% homologues_seg %] | ||
| 98 | [% END ~%] | ||
| 99 | -num_threads: 1 | ||
| 100 | -max_target_seqs: [% max_target_seqs %] | ||
| 101 | [%- IF ref_brh == 'on' %] | ||
| 102 | # BLASTP vs ref banks (for transitive BRH ; actually two steps) | ||
| 103 | references: | ||
| 104 | -evalue: [% evalue %] | ||
| 105 | -num_threads: 1 | ||
| 106 | # BLASTX vs ref banks (for transitive BRH) | ||
| 107 | orthologues: | ||
| 108 | -evalue: [% evalue %] | ||
| 109 | -num_threads: 1[% END %] | ||
| 110 | # BLASTX vs ALI (for tax filters and alignment) | ||
| 111 | templates: | ||
| 112 | -evalue: [% evalue %] | ||
| 113 | [% UNLESS SSUrRNA ~%] | ||
| 114 | -seg: [% templates_seg %] | ||
| 115 | [% END ~%] | ||
| 116 | -num_threads: 1 | ||
| 117 | |||
| 118 | # ===BRH switch for assessing orthology=== | ||
| 119 | # Two values are available: 'on' and 'off'. | ||
| 120 | # If set to 'on', a candidate seq must be in BRH with all reference proteomes | ||
| 121 | # to be considered as an orthologous seq. In contrast, all candidate seqs are | ||
| 122 | # considered as orthologous seqs when this parameter is set to 'off'. | ||
| 123 | # When not specified, 'ref_brh' internally defaults to 'on'. | ||
| 124 | # To limit the number of candidate seqs, use the '-max_target_seqs' option of | ||
| 125 | # the BLAST executable(s) at the 'homologues' step. | ||
| 126 | ref_brh: [% ref_brh %] | ||
| 127 | |||
| 128 | [% IF ref_brh == 'on' -%] | ||
| 129 | # ===Path to dir holding complete proteome BLAST databases=== | ||
| 130 | # Only required when setting 'ref_brh' to 'on'. | ||
| 131 | ref_bank_dir: [% ref_bank_dir %] | ||
| 132 | |||
| 133 | # ===Basenames of complete proteome BLAST databases (keyed by org name)=== | ||
| 134 | # Only required when setting 'ref_brh' to 'on'. | ||
| 135 | # You can list as many databases as needed here. Only those specified as | ||
| 136 | # 'ref_orgs' below will actually be used for BRH. | ||
| 137 | ref_org_mapper:[% FOREACH bank IN ref_org_for.keys.sort %] | ||
| 138 | [% ref_org_for.$bank %]: [% bank %][% END %] | ||
| 139 | |||
| 140 | # ===Orgs to be used for BRH checks=== | ||
| 141 | # Only required when setting 'ref_brh' to 'on'. | ||
| 142 | # To be considered as an orthologue, a candidate seq must be in transitive BRH | ||
| 143 | # for all listed orgs (and not for only one of them). Listing more orgs thus | ||
| 144 | # increases the stringency of the BRH check. Note that 'ref_orgs' may but DO | ||
| 145 | # NOT NEED to match 'query_orgs'. | ||
| 146 | ref_orgs:[% FOREACH bank IN ref_org_for.keys.sort %] | ||
| 147 | - [% ref_org_for.$bank %][% END %] | ||
| 148 | |||
| 149 | # ===Fraction of ref_orgs to really use when assessing orthology=== | ||
| 150 | # Only meaningful when setting 'ref_brh' to 'on'. | ||
| 151 | # This parameter introduces some flexibility when using reference proteomes. | ||
| 152 | # If set to a fractional value (below 1), only the best proteomes will be | ||
| 153 | # considered during BRHs. The best proteomes are those against which the | ||
| 154 | # queries have the highest average scores. This helps discarding ref_orgs that | ||
| 155 | # might hinder orthology assessment because they lack the orthologous gene(s). | ||
| 156 | # When not specified, 'reg_org_mul' internally defaults to 1.0, which is the | ||
| 157 | # strictest mode since all reference proteomes are used during BRHs. | ||
| 158 | ref_org_mul: [% ref_org_mul %] | ||
| 159 | |||
| 160 | # ===Bit score reduction allowed when including non-1st hits among best hits=== | ||
| 161 | # Only meaningful when setting 'ref_brh' to 'on'. | ||
| 162 | # This parameter applies when collecting best hits for queries to complete | ||
| 163 | # proteomes, so that close in-paralogues can all be included in the set of | ||
| 164 | # best hits. The allowed bit score reduction of any hit is expressed | ||
| 165 | # relatively to the score of the previous hit. During BRH checks, only the | ||
| 166 | # very first hit for the candidate seq is actually tested for inclusion in | ||
| 167 | # this set but for all complete proteomes. By default at most 10 hits are | ||
| 168 | # considered. To change this, use the '-max_target_seqs' option of the BLAST | ||
| 169 | # executable(s) at the 'reference' step. | ||
| 170 | # When not specified 'ref_score_mul' internally defaults to 1.0, which is the | ||
| 171 | # strictest mode since only equally-best hits are retained. | ||
| 172 | ref_score_mul: [% ref_score_mul %] | ||
| 173 | [% END -%] | ||
| 174 | |||
| 175 | [% IF tol_check == 'on' -%] | ||
| 176 | # ===TreeOfLife check=== | ||
| 177 | # | ||
| 178 | # | ||
| 179 | tol_check: [% tol_check %] | ||
| 180 | |||
| 181 | # ===Path to TreeOfLife database=== | ||
| 182 | # | ||
| 183 | # | ||
| 184 | tol_bank_dir: [% tol_bank_dir %] | ||
| 185 | tol_bank: [% tol_bank %] | ||
| 186 | [% END -%] | ||
| 187 | |||
| 188 | # ===Homologues trimming switch=== | ||
| 189 | # Two values are available: 'on' and 'off'. | ||
| 190 | # If set to 'on', each candidate seq is first trimmed to the range covered by | ||
| 191 | # the HSPs that retrieved it. This makes the orthology assessment more robust | ||
| 192 | # and helps exonerate to splice genes correctly. The details of this trimming | ||
| 193 | # step can be fine-tuned by editing the other trim_* parameters of this | ||
| 194 | # configuration file. | ||
| 195 | # When not specified, 'trim_homologues' internally defaults to 'on'. | ||
| 196 | trim_homologues: [% trim_homologues %] | ||
| 197 | |||
| 198 | [% IF trim_homologues == 'on' -%] | ||
| 199 | # ===Max distance between HSPs allowed when defining a hit range=== | ||
| 200 | # Only meaningful when setting 'trim_homologues' to 'on'. | ||
| 201 | # HSPs define ranges that will be used to extract one or more candidate seq(s) | ||
| 202 | # from each hit. Before extraction, neighboring ranges are merged if they lie | ||
| 203 | # at max this distance (in nt) apart. This distance can thus be seen as the | ||
| 204 | # max length allowed for an intron within a gene to be added. | ||
| 205 | # When not specified 'trim_max_shift' internally defaults to 20000 nt. | ||
| 206 | trim_max_shift: [% trim_max_shift %] | ||
| 207 | |||
| 208 | # ===Extra margin to hit range=== | ||
| 209 | # Only meaningful when setting 'trim_homologues' to 'on'. | ||
| 210 | # Since HSPs can sometimes miss the beginning or end of the best hit, this | ||
| 211 | # parameter extends the range of the candidate seq to be extracted at both | ||
| 212 | # extremities (in nt) to allow for a potentially more complete seq. | ||
| 213 | # When not specified 'trim_extra_margin' internally defaults to 15 nt. | ||
| 214 | trim_extra_margin: [% trim_extra_margin %] | ||
| 215 | [% END -%] | ||
| 216 | |||
| 217 | # ===Orthologues merging switch=== | ||
| 218 | # Two values are available: 'on' and 'off'. | ||
| 219 | # If set to 'on', each batch of orthologous seqs from the same org is first | ||
| 220 | # fed to CAP3 in an attempt to merge some of them into contigs. Successfully | ||
| 221 | # merged orthologous seqs are identified by a trailing +N tag where N is the | ||
| 222 | # number of orthologous seqs removed in the merging process. The contig itself | ||
| 223 | # is named after the longest orthologous seq composing it. | ||
| 224 | # The details of this merging step can be fine-tuned by editing the other | ||
| 225 | # merge_* parameters of this configuration file. | ||
| 226 | # When not specified, 'merge_orthologues' internally defaults to 'off'. | ||
| 227 | # The YAML wizard automatically sets it to 'off' if 'run_mode' is 'metagenomic'. | ||
| 228 | merge_orthologues: [% merge_orthologues %] | ||
| 229 | |||
| 230 | [% IF merge_orthologues == 'on' -%] | ||
| 231 | # ===Min identity in overlap for merging two orthologous seqs=== | ||
| 232 | # Only meaningful when setting 'merge_orthologues' to 'on'. | ||
| 233 | # This parameter is the CAP3 '-p' parameter except that it is specified as a | ||
| 234 | # fractional number (between 0 and 1). | ||
| 235 | # When not specified, 'merge_min_ident' internally defaults to 0.9 (= 90%). | ||
| 236 | merge_min_ident: [% merge_min_ident %] | ||
| 237 | |||
| 238 | # ===Min length of overlap for merging two orthologous seqs=== | ||
| 239 | # Only meaningful when setting 'merge_orthologues' to 'on'. | ||
| 240 | # This parameter is the CAP3 '-o' parameter (in nt). | ||
| 241 | # When not specified, 'merge_min_len' internally defaults to 40 nt. | ||
| 242 | merge_min_len: [% merge_min_len %] | ||
| 243 | [% END -%] | ||
| 244 | |||
| 245 | # ===Engine to be used for aligning new seqs=== | ||
| 246 | # Four values are available: 'blast', 'exonerate', 'exoblast' and 'off'. | ||
| 247 | # If the alignment engine is 'off', new seqs are added 'as is' to the ALI. | ||
| 248 | # Consequently, they will be full length but not aligned to existing seqs. | ||
| 249 | # This mode is meant for protein seqs only and thus cannot be used when adding | ||
| 250 | # transcripts from nucleotide banks. | ||
| 251 | # The 'exonerate' mode sometimes fails to align orthologous seqs due to a bug | ||
| 252 | # in exonerate executable. This causes new seqs to be lost. To automatically | ||
| 253 | # retry aligning them with BLAST in case of failure, use the 'exoblast' mode. | ||
| 254 | # When not specified, 'aligner_mode' internally defaults to 'blast'. | ||
| 255 | # The YAML wizard automatically sets it to 'off' if 'run_mode' is 'metagenomic'. | ||
| 256 | aligner_mode: [% aligner_mode %] | ||
| 257 | |||
| 258 | [% UNLESS aligner_mode == 'off' -%] | ||
| 259 | # ===Self-template selection switch for aligning new seqs=== | ||
| 260 | # Only meaningful when setting 'aligner_mode' to a value other than 'off'. | ||
| 261 | # Two values are available: 'on' and 'off'. | ||
| 262 | # If set to 'on', closest relatives belonging to the same org as the new seqs | ||
| 263 | # will not be selected as templates, thus allowing the latter to align better. | ||
| 264 | # When not specified, 'ali_skip_self' internally defaults to 'off'. | ||
| 265 | ali_skip_self: [% ali_skip_self %] | ||
| 266 | |||
| 267 | # ===Coverage improvement required to consider non-1st hits as templates=== | ||
| 268 | # Only meaningful when setting 'aligner_mode' to a value other than 'off'. | ||
| 269 | # This parameter applies when collecting templates for aligning the new seqs. | ||
| 270 | # Templates get considered as long as query coverage improves at least of this | ||
| 271 | # value (relatively to the previous template). The exact effect of this | ||
| 272 | # parameter depends on the 'aligner_mode' engine: 'exonerate' will try to use | ||
| 273 | # the longest template for alignment while 'blast' will use each hit in turn | ||
| 274 | # (as a fall-back with 'exoblast'). New seqs can thus be added more than once | ||
| 275 | # to the ALI (with ids *.H1.N, *.H2.N etc). | ||
| 276 | # When not specified 'ali_cover_mul' internally defaults to 1.1., which means | ||
| 277 | # that if the BLAST alignment with the second template is at least 110% of the | ||
| 278 | # BLAST alignment with the first template, both templates are retained. | ||
| 279 | ali_cover_mul: [% ali_cover_mul %] | ||
| 280 | [% END -%] | ||
| 281 | |||
| 282 | # ===Preservation switch for '#NEW#' tags from preexisting sequences=== | ||
| 283 | # Two values are available: 'on' and 'off'. | ||
| 284 | # If set to 'on' (default), #NEW# tags will be preserved. Note that | ||
| 285 | # preexisting new sequences are invisible to 42 (they cannot be used as | ||
| 286 | # queries etc). | ||
| 287 | ali_keep_old_new_tags: [% ali_keep_old_new_tags %] | ||
| 288 | |||
| 289 | # ===Action to perform when a preexisting lengthened seq is identified=== | ||
| 290 | # Currently, two values are available: 'remove' and 'keep'. | ||
| 291 | # The option is quite self-explanatory. It is useful when one runs 42 multiple | ||
| 292 | # times on the sames ALIs to repeatedly enrich the same orgs, assuming that | ||
| 293 | # org banks are updated between runs. | ||
| 294 | # When not specified, 'ali_keep_lengthened_seqs' internally defaults to | ||
| 295 | # 'keep'. | ||
| 296 | ali_keep_lengthened_seqs: [% ali_keep_lengthened_seqs %] | ||
| 297 | |||
| 298 | # ===Taxonomic report switch=== | ||
| 299 | # Two values are available: 'on' and 'off'. | ||
| 300 | # If set to 'on', the lineage of new seqs is inferred by analyzing the | ||
| 301 | # taxonomy of their ALI closest relatives and one '.tax-report' file is | ||
| 302 | # generated for each ALI processed (see 'run_mode' above). | ||
| 303 | # The details of this taxonomic analysis can be fine-tuned by editing the | ||
| 304 | # other tax_* parameters of this configuration file. | ||
| 305 | # When not specified, 'tax_reports' internally defaults to 'off'. Yet, the | ||
| 306 | # The YAML wizard automatically sets it to 'on' if 'run_mode' is 'metagenomic'. | ||
| 307 | [% IF tax_reports -%] | ||
| 308 | tax_reports: [% tax_reports %] | ||
| 309 | [% ELSE -%] | ||
| 310 | tax_reports: on | ||
| 311 | [% END -%] | ||
| 312 | |||
| 313 | [% IF tax_dir -%] | ||
| 314 | # ===Path to dir holding NCBI Taxonomy database=== | ||
| 315 | # Only required when enabling 'tax_reports' or specifying 'tax_filter'. | ||
| 316 | # It can be installed using setup-taxdir.pl. | ||
| 317 | tax_dir: [% tax_dir %] | ||
| 318 | |||
| 319 | # ===Min number of relatives to use when inferring taxonomy of new seqs=== | ||
| 320 | # Only meaningful when enabling 'tax_reports' or specifying 'tax_filter'. | ||
| 321 | # This parameter is a lower bound. The real number will depend both on the | ||
| 322 | # four thresholds below ('tax_min_ident', 'tax_min_len', 'tax_min_score' and | ||
| 323 | # 'tax_score_mul') and on the ability of 42 to deduce the taxonomy of each | ||
| 324 | # individual relative to compute the LCA of the new seq. | ||
| 325 | # When not specified, 'tax_min_hits' internally defaults to 1. | ||
| 326 | [% IF tax_min_hits -%] | ||
| 327 | tax_min_hits: [% tax_min_hits %] | ||
| 328 | [% ELSE -%] | ||
| 329 | tax_min_hits: 1 | ||
| 330 | [% END -%] | ||
| 331 | |||
| 332 | # ===Max number of relatives to use when inferring taxonomy of new seqs=== | ||
| 333 | # Only meaningful when enabling 'tax_reports' or specifying 'tax_filter'. | ||
| 334 | # As for 'tax_min_hits' above, this parameter is a upper bound. | ||
| 335 | # When not specified, 'tax_max_hits' internally defaults to unlimited. | ||
| 336 | [% IF megan_like -%] | ||
| 337 | tax_max_hits: 100 | ||
| 338 | [% ELSIF best_hit -%] | ||
| 339 | tax_max_hits: 1 | ||
| 340 | [% ELSIF tax_max_hits -%] | ||
| 341 | tax_max_hits: [% tax_max_hits %] | ||
| 342 | [% END -%] | ||
| 343 | |||
| 344 | # ===Min identity of relatives to use when inferring taxonomy of new seqs=== | ||
| 345 | # Only meaningful when enabling 'tax_reports' or specifying 'tax_filter'. | ||
| 346 | # This parameter is the traditional BLAST 'percent identity' statistics except | ||
| 347 | # that it is specified as a fractional number (between 0 and 1). It is | ||
| 348 | # evaluated on the first HSP of potential relatives. | ||
| 349 | # When not specified, 'tax_min_ident' internally defaults to 0. | ||
| 350 | [% IF megan_like -%] | ||
| 351 | tax_min_ident: 0 | ||
| 352 | [% ELSIF best_hit -%] | ||
| 353 | tax_min_ident: 0 | ||
| 354 | [% ELSIF tax_min_ident -%] | ||
| 355 | tax_min_ident: [% tax_min_ident %] | ||
| 356 | [% END -%] | ||
| 357 | |||
| 358 | # ===Min length of relatives to use when inferring taxonomy of new seqs=== | ||
| 359 | # Only meaningful when enabling 'tax_reports' or specifying 'tax_filter'. | ||
| 360 | # This parameter is the traditional BLAST 'alignment length' statistics. It is | ||
| 361 | # evaluated on the first HSP of potential relatives. | ||
| 362 | # When not specified, 'tax_min_len' internally defaults to 0. | ||
| 363 | [% IF megan_like -%] | ||
| 364 | tax_min_len: 0 | ||
| 365 | [% ELSIF best_hit -%] | ||
| 366 | tax_min_len: 0 | ||
| 367 | [% ELSIF tax_min_len -%] | ||
| 368 | tax_min_len: [% tax_min_len %] | ||
| 369 | [% END -%] | ||
| 370 | |||
| 371 | # ===Min bit score of relatives to use when inferring taxonomy of new seqs=== | ||
| 372 | # Only meaningful when enabling 'tax_reports' or specifying 'tax_filter'. | ||
| 373 | # This parameter is the traditional BLAST 'bit score' statistics. It is | ||
| 374 | # evaluated on the first HSP of potential relatives. | ||
| 375 | # When not specified, 'tax_min_score' internally defaults to 0. | ||
| 376 | [% IF megan_like -%] | ||
| 377 | tax_min_score: 80 | ||
| 378 | [% ELSIF best_hit -%] | ||
| 379 | tax_min_score: 0 | ||
| 380 | [% ELSIF tax_min_score -%] | ||
| 381 | tax_min_score: [% tax_min_score %] | ||
| 382 | [% END -%] | ||
| 383 | |||
| 384 | # ===Bit score reduction allowed when inferring taxonomy of new seqs=== | ||
| 385 | # Only meaningful when enabling 'tax_reports' or specifying 'tax_filter'. | ||
| 386 | # The allowed bit score reduction of any relative is expressed relatively to | ||
| 387 | # the score of the FIRST relative (as in MEGAN algorithm). | ||
| 388 | # When not specified, 'tax_score_mul' internally defaults to 0. | ||
| 389 | [% IF megan_like -%] | ||
| 390 | tax_score_mul: 0.95 | ||
| 391 | [% ELSIF best_hit -%] | ||
| 392 | tax_score_mul: 0 | ||
| 393 | [% ELSIF tax_score_mul -%] | ||
| 394 | tax_score_mul: [% tax_score_mul %] | ||
| 395 | [% END -%] | ||
| 396 | [% END -%] | ||
| 397 | |||
| 398 | # ===Path to dir holding transcript BLAST databases=== | ||
| 399 | bank_dir: [% bank_dir %] | ||
| 400 | |||
| 401 | # ===Default args applying to all orgs unless otherwise specified=== | ||
| 402 | # Some of these args can be thus specified on a per-org basis below if needed. | ||
| 403 | # This especially makes sense for 'code'. | ||
| 404 | defaults: | ||
| 405 | # ===Genetic code for translated BLAST searches=== | ||
| 406 | # When not specified 'code' internally defaults to 1 (standard). | ||
| 407 | # See ftp://ftp.ncbi.nih.gov/entrez/misc/data/gc.prt for other codes. | ||
| 408 | code: [% code %] | ||
| 409 | |||
| 410 | # ===Org-specific args=== | ||
| 411 | # The only mandatory args are 'org' and 'banks'. All other args are taken from | ||
| 412 | # the 'defaults:' section described above. | ||
| 413 | # This part can be concatenated on a per-run basis to the previous part, which | ||
| 414 | # would be the same for several runs. In the future, forty-two might support | ||
| 415 | # two different configuration files to reflect this conceptual distinction. | ||
| 416 | orgs:[% FOREACH bank IN org_for.keys.sort %] | ||
| 417 | - org: [% org_for.$bank %] | ||
| 418 | banks: | ||
| 419 | - [% bank %] | ||
| 420 | [% tax_filter_for.$bank %][%~ END %] | ||
| 421 | |||
| 422 | [% USE date %] | ||
| 423 | # This config file has been generated automatically on [% date.format %]. | ||
| 424 | # We advise you not to modify directly this file manually but rather to modify | ||
| 425 | # the yaml-generator command instead for traceability and reproducibility. | ||
| 426 | # | ||
| 427 | # yaml-generator-42.pl --run_mode=[% run_mode %][% IF SSUrRNA %] --SSUrRNA[% END %] --out_suffix=[% out_suffix %] \ | ||
| 428 | # --queries [% queries %] \ | ||
| 429 | # --evalue=[% evalue %][% UNLESS SSUrRNA %] --homologues_seg=[% homologues_seg %][% END %] --max_target_seqs=[% max_target_seqs %][% UNLESS SSUrRNA %] --templates_seg=[% templates_seg %][% END %] \ | ||
| 430 | # --bank_dir [% bank_dir %] --bank_suffix=[% bank_suffix %][% IF bank_mapper %] --bank_mapper [% bank_mapper %][% END %] --code=[% code %] \ | ||
| 431 | # --ref_brh=[% ref_brh -%][% IF ref_brh == 'on' %] --ref_bank_dir [% ref_bank_dir %] --ref_bank_suffix=[% ref_bank_suffix %][% IF ref_bank_mapper %] --ref_bank_mapper [% ref_bank_mapper %][% END %] \ | ||
| 432 | # --ref_org_mul=[% ref_org_mul %] --ref_score_mul=[% ref_score_mul %][%- END %] \ | ||
| 433 | # --trim_homologues=[% trim_homologues %][% IF trim_homologues == 'on' %] --trim_max_shift=[% trim_max_shift %] --trim_extra_margin=[% trim_extra_margin %][% END %] \ | ||
| 434 | # --merge_orthologues=[% merge_orthologues %][% IF merge_orthologues == 'on' %] --merge_min_ident=[% merge_min_ident %] --merge_min_len=[% merge_min_len %][% END %] \ | ||
| 435 | # --aligner_mode=[% aligner_mode %][% UNLESS aligner_mode == 'off' %] --ali_skip_self=[% ali_skip_self %] --ali_cover_mul=[% ali_cover_mul %][% END %] --ali_keep_old_new_tags=[% ali_keep_old_new_tags %] --ali_keep_lengthened_seqs=[% ali_keep_lengthened_seqs %] \ | ||
| 436 | # --tax_reports=[% tax_reports %][% IF tax_dir %] --tax_dir [% tax_dir %][% END %] \ | ||
| 437 | # [% IF tax_min_hits %]--tax_min_hits=[% tax_min_hits %] [% END %][% IF megan_like %]--megan_like[% ELSIF best_hit %]--best_hit[% ELSE %][% IF tax_max_hits %]--tax_max_hits=[% tax_max_hits %] [% END %]--tax_min_score=[% tax_min_score %] --tax_score_mul=[% tax_score_mul %] --tax_min_ident=[% tax_min_ident %] --tax_min_len=[% tax_min_len %][% END %] \ | ||
| 438 | # --tol_check=[% tol_check %][% IF tol_check == 'on' %] --tol_db [% tol_db %] \[%- END %] | ||
| 439 | [% IF levels %]# --levels=[% levels.join(' ') %][%- END %] | ||
| 440 | EOT | ||
| 441 | |||
| 442 | # CMD TEMPLATE | ||
| 443 | my $tt_cmd = <<'EOT'; | ||
| 444 | [% USE date %] | ||
| 445 | # This config file has been generated automatically on [% date.format %]. | ||
| 446 | # We advise you not to modify directly this file manually but rather to modify | ||
| 447 | # the yaml-generator command instead for traceability and reproducibility. | ||
| 448 | |||
| 449 | yaml-generator-42.pl --run_mode=[% run_mode %][% IF SSUrRNA %] --SSUrRNA[% END %] --out_suffix=[% out_suffix %] \ | ||
| 450 | --queries [% queries %] \ | ||
| 451 | --evalue=[% evalue %][% UNLESS SSUrRNA %] --homologues_seg=[% homologues_seg %][% END %] --max_target_seqs=[% max_target_seqs %][% UNLESS SSUrRNA %] --templates_seg=[% templates_seg %][% END %] \ | ||
| 452 | --bank_dir [% bank_dir %] --bank_suffix=[% bank_suffix %][% IF bank_mapper %] --bank_mapper [% bank_mapper %][% END %] --code=[% code %] \ | ||
| 453 | --ref_brh=[% ref_brh -%][% IF ref_brh == 'on' %] --ref_bank_dir [% ref_bank_dir %] --ref_bank_suffix=[% ref_bank_suffix %][% IF ref_bank_mapper %] --ref_bank_mapper [% ref_bank_mapper %][% END %] \ | ||
| 454 | --ref_org_mul=[% ref_org_mul %] --ref_score_mul=[% ref_score_mul %][%- END %] \ | ||
| 455 | --trim_homologues=[% trim_homologues %][% IF trim_homologues == 'on' %] --trim_max_shift=[% trim_max_shift %] --trim_extra_margin=[% trim_extra_margin %][% END %] \ | ||
| 456 | --merge_orthologues=[% merge_orthologues %][% IF merge_orthologues == 'on' %] --merge_min_ident=[% merge_min_ident %] --merge_min_len=[% merge_min_len %][% END %] \ | ||
| 457 | --aligner_mode=[% aligner_mode %][% UNLESS aligner_mode == 'off' %] --ali_skip_self=[% ali_skip_self %] --ali_cover_mul=[% ali_cover_mul %][% END %] --ali_keep_old_new_tags=[% ali_keep_old_new_tags %] --ali_keep_lengthened_seqs=[% ali_keep_lengthened_seqs %] \ | ||
| 458 | --tax_reports=[% tax_reports %][% IF tax_dir %] --tax_dir [% tax_dir %][% END %] \ | ||
| 459 | [% IF tax_min_hits %]--tax_min_hits=[% tax_min_hits %] [% END %][% IF megan_like %]--megan_like[% ELSIF best_hit %]--best_hit[% ELSE %][% IF tax_max_hits %]--tax_max_hits=[% tax_max_hits %] [% END %]--tax_min_score=[% tax_min_score %] --tax_score_mul=[% tax_score_mul %] --tax_min_ident=[% tax_min_ident %] --tax_min_len=[% tax_min_len %][% END %] \ | ||
| 460 | --tol_check=[% tol_check %][% IF tol_check == 'on' %] --tol_db [% tol_db %] \[%- END %] | ||
| 461 | [% IF levels %]--levels=[% levels.join(' ') %][%- END %] | ||
| 462 | EOT | ||
| 463 | |||
| 464 | # HOW TO | ||
| 465 | my $howto = << "EOT"; | ||
| 466 | |||
| 467 | \e[1;35m============================== Prompting: How To? ============================== | ||
| 468 | |||
| 469 | You may use the following control keys for manual input and menu input:\e[0m | ||
| 470 | ENTER yes/default value | ||
| 471 | CTRL-C quit | ||
| 472 | |||
| 473 | \e[1;35mYou may use the following control keys for path input:\e[0m | ||
| 474 | TAB complete the word | ||
| 475 | CTRL-D show list of matching choices (same as TAB-TAB) | ||
| 476 | CTRL-U delete the entire input | ||
| 477 | CTRL-H delete a character (backspace) | ||
| 478 | CTRL-P cycle through choices (backward) (also up arrow) | ||
| 479 | CTRL-N cycle through choices (forward) (also down arrow) | ||
| 480 | |||
| 481 | \e[1;35m================================================================================ | ||
| 482 | EOT | ||
| 483 | |||
| 484 | die "Error: No arguments provided! | ||
| 485 | Use the '--wizard' for a guided configuration or define at least the following variables: '--bank_dir' '--bank_suffix' '--queries'" | ||
| 486 | unless | ||
| 487 | List::AllUtils::all { defined $ARGV{$_} } qw(--bank_dir --bank_suffix --queries) | ||
| 488 | or defined $ARGV{'--wizard'}; | ||
| 489 | |||
| 490 | my $tf_auto; | ||
| 491 | if ( $ARGV{'--wizard'} ) { | ||
| 492 | # HOW TO | ||
| 493 | say $howto; | ||
| 494 | |||
| 495 | # CONTEXT | ||
| 496 | $ARGV{'--run_mode'} = prompt "\nWhich mode would you like to run Forty-Two: ", | ||
| 497 | -menu => { 'phylogenomic' => 'phylogenomic', 'metagenomic' => 'metagenomic' }, | ||
| 498 | '>'; | ||
| 499 | |||
| 500 | # OUT_SUFFIX | ||
| 501 | $ARGV{'--out_suffix'} = prompt "\nSuffix to append to infile basenames for deriving outfile names [default: -42]: ", | ||
| 502 | -def => $ARGV{'--out_suffix'}; | ||
| 503 | |||
| 504 | # QUERIES | ||
| 505 | $ARGV{'--queries'} = prompt4file("\nEnter path to query organisms list file: "); | ||
| 506 | |||
| 507 | # ALI TYPE | ||
| 508 | $ARGV{'--SSUrRNA'} = prompt "\nWould you like to enrich SSU rRNA alignments?", -menu => { Yes => 1, no => 0 }, -def => 0; | ||
| 509 | $ARGV{'--ref_brh'} = 'off' if $ARGV{'--SSUrRNA'}; | ||
| 510 | |||
| 511 | # BLASTS | ||
| 512 | $ARGV{'--evalue'} = prompt "\nSet e-value for all blasts performed by 42 [default: 1e-05]: ", | ||
| 513 | -def => $ARGV{'--evalue'}; | ||
| 514 | |||
| 515 | |||
| 516 | unless ( $ARGV{'--SSUrRNA'} ) { | ||
| 517 | |||
| 518 | # REF BANKS | ||
| 519 | $ARGV{'--ref_brh'} = prompt "\nWould you like to use a ref_brh: ", | ||
| 520 | -menu => { 'on [default]' => $ARGV{'--ref_brh'}, off => 'off'}, | ||
| 521 | -def => $ARGV{'--ref_brh'}, | ||
| 522 | '>'; | ||
| 523 | |||
| 524 | unless ( $ARGV{'--ref_brh'} eq 'off' ) { | ||
| 525 | $ARGV{'--ref_bank_dir'} = prompt4dir("\nEnter path to reference organisms banks directory: "); | ||
| 526 | $ARGV{'--ref_bank_suffix'} = prompt4suffix("\nSet reference banks suffix: ", $ARGV{'--ref_bank_dir'}); | ||
| 527 | $ARGV{'--ref_bank_mapper'} = prompt4file("\nEnter path to reference bank mapper file: "); | ||
| 528 | |||
| 529 | $ARGV{'--ref_org_mul'} = prompt "\nSet ref org mul [default: 1.0]: ", | ||
| 530 | -must => { 'be a number between 0 and 1' => qr{^[0-1](?:\.\d+)?}xms }, | ||
| 531 | -def => $ARGV{'--ref_org_mul'}; | ||
| 532 | |||
| 533 | $ARGV{'--ref_score_mul'} = prompt "\nSet ref score mul [default: 0.99]: ", | ||
| 534 | -must => { 'be a number between 0 and 1' => qr{^[0-1](?:\.\d+)?}xms }, | ||
| 535 | -def => $ARGV{'--ref_score_mul'}; | ||
| 536 | } | ||
| 537 | |||
| 538 | my $tax_filter; | ||
| 539 | |||
| 540 | # TreeOfLIfe CHECK | ||
| 541 | $ARGV{'--tol_check'} = prompt "\nDo you need to perform the Tree Of Life check before adding an ortholog?", | ||
| 542 | -menu => { 'yes' => 'on', 'no [default]' => 'off'}, | ||
| 543 | -def => $ARGV{'--tol_check'}, | ||
| 544 | '>'; | ||
| 545 | if ($ARGV{'--tol_check'} eq 'on') { | ||
| 546 | $tax_filter = 1; | ||
| 547 | $ARGV{'--tol_db'} = prompt4dir("\nEnter path to TreeOfLife database: "); | ||
| 548 | |||
| 549 | $tf_auto = prompt "\nSet tax filter input: ", | ||
| 550 | -menu => { 'from org mapper file' => 0, | ||
| 551 | "from NCBI's taxonomy - auto + prompt for missing" => 1, | ||
| 552 | "from NCBI's taxonomy - auto + prompt for all" => 2, | ||
| 553 | }; | ||
| 554 | if ( $tf_auto == 1 ) { | ||
| 555 | @{ $ARGV{'--levels'} } = split ",", ( prompt "\nLevels separated by a coma (no whitespace): "); | ||
| 556 | } | ||
| 557 | } | ||
| 558 | |||
| 559 | # TRIMMING HOMOLOGUES | ||
| 560 | $ARGV{'--trim_homologues'} = prompt "\nChoose trim_homologues mode: ", | ||
| 561 | -menu => { 'on [default]' => $ARGV{'--trim_homologues'}, off => 'off' }, '>', | ||
| 562 | -def => $ARGV{'--trim_homologues'}; | ||
| 563 | |||
| 564 | unless ( $ARGV{'--trim_homologues'} eq 'off' ) { | ||
| 565 | $ARGV{'--trim_max_shift' } = prompt "\nSet trim_max_shift: ", -def => $ARGV{'--trim_max_shift'}; | ||
| 566 | $ARGV{'--trim_extra_margin'} = prompt "\nSet trim_extra_margin: ", -def => $ARGV{'--trim_extra_margin'}; | ||
| 567 | } | ||
| 568 | |||
| 569 | # MERGING ORTHOLOGUES | ||
| 570 | $ARGV{'--merge_orthologues'} = prompt "\nChoose merge_orthologues mode: ", | ||
| 571 | -menu => { on => 'on', 'off [default]' => $ARGV{'--merge_orthologues'} }, '>', | ||
| 572 | -def => $ARGV{'--merge_orthologues'}; | ||
| 573 | |||
| 574 | unless ( $ARGV{'--merge_orthologues'} eq 'off' ) { | ||
| 575 | $ARGV{'--merge_min_ident' } = prompt "\nSet merge_min_ident: ", -def => $ARGV{'--merge_min_ident'}; | ||
| 576 | $ARGV{'--merge_min_len' } = prompt "\nSet merge_min_len: ", -def => $ARGV{'--merge_min_len'}; | ||
| 577 | } | ||
| 578 | |||
| 579 | # ali_keep_lengthened_seqs | ||
| 580 | $ARGV{'--ali_keep_lengthened_seqs'} = prompt "\nAction to perform when a preexisting lengthened seq is identified: ", | ||
| 581 | -menu => { 'keep [default]' => 'keep', remove => 'remove' }, | ||
| 582 | -def => $ARGV{'--ali_keep_lengthened_seqs'}, '>'; | ||
| 583 | |||
| 584 | if ($ARGV{'--run_mode'} eq 'phylogenomic') { | ||
| 585 | |||
| 586 | # ALIGNER | ||
| 587 | $ARGV{'--tax_reports'} = 'on'; | ||
| 588 | |||
| 589 | $ARGV{'--aligner_mode'} = prompt "\nSet aligner_mode: ", | ||
| 590 | -menu => { 'blast [default]' => $ARGV{'--aligner_mode'}, | ||
| 591 | exonerate => 'exonerate', | ||
| 592 | exoblast => 'exoblast', | ||
| 593 | off => 'off' | ||
| 594 | }, | ||
| 595 | -def => $ARGV{'--aligner_mode'}, | ||
| 596 | '>'; | ||
| 597 | |||
| 598 | |||
| 599 | # ali_skip_self | ||
| 600 | $ARGV{'--ali_skip_self'} = prompt "\nSet patch mode: ", | ||
| 601 | -menu => { 'off [default]' => $ARGV{'--ali_skip_self'}, on => 'on' }, | ||
| 602 | -def => $ARGV{'--ali_skip_self'}, '>'; | ||
| 603 | |||
| 604 | # TAXONOMIC FILTER | ||
| 605 | unless ($tax_filter) { | ||
| 606 | $tax_filter = prompt "\nIs a taxonomic filter needed?", -menu => { Yes => 1, no => 0 }; | ||
| 607 | |||
| 608 | if ($tax_filter) { | ||
| 609 | |||
| 610 | $ARGV{'--tax_dir'} = prompt4dir("\nEnter path to taxdump directory: "); | ||
| 611 | |||
| 612 | $tf_auto = prompt "\nSet tax filter input: ", | ||
| 613 | -menu => { 'from org mapper file' => 0, | ||
| 614 | "from NCBI's taxonomy - auto + prompt for missing" => 1, | ||
| 615 | "from NCBI's taxonomy - auto + prompt for all" => 2, | ||
| 616 | }; | ||
| 617 | |||
| 618 | if ( $tf_auto == 1 ) { | ||
| 619 | @{ $ARGV{'--levels'} } = split ",", ( prompt "\nLevels separated by a coma (no whitespace): "); | ||
| 620 | } | ||
| 621 | } | ||
| 622 | |||
| 623 | # TAXNOMIC AFFILIATION | ||
| 624 | $tax_filter = prompt "\nIs taxonomic classification needed?", -menu => { Yes => 1, no => 0 }; | ||
| 625 | } | ||
| 626 | } | ||
| 627 | |||
| 628 | else { | ||
| 629 | $ARGV{'--tax_reports'} = 'on'; | ||
| 630 | $ARGV{'--aligner_mode'} = 'off'; | ||
| 631 | $ARGV{'--merge_orthologues'} = 'off'; | ||
| 632 | } | ||
| 633 | |||
| 634 | if ($ARGV{'--run_mode'} eq 'metagenomic' || $tax_filter) { | ||
| 635 | |||
| 636 | # TAX DIR | ||
| 637 | unless ( $ARGV{'--tax_dir'} ) { | ||
| 638 | $ARGV{'--tax_dir'} = prompt4dir("\nEnter path to taxdump directory: "); | ||
| 639 | } | ||
| 640 | |||
| 641 | my $tax_aff = prompt "\nChoose taxonomic affiliation mode: ", | ||
| 642 | -menu => { 'megan-like' => '--megan_like', 'best-hit' => '--best_hit' }, | ||
| 643 | -def => 1; | ||
| 644 | $ARGV{"$tax_aff"} = 1; | ||
| 645 | |||
| 646 | # BEST_HIT | ||
| 647 | if ( $ARGV{'--best_hit'} ) { | ||
| 648 | say "The '--best_hit' flag autosets the following parameter:\n'--tax_max_hits' = 1"; | ||
| 649 | $ARGV{'--tax_max_hits'} = 1; | ||
| 650 | |||
| 651 | my $hit_filtering = prompt "\nSet hit-filtering mode: ", | ||
| 652 | -menu => { 'default values' => 0, 'length/identity' => 'length_identity', 'Bit score' => 'bitscore' }; | ||
| 653 | |||
| 654 | if ($hit_filtering eq 'bitscore') { | ||
| 655 | $ARGV{'--tax_min_score'} = prompt "\nSet minimum bit score to consider a hit: ", | ||
| 656 | -must => { 'be an integer' => qr{^[0-9]+\z} }, | ||
| 657 | -def => $ARGV{'--tax_min_score'}; | ||
| 658 | } | ||
| 659 | if ($hit_filtering eq 'length_identity') { | ||
| 660 | $ARGV{'--tax_min_ident'} = prompt "\nSet minimum percentage of identity to consider a hit: ", | ||
| 661 | -must => { 'be a number between 0 and 1' => qr{^[0-1](?:\.\d+)?}xms }, | ||
| 662 | -def => $ARGV{'--tax_min_ident'}; | ||
| 663 | |||
| 664 | $ARGV{'--tax_min_len'} = prompt "\nSet minimum length to consider a hit: ", | ||
| 665 | -must => { 'be an integer' => qr{^[1-9]+} }, | ||
| 666 | -def => $ARGV{'--tax_min_len'}; | ||
| 667 | } | ||
| 668 | } | ||
| 669 | |||
| 670 | # MEGAN_LIKE | ||
| 671 | if ($ARGV{'--megan_like'}) { | ||
| 672 | say "\nThe '--megan_like' flag autosets the following parameters:\n'--tax_min_score' = 80,\n'--tax_score_mul' = 0.95,\n'--tax_min_ident' = 0,\n'--tax_min_len' = 0."; | ||
| 673 | say "\nFeel free to modify the default settings according to your own flavors."; | ||
| 674 | |||
| 675 | $ARGV{'--tax_min_ident'} = 0; | ||
| 676 | $ARGV{'--tax_min_len'} = 0; | ||
| 677 | $ARGV{'--tax_min_score'} = 80; | ||
| 678 | $ARGV{'--tax_score_mul'} = 0.95; | ||
| 679 | } | ||
| 680 | } | ||
| 681 | } | ||
| 682 | |||
| 683 | # BANKS | ||
| 684 | $ARGV{'--bank_dir'} = prompt4dir("\nEnter path to your candidate genomes directory: "); | ||
| 685 | $ARGV{'--bank_suffix'} = prompt4suffix("\nSet candiate banks suffix: ", $ARGV{'--bank_dir'}); | ||
| 686 | $ARGV{'--bank_mapper'} = prompt4file("\nEnter path to bank mapper file: "); | ||
| 687 | |||
| 688 | # CODE | ||
| 689 | $ARGV{'--code'} = prompt "\nGenetic code for translated BLAST searches [default: 1]: ", | ||
| 690 | -must => { 'be an integer' => qr{^[1-9]+} }, | ||
| 691 | -def => $ARGV{'--code'}; | ||
| 692 | |||
| 693 | } | ||
| 694 | |||
| 695 | #### %ARGV | ||
| 696 | |||
| 697 | # tol arguments | ||
| 698 | if ( $ARGV{'--tol_db'} ) { | ||
| 699 | my $file = Path::Class::File->new($ARGV{'--tol_db'}); | ||
| 700 | $ARGV{'--tol_bank'} = $file->basename; | ||
| 701 | $ARGV{'--tol_bank_dir'} = $file->dir->absolute->stringify; | ||
| 702 | } | ||
| 703 | |||
| 704 | # convert arguments to values for placeholders | ||
| 705 | my %vars = map { tr/-<>//dr => $ARGV{$_} } keys %ARGV; | ||
| 706 | |||
| 707 | # bank files | ||
| 708 | my @bank_files = File::Find::Rule | ||
| 709 | ->file() | ||
| 710 | ->relative() | ||
| 711 | ->maxdepth(1) | ||
| 712 | ->name( qr{ $ARGV{'--bank_suffix'} $}xmsi ) | ||
| 713 | ->in($ARGV{'--bank_dir'}) | ||
| 714 | ; | ||
| 715 | # org mapper: from file names or file | ||
| 716 | $ARGV{'--choose_tax_filter'} = 1 if $ARGV{'--levels'}; | ||
| 717 | $tf_auto = $ARGV{'--choose_tax_filter'}; | ||
| 718 | my $tax = Taxonomy->new_from_cache( tax_dir => $ARGV{'--tax_dir'} ) if $tf_auto; | ||
| 719 | #### lvl: $ARGV{'--levels'} | ||
| 720 | |||
| 721 | my ($org_for, $tax_filter_for) = build_org_n_tax_filter_for(); | ||
| 722 | #### $org_for | ||
| 723 | #### $tax_filter_for | ||
| 724 | |||
| 725 | # ref_bank files | ||
| 726 | my $ref_org_for; | ||
| 727 | my @ref_bank_files; | ||
| 728 | unless ( $ARGV{'--ref_brh'} eq 'off' ) { | ||
| 729 | @ref_bank_files = File::Find::Rule | ||
| 730 | ->file() | ||
| 731 | ->relative() | ||
| 732 | ->maxdepth(1) | ||
| 733 | ->name( qr{ $ARGV{'--ref_bank_suffix'} $}xmsi ) | ||
| 734 | ->in($ARGV{'--ref_bank_dir'}) | ||
| 735 | ; | ||
| 736 | # ref org mapper: from file names or file | ||
| 737 | $ref_org_for = build_ref_org_for(); | ||
| 738 | } | ||
| 739 | |||
| 740 | # complete %vars | ||
| 741 | $vars{org_for} = $org_for; | ||
| 742 | $vars{query_orgs} = [ IdList->load( $ARGV{'--queries'} )->all_ids ]; | ||
| 743 | $vars{ref_org_for} = $ref_org_for if $ref_org_for; | ||
| 744 | $vars{tax_filter_for} = $tax_filter_for if $tax_filter_for; | ||
| 745 | #### %vars | ||
| 746 | |||
| 747 | # build config filenames | ||
| 748 | my $dir = '.'; # default to working dir | ||
| 749 | if ( $ARGV{'--outdir'} ) { | ||
| 750 | $dir = dir( $ARGV{'--outdir'} )->relative; | ||
| 751 | $dir->mkpath(); | ||
| 752 | } | ||
| 753 | $ARGV{'--out_suffix'} =~ s/^\-//xms; | ||
| 754 | my $outyaml = file($dir, 'config-' . $ARGV{'--out_suffix'} . '.yaml'); | ||
| 755 | my $outcmd = file($dir, 'build-' . $ARGV{'--out_suffix'} . '-yaml.sh'); | ||
| 756 | #### yaml: $outyaml->stringify | ||
| 757 | #### sh: $outcmd->stringify | ||
| 758 | |||
| 759 | # fill-in template | ||
| 760 | my $tt = Template->new; | ||
| 761 | $tt->process(\$tt_str, \%vars, $outyaml->stringify) or die "Unable to write $outyaml"; | ||
| 762 | $tt->process(\$tt_cmd, \%vars, $outcmd->stringify) or die "Unable to write $outcmd"; | ||
| 763 | |||
| 764 | say "\nSuccessfully wrote files: $outyaml and $outcmd!"; | ||
| 765 | |||
| 766 | # SUBROUTINES | ||
| 767 | |||
| 768 | sub prompt4dir { | ||
| 769 | return _prompt4path(\&dir, @_); | ||
| 770 | } | ||
| 771 | |||
| 772 | |||
| 773 | sub prompt4file { | ||
| 774 | return _prompt4path(\&file, @_); | ||
| 775 | } | ||
| 776 | |||
| 777 | sub _prompt4path { | ||
| 778 | my $sub = shift; | ||
| 779 | my $string = shift; | ||
| 780 | $string = "\e[1;34m$string\e[0m"; | ||
| 781 | my $path; | ||
| 782 | my $areyousure = 0; | ||
| 783 | my $tc = Term::Completion::Path->new( | ||
| 784 | prompt => $string, | ||
| 785 | ); | ||
| 786 | while ( $areyousure == 0 ) { | ||
| 787 | $path = '' unless $areyousure; | ||
| 788 | until (-e $path) { | ||
| 789 | $path = $tc->complete(); | ||
| 790 | say "No such file or directory '$path'. Try again..." unless -e $path; | ||
| 791 | } | ||
| 792 | $path = $sub->($path)->absolute->resolve->stringify unless $ARGV{'--relative'}; | ||
| 793 | $areyousure = prompt "\nIs that correct: $path ? ", -menu => { Yes => 1, no => 0 }, -def => 1, -style => 'blue'; | ||
| 794 | } | ||
| 795 | return $path; | ||
| 796 | } | ||
| 797 | |||
| 798 | |||
| 799 | sub prompt4suffix { | ||
| 800 | my $string = shift; | ||
| 801 | my $dir = shift; | ||
| 802 | my $areyousure = 0; | ||
| 803 | my $suffix; | ||
| 804 | |||
| 805 | while ( $areyousure == 0 ) { | ||
| 806 | $suffix = prompt $string; | ||
| 807 | say "\n\e[0;33mFiles in directory: "; | ||
| 808 | system("ls $dir/*$suffix | xargs -n1 basename"); | ||
| 809 | $areyousure = prompt "\nIs that correct: $suffix ? ", | ||
| 810 | -menu => { Yes => 1, no => 0 }, | ||
| 811 | -def => 1, -style => 'blue'; | ||
| 812 | } | ||
| 813 | return $suffix; | ||
| 814 | } | ||
| 815 | |||
| 816 | sub build_ref_org_for { | ||
| 817 | |||
| 818 | # default to all available ref_banks and default ref_org names | ||
| 819 | my @ref_banks = map { basename $_, $ARGV{'--ref_bank_suffix'} } @ref_bank_files; | ||
| 820 | my @ref_orgs = map { join q{ }, (split /_/xms, $_, 2) } @ref_banks; | ||
| 821 | |||
| 822 | # override (possibly restrict) default values if mapper specified | ||
| 823 | if ($ARGV{'--ref_bank_mapper'}) { | ||
| 824 | my $mapper = IdMapper->load( $ARGV{'--ref_bank_mapper'} ); | ||
| 825 | @ref_banks = $mapper->all_abbr_ids; | ||
| 826 | @ref_orgs = $mapper->all_long_ids; | ||
| 827 | } | ||
| 828 | |||
| 829 | my %ref_org_for = mesh @ref_banks, @ref_orgs; | ||
| 830 | return \%ref_org_for; | ||
| 831 | } | ||
| 832 | |||
| 833 | sub build_org_n_tax_filter_for { | ||
| 834 | |||
| 835 | # default to all available banks and default org names | ||
| 836 | my @banks = map { basename $_, $ARGV{'--bank_suffix'} } @bank_files; | ||
| 837 | my @orgs = map { join q{ }, (split /_/xms, $_, 2) } @banks; | ||
| 838 | return { mesh @banks, @orgs } unless $ARGV{'--bank_mapper'}; | ||
| 839 | |||
| 840 | # override (possibly restrict) default values if mapper specified | ||
| 841 | my %org_for; | ||
| 842 | my %tax_filter_for; | ||
| 843 | |||
| 844 | open my $in, '<', $ARGV{'--bank_mapper'}; | ||
| 845 | # Note: cannot use IdMapper class due to four fields (instead of two) | ||
| 846 | |||
| 847 | LINE: | ||
| 848 | while (my $line = <$in>) { | ||
| 849 | chomp $line; | ||
| 850 | next LINE if $line =~ $COMMENT_LINE | ||
| 851 | || $line =~ $EMPTY_LINE; | ||
| 852 | $line =~ s/\s+$//xmsg; | ||
| 853 | |||
| 854 | # collect (or generate) bank details and tax_filter | ||
| 855 | my ($org, $bank, $tax_filters, $lineage) = split /\t/xms, $line; | ||
| 856 | ($tax_filters, $lineage) = _get_tax_filter($org) | ||
| 857 | if $tf_auto; | ||
| 858 | |||
| 859 | $org_for{$bank} = $org; | ||
| 860 | $tax_filter_for{$bank} = "tax_filter: [ $tax_filters ]" | ||
| 861 | . ( $lineage ? " # $lineage" : q{} ) if defined $tax_filters; | ||
| 862 | } | ||
| 863 | |||
| 864 | return \%org_for, \%tax_filter_for; | ||
| 865 | } | ||
| 866 | |||
| 867 | sub _get_tax_filter { | ||
| 868 | my $org = shift; | ||
| 869 | |||
| 870 | my $entity; | ||
| 871 | my $method; | ||
| 872 | my $lineage; | ||
| 873 | if ($org =~ m/^GCA|GCF/xms || $org =~ m/^\d+$/xms) { | ||
| 874 | $entity = $org; | ||
| 875 | $method = 'get_taxonomy_with_levels'; | ||
| 876 | #### TID/GCA: $entity | ||
| 877 | } | ||
| 878 | else { | ||
| 879 | $entity = SeqId->new( full_id => $org . '@1'); | ||
| 880 | $method = 'get_taxonomy_with_levels_from_seq_id'; | ||
| 881 | #### ORG: $entity | ||
| 882 | } | ||
| 883 | my @tax = $tax->$method($entity); | ||
| 884 | $lineage = join q{; }, map { @{ $tax[$_] }[0] } 0..$#tax; | ||
| 885 | #### $lineage | ||
| 886 | |||
| 887 | # Type a name untill it works! | ||
| 888 | my $loop; | ||
| 889 | while (! @tax) { | ||
| 890 | $loop++; | ||
| 891 | say "Warning: Unable to retrieve taxonomy for $org.\n"; #TODO | ||
| 892 | say "Try with '$org" . "_sp'" if $loop > 1; | ||
| 893 | |||
| 894 | $org = prompt "Please enter a valid species name or taxonomic rank followed by '_sp'...\n", '>'; | ||
| 895 | my $seq_id = SeqId->new( full_id => $org.'@1'); | ||
| 896 | @tax = $tax->$method($seq_id); | ||
| 897 | $lineage = join q{; }, map { @{ $tax[$_] }[0] } 0..$#tax; | ||
| 898 | } | ||
| 899 | |||
| 900 | tie my %tax_for, 'Tie::IxHash'; | ||
| 901 | for my $tax_n_level (@tax) { | ||
| 902 | $tax_for{$$tax_n_level[1]} = $$tax_n_level[0]; | ||
| 903 | } | ||
| 904 | |||
| 905 | my $tax_filter; | ||
| 906 | if ($tf_auto == 1) { | ||
| 907 | LEVEL: | ||
| 908 | for my $level (@{ $ARGV{'--levels'} }) { | ||
| 909 | $tax_filter = $tax_for{$level}; | ||
| 910 | last LEVEL if defined $tax_filter; | ||
| 911 | } | ||
| 912 | return '+' . $tax_filter, $lineage if defined $tax_filter; | ||
| 913 | } | ||
| 914 | |||
| 915 | unless (defined $tax_filter) { | ||
| 916 | say "\nWarning: no taxon defined for level(s): @{ $ARGV{'--levels'} }"; | ||
| 917 | } | ||
| 918 | |||
| 919 | $tax_filter = '+' . _tax_prompter(\@tax, $org); | ||
| 920 | |||
| 921 | return $tax_filter, $lineage; | ||
| 922 | } | ||
| 923 | |||
| 924 | sub _tax_prompter { | ||
| 925 | my ($tax_ref, $org) = @_; | ||
| 926 | my @tax = map { @$_[0] } @$tax_ref; | ||
| 927 | my $tax_filter = prompt "\nChoose tax_filter for '$org':", | ||
| 928 | -menu => \@tax, | ||
| 929 | '>'; | ||
| 930 | return $tax_filter; | ||
| 931 | } | ||
| 932 | |||
| 933 | # for testing: | ||
| 934 | # perl -Ilib bin/yaml-generator-42.pl --run_mode=metagenomic --out_suffix=-test1 \ | ||
| 935 | # --queries xtest/yaml_gen/queries/queries-prokaryotes.idl \ | ||
| 936 | # --evalue=1e-3 --homologues_seg=yes --max_target_seqs=50 --templates_seg=no \ | ||
| 937 | # --bank_dir xtest/yaml_gen/genomes --bank_suffix=.nsq --bank_mapper xtest/yaml_gen/genomes/mapper-genomes.idm --code=1 \ | ||
| 938 | # --ref_brh=on --ref_bank_dir xtest/yaml_gen/ref_orgs --ref_bank_suffix=.psq --ref_bank_mapper xtest/yaml_gen/ref_orgs/mapper-prokaryotes.idm \ | ||
| 939 | # --ref_org_mul=0.33 --ref_score_mul=0.99 \ | ||
| 940 | # --trim_homologues=on --trim_max_shift=5000 --trim_extra_margin=15 \ | ||
| 941 | # --merge_orthologues=off \ | ||
| 942 | # --aligner_mode=off --ali_keep_old_new_tags=off --ali_keep_lengthened_seqs=keep \ | ||
| 943 | # --tax_reports=on --tax_dir ../Bio-MUST-Core/test/taxdump \ | ||
| 944 | # --tax_max_hits=10 --tax_min_score=80 --tax_score_mul=0.99 --tax_min_ident=0.50 --tax_min_len=0 \ | ||
| 945 | # --tol_check=off \ | ||
| 946 | # --out_dir xtest/yaml_gen/outdir | ||
| 947 | # | ||
| 948 | # perl -Ilib bin/yaml-generator-42.pl --run_mode=metagenomic --out_suffix=-test2 \ | ||
| 949 | # --queries xtest/yaml_gen/queries/queries-prokaryotes.idl \ | ||
| 950 | # --evalue=1e-3 --homologues_seg=yes --max_target_seqs=50 --templates_seg=no \ | ||
| 951 | # --bank_dir xtest/yaml_gen/genomes --bank_suffix=.nsq --code=1 \ | ||
| 952 | # --ref_brh=on --ref_bank_dir xtest/yaml_gen/ref_orgs --ref_bank_suffix=.psq \ | ||
| 953 | # --ref_org_mul=0.33 --ref_score_mul=0.99 \ | ||
| 954 | # --trim_homologues=off \ | ||
| 955 | # --merge_orthologues=on --merge_min_ident=0.9 --merge_min_len=40 \ | ||
| 956 | # --aligner_mode=off --ali_keep_old_new_tags=off --ali_keep_lengthened_seqs=keep \ | ||
| 957 | # --tax_reports=on \ | ||
| 958 | # --tax_min_score=0 --tax_score_mul=0 --tax_min_ident=0 --tax_min_len=0 \ | ||
| 959 | # --tol_check=off \ | ||
| 960 | # --out_dir xtest/yaml_gen/outdir | ||
| 961 | # | ||
| 962 | # perl -Ilib bin/yaml-generator-42.pl --run_mode=metagenomic --out_suffix=-test3 \ | ||
| 963 | # --queries xtest/yaml_gen/queries/queries-prokaryotes.idl \ | ||
| 964 | # --evalue=1e-3 --homologues_seg=yes --max_target_seqs=50 --templates_seg=no \ | ||
| 965 | # --bank_dir xtest/yaml_gen/genomes --bank_suffix=.nsq --code=1 \ | ||
| 966 | # --ref_brh=off \ | ||
| 967 | # --trim_homologues=off \ | ||
| 968 | # --merge_orthologues=off \ | ||
| 969 | # --aligner_mode=blast --ali_skip_self=off --ali_cover_mul=1.1 --ali_keep_old_new_tags=off --ali_keep_lengthened_seqs=keep \ | ||
| 970 | # --tax_reports=on \ | ||
| 971 | # --megan_like \ | ||
| 972 | # --tol_check=off \ | ||
| 973 | # --out_dir xtest/yaml_gen/outdir | ||
| 974 | |||
| 975 | __END__ |