From 38adb65018141180b9ede9ddedece9e40ac6be57 Mon Sep 17 00:00:00 2001 From: ens-ftricomi Date: Wed, 14 Aug 2024 14:31:51 +0100 Subject: [PATCH] retry when file reading didn't work --- .../transcriptomic_alignment/index_genome.nf | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pipelines/nextflow/modules/transcriptomic_alignment/index_genome.nf b/pipelines/nextflow/modules/transcriptomic_alignment/index_genome.nf index af203c2..c3ab961 100644 --- a/pipelines/nextflow/modules/transcriptomic_alignment/index_genome.nf +++ b/pipelines/nextflow/modules/transcriptomic_alignment/index_genome.nf @@ -47,11 +47,15 @@ process INDEX_GENOME { // Initialize variables def numberOfReferences = 0 def genomeLength = 0 - // Read the FASTA file line by line - genomefilePath.eachLine { line -> - if (line.startsWith('>')) { - numberOfReferences++ - } else { + def retryCount = 0 + def maxRetries = 3 + def filesValid = false + while (!filesValid && retryCount < maxRetries) { + // Read the FASTA file line by line + genomefilePath.eachLine { line -> + if (line.startsWith('>')) { + numberOfReferences++ + } else { genomeLength += line.trim().length() } } @@ -66,6 +70,10 @@ process INDEX_GENOME { // Calculate the genome length (excluding header lines) //def genomeLength = fastaContent.split('\n').findAll { !it.startsWith('>') }.join('').length() + if (genomeLength != 0) { + filesValid = true + } + } // Define read length (you may need to adjust this based on your data) def readLength = 100 @@ -97,6 +105,6 @@ process INDEX_GENOME { """ } - } +}