diff --git a/src/RNAseq_XGR.nf b/src/RNAseq_XGR.nf
index 299234076703463c78597fe3d5fa9c414fedde78..45b2ace393e20e43b4e32e56fed92ce9617ab326 100644
--- a/src/RNAseq_XGR.nf
+++ b/src/RNAseq_XGR.nf
@@ -151,6 +151,7 @@ workflow {
     Channel
       .fromPath( idx_genome )
       .ifEmpty { error "Cannot find idexed genome reference files" }
+      .map{it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]}
       .set { genome_indexed_input }
     mapping_withindex(genome_indexed_input, fastp.out.fastq)
   }
diff --git a/src/nf_modules/star/main_2.7.8a.nf b/src/nf_modules/star/main_2.7.8a.nf
index 44e6693522af0b190b3d6e19c63c8db54603ed74..13d0af19c9320b16c8315e7928f764381f7f4d9a 100644
--- a/src/nf_modules/star/main_2.7.8a.nf
+++ b/src/nf_modules/star/main_2.7.8a.nf
@@ -181,6 +181,59 @@ STAR --runThreadN ${task.cpus} \
 --outSAMstrandField intronMotif \
 --chimOutType WithinBAM
 
+mv ${reads_id}.Aligned.sortedByCoord.out.bam ${reads_id}.bam
+"""
+}
+
+
+process mapping_withindex {
+  container = "${container_url}"
+  label "big_mem_multi_cpus"
+  if (params.star_mapping_fastq_out != "") {
+    publishDir "results/${params.star_mapping_fastq_out}", mode: 'copy'
+  }
+
+  input:
+    tuple val(index_id), path(index)
+    tuple val(reads_id), path(reads) 
+
+  output:
+    path "*.Log.final.out", emit: report
+    tuple val(reads_id), path("*.bam"), emit: bam
+
+  script:
+if (reads_id instanceof List){
+    file_prefix = reads_id[0]
+  } else {
+    file_prefix = reads_id
+  }
+
+if (reads.size() == 2)
+"""
+STAR --runThreadN ${task.cpus} \
+--genomeDir index/ \
+--readFilesCommand zcat \
+--readFilesIn ${reads[0]} ${reads[1]} \
+--outFileNamePrefix ${reads_id}. \
+--alignIntronMax 10000 \
+--outSAMtype BAM SortedByCoordinate \
+--outSAMstrandField intronMotif
+
+mv ${reads_id}.Aligned.sortedByCoord.out.bam ${reads_id}.bam
+"""
+else
+"""
+mkdir -p index
+mv ${index} index/
+STAR --runThreadN ${task.cpus} \
+--genomeDir index/ \
+--readFilesCommand zcat \
+--readFilesIn ${reads} \
+--outFileNamePrefix ${reads_id}. \
+--alignIntronMax 10000 \
+--outSAMtype BAM SortedByCoordinate \
+--outSAMstrandField intronMotif
+
 mv ${reads_id}.Aligned.sortedByCoord.out.bam ${reads_id}.bam
 """
 }
\ No newline at end of file