From 82f6199613855f971036b0ee39bd153a7bb2e82d Mon Sep 17 00:00:00 2001
From: rlegendre <rachel.legendre@pasteur.fr>
Date: Fri, 30 Dec 2022 13:57:24 +0100
Subject: [PATCH] fix some code issues

---
 workflow/rules/kallisto_index.rules |  2 +-
 workflow/rules/kallisto_quant.rules |  2 +-
 workflow/rules/sortmerna.rules      |  4 ++--
 workflow/rules/star_index.rules     | 13 +++++++------
 4 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/workflow/rules/kallisto_index.rules b/workflow/rules/kallisto_index.rules
index 738aeda..879418d 100755
--- a/workflow/rules/kallisto_index.rules
+++ b/workflow/rules/kallisto_index.rules
@@ -35,7 +35,7 @@ rule kallisto_index:
     log:
         kallisto_index_log
     threads:
-        config['pseudomapping']['threads']
+        config['kallisto']['threads']
     envmodules:
         "kallisto/0.46.2"
     shell:
diff --git a/workflow/rules/kallisto_quant.rules b/workflow/rules/kallisto_quant.rules
index 56f2b29..a17d425 100755
--- a/workflow/rules/kallisto_quant.rules
+++ b/workflow/rules/kallisto_quant.rules
@@ -37,7 +37,7 @@ rule kallisto_quant:
     log:
         kallisto_pseudo_log
     threads:
-        config['pseudomapping']['threads']
+        config['kallisto']['threads']
     envmodules:
         "kallisto/0.46.2"
     shell:
diff --git a/workflow/rules/sortmerna.rules b/workflow/rules/sortmerna.rules
index 58e89a5..9fed2f6 100755
--- a/workflow/rules/sortmerna.rules
+++ b/workflow/rules/sortmerna.rules
@@ -74,13 +74,13 @@ rule sortmerna:
             mv out_paired_rev.fq${{ext}} {{outnorRNA[1]}}
             mv out_paired_ribo_fwd.fq${{ext}} {{outrRNA[0]}}
             mv out_paired_ribo_rev.fq${{ext}} {{outrRNA[1]}}
-            mv output.rRNA.log {log.out}
+            #mv output.rRNA.log {log.out}
 
         else
             sortmerna --ref ${{fasta}} --idx-dir ${{idxdir}} --workdir {params.tmpdir}/{wildcards.SAMPLE} -threads {threads} --reads {input.fastq} --aligned output.rRNA --fastx --other output.no_rRNA  -v  > {log.out} 2> {log.err}
             mv output.no_rRNA.fq${{ext}} {output.no_rRNA}
             mv output.rRNA.fq${{ext}} {output.rRNA}
-            mv output.rRNA.log {log.out}
+            #mv output.rRNA.log {log.out}
         fi
 
 
diff --git a/workflow/rules/star_index.rules b/workflow/rules/star_index.rules
index aedc51e..b14843f 100755
--- a/workflow/rules/star_index.rules
+++ b/workflow/rules/star_index.rules
@@ -43,18 +43,19 @@ rule star_index:
     shell:
         """
         set +o pipefail
-        GenomeLength=`grep -v ">" {input} | tr -d '\n' | wc -c`
+        GenomeLength=`grep -v ">" {input.fasta} | tr -d '\n' | wc -c`
         SAindex=$(echo $GenomeLength | awk '{{a=log($1)/2 - 1; if (a>14) a=14; printf("%d\\n",a)}}')
-        
-        
+        NumberOfReferences=`grep -c ">" {input.fasta}`
+        ChrBin=$(echo | awk -v g=$GenomeLength -v n=$NumberOfReferences '{{a=log(g/n); if (a>18) a=18; printf("%d\\n",a)}}' )
+
         if [[ -s {input.gff_file} && {input.gff_file} == "*.gtf"  ]]
         then
-            STAR --runMode genomeGenerate --genomeFastaFiles {input.fasta} --genomeDir {params.wkdir} --runThreadN {threads} --sjdbGTFfile {input.gff_file} --genomeSAindexNbases $SAindex
+            STAR --runMode genomeGenerate --genomeFastaFiles {input.fasta} --genomeDir {params.wkdir} --runThreadN {threads} --sjdbGTFfile {input.gff_file} --genomeSAindexNbases $SAindex --genomeChrBinNbits $ChrBin
         elif [[ -s {input.gff_file} && {input.gff_file} == "*.gff" ]]
         then
-             STAR --runMode genomeGenerate --genomeFastaFiles {input.fasta} --genomeDir {params.wkdir} --runThreadN {threads} --sjdbGTFfile {input.gff_file} --sjdbGTFtagExonParentTranscript Parent --genomeSAindexNbases $SAindex
+             STAR --runMode genomeGenerate --genomeFastaFiles {input.fasta} --genomeDir {params.wkdir} --runThreadN {threads} --sjdbGTFfile {input.gff_file} --sjdbGTFtagExonParentTranscript Parent --genomeSAindexNbases $SAindex --genomeChrBinNbits $ChrBin
         else
-            STAR --runMode genomeGenerate --genomeFastaFiles {input.fasta} --genomeDir {params.wkdir} --runThreadN {threads} --genomeSAindexNbases $SAindex
+            STAR --runMode genomeGenerate --genomeFastaFiles {input.fasta} --genomeDir {params.wkdir} --runThreadN {threads} --genomeSAindexNbases $SAindex --genomeChrBinNbits $ChrBin
         fi
         
         samtools faidx {input.fasta}
-- 
GitLab