I am trying to map reads with `rsem-calculate-expression` using STAR aligner using a loop, however I am getting an error of the STARtemp folder not being deleted after the first run, hence it is stopping the next run. What wrong I am doing ?

1. I have changed the permission in `..\test_results` folder
2. I am running on the same number of nodes as the threads requested.

this is my code

    for prefix in $(ls *.fastq.gz | rev | cut -c 12-| rev | uniq)
    do
    rsem-calculate-expression --star \
                            --star-path /share/pkg/star/2.7.0e/bin \
                            --star-gzipped-read-file \
                            -p 4 \
                            --paired-end \
                            "${prefix}R1.fastq.gz" "${prefix}R2.fastq.gz" \
                            ../genome_indices/rsem-star/rsem-star \
                            ../test_results2/"${prefix}res"
    done

This is the error part of the output


    Expression Results are written!
    1000000 alignment lines are loaded!
    2000000 alignment lines are loaded!
    3000000 alignment lines are loaded!
    4000000 alignment lines are loaded!
    5000000 alignment lines are loaded!
    Bam output file is generated!
    Time Used for EM.cpp : 0 h 02 m 50 s
    
    rm -rf ../test_results/G20P1sc-C05-res.temp
    rm: cannot remove `../test_results/G20P1sc-C05-res.temp/.nfs000000047fe2b1c700000f07': Device or resource busy
    rm: cannot remove `../test_results/G20P1sc-C05-res.temp/.nfs00000004809fdb5b00000f06': Device or resource busy
    rm: cannot remove `../test_results/G20P1sc-C05-res.temp/.nfs0000000480b151e000000f09': Device or resource busy
    rm: cannot remove `../test_results/G20P1sc-C05-res.temp/.nfs000000048022bb5100000f08': Device or resource busy
    Fail to delete the temporary folder!

    "rm -rf ../test_results/G20P1sc-C05-res.temp" failed! Plase check if you provide correct parameters/options for the pipeline!
    /share/pkg/star/2.7.0e/bin/STAR --genomeDir ../genome_indices/rsem-star  --outSAMunmapped Within  --outFilterType BySJout  --outSAMattributes NH HI AS NM MD  --outFilterMultimapNmax 20  --outFilterMismatchNmax 999  --outFilterMismatchNoverLmax 0.04  --alignIntronMin 20  --alignIntronMax 1000000  --alignMatesGapMax 1000000  --alignSJoverhangMin 8  --alignSJDBoverhangMin 1  --sjdbScore 1  --runThreadN 4  --genomeLoad NoSharedMemory  --outSAMtype BAM Unsorted  --quantMode TranscriptomeSAM  --outSAMheaderHD \@HD VN:1.4 SO:unsorted  --outFileNamePrefix ../test_results/G20P1sc-C08-res.temp/G20P1sc-C08-res  --readFilesCommand zcat  --readFilesIn G20P1sc-C08-R1.fastq.gz G20P1sc-C08-R2.fastq.gz
    
    EXITING because of fatal ERROR: could not make temporary directory: ../test_results/G20P1sc-C08-res.temp/G20P1sc-C08-res_STARtmp/
    SOLUTION: (i) please check the path and writing permissions 
     (ii) if you specified --outTmpDir, and this directory exists - please remove it before running STAR

    Jun 01 13:30:25 ...... FATAL ERROR, exiting
    "/share/pkg/star/2.7.0e/bin/STAR --genomeDir ../genome_indices/rsem-star  --outSAMunmapped Within  --outFilterType BySJout  --outSAMattributes NH HI AS NM MD  --outFilterMultimapNmax 20  --outFilterMismatchNmax 999  --outFilterMismatchNoverLmax 0.04  --alignIntronMin 20  --alignIntronMax 1000000  --alignMatesGapMax 1000000  --alignSJoverhangMin 8  --alignSJDBoverhangMin 1  --sjdbScore 1  --runThreadN 4  --genomeLoad NoSharedMemory  --outSAMtype BAM Unsorted  --quantMode TranscriptomeSAM  --outSAMheaderHD \@HD VN:1.4 SO:unsorted  --outFileNamePrefix ../test_results/G20P1sc-C08-res.temp/G20P1sc-C08-res  --readFilesCommand zcat  --readFilesIn G20P1sc-C08-R1.fastq.gz G20P1sc-C08-R2.fastq.gz" failed! Plase check if you provide correct parameters/options for the pipeline!


I found out that the ```. nfs000000047fe2b1c700000f07``` type files are the problem. 

Once I directed the output to a new folder, it solved the issue :) 