nf-core_modules/software/last/lastal/functions.nf

69 lines
2.5 KiB
Text
Raw Normal View History

//
// Utility functions used in nf-core DSL2 module files
//
New last/lastal module to align query sequences on a target index (#510) * New last/lastal to align query sequences on a target index `lastal` is the main program of the [LAST](https://gitlab.com/mcfrith/last) suite. It align query DNA sequences in FASTA or FASTQ format to a target index of DNA or protein sequences. The index is produced by the `lastdb` program (module `last/lastdb`). The score matrix for evaluating the alignment can be chosen among preset ones or computed iteratively by the `last-train` program (module `last/train`). For this reason, the `last/lastal` module proposed here has one input channel containing an optional file, that has to be dummy when not used. The LAST aligner outputs MAF files that can be very large (up to hundreds of gigabytes), therefore this module unconditionally compresses its output with gzip. This new module is part of the work described in Issue #464. During this development, we fix the version of LAST to 1219 to ensure consistency (hence ignore lint's version warning). * Apply suggestions from code review Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> * Un-hardcode the path to the LAST index. Among multiple alternatives I have chosen the following command to detect the sample name of the index, because it fails in situations where there is no index files in the index folder, and in situations were there are two indexes files in the folder. Not failing would result in feeding garbage information in the INDEX_NAME variable. basename \$(ls $index/*.bck) .bck In case of missing file, a clear error message is given by `ls`. In case of more than one file, the error message of `basename` is more cryptic, unfortunately. (`basename: extra operand ‘.bck’`) Alternatives that do not fail if there is no .bck file: basename $index/*bck .bck find $index -name '*bck' | sed 's/.bck//' Alternatives that do not fail if there are more than one .bck file: basename -s .bck $index/*bck ls $index/*.bck | xargs basename -s .bck find $index -name '*bck' | sed 's/.bck//' Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
2021-05-25 21:10:48 +00:00
//
// Extract name of software tool from process name using $task.process
//
New last/lastal module to align query sequences on a target index (#510) * New last/lastal to align query sequences on a target index `lastal` is the main program of the [LAST](https://gitlab.com/mcfrith/last) suite. It align query DNA sequences in FASTA or FASTQ format to a target index of DNA or protein sequences. The index is produced by the `lastdb` program (module `last/lastdb`). The score matrix for evaluating the alignment can be chosen among preset ones or computed iteratively by the `last-train` program (module `last/train`). For this reason, the `last/lastal` module proposed here has one input channel containing an optional file, that has to be dummy when not used. The LAST aligner outputs MAF files that can be very large (up to hundreds of gigabytes), therefore this module unconditionally compresses its output with gzip. This new module is part of the work described in Issue #464. During this development, we fix the version of LAST to 1219 to ensure consistency (hence ignore lint's version warning). * Apply suggestions from code review Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> * Un-hardcode the path to the LAST index. Among multiple alternatives I have chosen the following command to detect the sample name of the index, because it fails in situations where there is no index files in the index folder, and in situations were there are two indexes files in the folder. Not failing would result in feeding garbage information in the INDEX_NAME variable. basename \$(ls $index/*.bck) .bck In case of missing file, a clear error message is given by `ls`. In case of more than one file, the error message of `basename` is more cryptic, unfortunately. (`basename: extra operand ‘.bck’`) Alternatives that do not fail if there is no .bck file: basename $index/*bck .bck find $index -name '*bck' | sed 's/.bck//' Alternatives that do not fail if there are more than one .bck file: basename -s .bck $index/*bck ls $index/*.bck | xargs basename -s .bck find $index -name '*bck' | sed 's/.bck//' Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
2021-05-25 21:10:48 +00:00
def getSoftwareName(task_process) {
return task_process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()
}
//
// Function to initialise default values and to generate a Groovy Map of available options for nf-core modules
//
New last/lastal module to align query sequences on a target index (#510) * New last/lastal to align query sequences on a target index `lastal` is the main program of the [LAST](https://gitlab.com/mcfrith/last) suite. It align query DNA sequences in FASTA or FASTQ format to a target index of DNA or protein sequences. The index is produced by the `lastdb` program (module `last/lastdb`). The score matrix for evaluating the alignment can be chosen among preset ones or computed iteratively by the `last-train` program (module `last/train`). For this reason, the `last/lastal` module proposed here has one input channel containing an optional file, that has to be dummy when not used. The LAST aligner outputs MAF files that can be very large (up to hundreds of gigabytes), therefore this module unconditionally compresses its output with gzip. This new module is part of the work described in Issue #464. During this development, we fix the version of LAST to 1219 to ensure consistency (hence ignore lint's version warning). * Apply suggestions from code review Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> * Un-hardcode the path to the LAST index. Among multiple alternatives I have chosen the following command to detect the sample name of the index, because it fails in situations where there is no index files in the index folder, and in situations were there are two indexes files in the folder. Not failing would result in feeding garbage information in the INDEX_NAME variable. basename \$(ls $index/*.bck) .bck In case of missing file, a clear error message is given by `ls`. In case of more than one file, the error message of `basename` is more cryptic, unfortunately. (`basename: extra operand ‘.bck’`) Alternatives that do not fail if there is no .bck file: basename $index/*bck .bck find $index -name '*bck' | sed 's/.bck//' Alternatives that do not fail if there are more than one .bck file: basename -s .bck $index/*bck ls $index/*.bck | xargs basename -s .bck find $index -name '*bck' | sed 's/.bck//' Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
2021-05-25 21:10:48 +00:00
def initOptions(Map args) {
def Map options = [:]
options.args = args.args ?: ''
options.args2 = args.args2 ?: ''
options.args3 = args.args3 ?: ''
options.publish_by_meta = args.publish_by_meta ?: []
options.publish_dir = args.publish_dir ?: ''
options.publish_files = args.publish_files
options.suffix = args.suffix ?: ''
return options
}
//
// Tidy up and join elements of a list to return a path string
//
New last/lastal module to align query sequences on a target index (#510) * New last/lastal to align query sequences on a target index `lastal` is the main program of the [LAST](https://gitlab.com/mcfrith/last) suite. It align query DNA sequences in FASTA or FASTQ format to a target index of DNA or protein sequences. The index is produced by the `lastdb` program (module `last/lastdb`). The score matrix for evaluating the alignment can be chosen among preset ones or computed iteratively by the `last-train` program (module `last/train`). For this reason, the `last/lastal` module proposed here has one input channel containing an optional file, that has to be dummy when not used. The LAST aligner outputs MAF files that can be very large (up to hundreds of gigabytes), therefore this module unconditionally compresses its output with gzip. This new module is part of the work described in Issue #464. During this development, we fix the version of LAST to 1219 to ensure consistency (hence ignore lint's version warning). * Apply suggestions from code review Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> * Un-hardcode the path to the LAST index. Among multiple alternatives I have chosen the following command to detect the sample name of the index, because it fails in situations where there is no index files in the index folder, and in situations were there are two indexes files in the folder. Not failing would result in feeding garbage information in the INDEX_NAME variable. basename \$(ls $index/*.bck) .bck In case of missing file, a clear error message is given by `ls`. In case of more than one file, the error message of `basename` is more cryptic, unfortunately. (`basename: extra operand ‘.bck’`) Alternatives that do not fail if there is no .bck file: basename $index/*bck .bck find $index -name '*bck' | sed 's/.bck//' Alternatives that do not fail if there are more than one .bck file: basename -s .bck $index/*bck ls $index/*.bck | xargs basename -s .bck find $index -name '*bck' | sed 's/.bck//' Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
2021-05-25 21:10:48 +00:00
def getPathFromList(path_list) {
def paths = path_list.findAll { item -> !item?.trim().isEmpty() } // Remove empty entries
paths = paths.collect { it.trim().replaceAll("^[/]+|[/]+\$", "") } // Trim whitespace and trailing slashes
return paths.join('/')
}
//
// Function to save/publish module results
//
New last/lastal module to align query sequences on a target index (#510) * New last/lastal to align query sequences on a target index `lastal` is the main program of the [LAST](https://gitlab.com/mcfrith/last) suite. It align query DNA sequences in FASTA or FASTQ format to a target index of DNA or protein sequences. The index is produced by the `lastdb` program (module `last/lastdb`). The score matrix for evaluating the alignment can be chosen among preset ones or computed iteratively by the `last-train` program (module `last/train`). For this reason, the `last/lastal` module proposed here has one input channel containing an optional file, that has to be dummy when not used. The LAST aligner outputs MAF files that can be very large (up to hundreds of gigabytes), therefore this module unconditionally compresses its output with gzip. This new module is part of the work described in Issue #464. During this development, we fix the version of LAST to 1219 to ensure consistency (hence ignore lint's version warning). * Apply suggestions from code review Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> * Un-hardcode the path to the LAST index. Among multiple alternatives I have chosen the following command to detect the sample name of the index, because it fails in situations where there is no index files in the index folder, and in situations were there are two indexes files in the folder. Not failing would result in feeding garbage information in the INDEX_NAME variable. basename \$(ls $index/*.bck) .bck In case of missing file, a clear error message is given by `ls`. In case of more than one file, the error message of `basename` is more cryptic, unfortunately. (`basename: extra operand ‘.bck’`) Alternatives that do not fail if there is no .bck file: basename $index/*bck .bck find $index -name '*bck' | sed 's/.bck//' Alternatives that do not fail if there are more than one .bck file: basename -s .bck $index/*bck ls $index/*.bck | xargs basename -s .bck find $index -name '*bck' | sed 's/.bck//' Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
2021-05-25 21:10:48 +00:00
def saveFiles(Map args) {
if (!args.filename.endsWith('.version.txt')) {
def ioptions = initOptions(args.options)
def path_list = [ ioptions.publish_dir ?: args.publish_dir ]
if (ioptions.publish_by_meta) {
def key_list = ioptions.publish_by_meta instanceof List ? ioptions.publish_by_meta : args.publish_by_meta
for (key in key_list) {
if (args.meta && key instanceof String) {
def path = key
if (args.meta.containsKey(key)) {
path = args.meta[key] instanceof Boolean ? "${key}_${args.meta[key]}".toString() : args.meta[key]
}
path = path instanceof String ? path : ''
path_list.add(path)
}
}
}
if (ioptions.publish_files instanceof Map) {
for (ext in ioptions.publish_files) {
if (args.filename.endsWith(ext.key)) {
def ext_list = path_list.collect()
ext_list.add(ext.value)
return "${getPathFromList(ext_list)}/$args.filename"
}
}
} else if (ioptions.publish_files == null) {
return "${getPathFromList(path_list)}/$args.filename"
}
}
}