This is a test version of Biostars. For the public version, visit https://www.biostars.org.
FeatureCounts Error (ERROR: temporary directory is not writable)

Hi.

Ive been trying to run feaureCounts on my bam files, however I keep getting this error:

ERROR: temporary directory is not writable: '/mnt/data/GROUP-sbiim1/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/star/sortedbycoord/featurecounts//mnt/data/GROUP-sbiim1/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/star/sortedbycoord'

Which is odd because I've been working with trimmomatic, star, and picard and I haven't had any issue like this. My script is as follows:

    #!/bin/bash
#SBATCH --partition=defq       # the requested queue
#SBATCH --nodes=1              # number of nodes to use
#SBATCH --tasks-per-node=1     #
#SBATCH --cpus-per-task=2      #
#SBATCH --mem-per-cpu=10G       # in megabytes, unless unit explicitly stated
#SBATCH --time=3:0:0
#SBATCH --error=%J.err         # redirect stderr to this file
#SBATCH --output=%J.out        # redirect stdout to this file
#SBATCH --mail-type=BEGIN,END,FAIL     # email on job start, end, and/or failure


#Load module

module load subread-2.0.0-gcc-8.3.1-l7x34bp

#Shortcuts

workingdir=/mnt/data/GROUP-sbiim1/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/star/sortedbycoord
refdir=/mnt/scratch/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/genomeDir


#Make storage directory

mkdir $workingdir/featurecounts

#Loop and run featue counts command

LIST=$workingdir/*Aligned.sortedByCoord.out.bam

for i in $LIST;
do
        featureCounts -T 4 -s 0 \
                -a $refdir/Mus_musculus.GRCm39.104.gtf \
                -o $workingdir/featurecounts/$i.featurecount \
                $workingdir/$i
done

Any help would be much appreciated.

rna-seq featurecounts

main issue is likely not having write permission in that specific directory (I know :) ). Can you post the permission status of that folder? Did you script create that featurecount directory in it?

moreover, in your loop you are writing/reading from a dir that I think is not what you expect. Can you add an echo $i in your loop? At first sight $i will also include the directory name again, so likely something will go awol there.

Noob question but how would I check the permission status in linux? Yes, it did create the featurecounts directory (nothing in it though).

I've added the echo (see below)

LIST=$workingdir/*Aligned.sortedByCoord.out.bam

for i in $LIST;
do
        echo $i
        featureCounts -T 4 -s 0 \
                -a $refdir/Mus_musculus.GRCm39.104.gtf \
                -o $workingdir/featurecounts/$i.featurecount \
                $workingdir/$i
done

And I got this in my out log file:

/mnt/data/GROUP-sbiim1/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/star/sortedbycoord/Sample10merge_trimmed_2.fastq.gz-.Aligned.sortedByCoord.out.bam
/mnt/data/GROUP-sbiim1/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/star/sortedbycoord/Sample11merge_trimmed_2.fastq.gz-.Aligned.sortedByCoord.out.bam
/mnt/data/GROUP-sbiim1/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/star/sortedbycoord/Sample12merge_trimmed_2.fastq.gz-.Aligned.sortedByCoord.out.bam
/mnt/data/GROUP-sbiim1/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/star/sortedbycoord/Sample13merge_trimmed_2.fastq.gz-.Aligned.sortedByCoord.out.bam
/mnt/data/GROUP-sbiim1/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/star/sortedbycoord/Sample1merge_trimmed_2.fastq.gz-.Aligned.sortedByCoord.out.bam
/mnt/data/GROUP-sbiim1/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/star/sortedbycoord/Sample2merge_trimmed_2.fastq.gz-.Aligned.sortedByCoord.out.bam
/mnt/data/GROUP-sbiim1/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/star/sortedbycoord/Sample3merge_trimmed_2.fastq.gz-.Aligned.sortedByCoord.out.bam
/mnt/data/GROUP-sbiim1/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/star/sortedbycoord/Sample4merge_trimmed_2.fastq.gz-.Aligned.sortedByCoord.out.bam
/mnt/data/GROUP-sbiim1/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/star/sortedbycoord/Sample5merge_trimmed_2.fastq.gz-.Aligned.sortedByCoord.out.bam
/mnt/data/GROUP-sbiim1/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/star/sortedbycoord/Sample6merge_trimmed_2.fastq.gz-.Aligned.sortedByCoord.out.bam
/mnt/data/GROUP-sbiim1/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/star/sortedbycoord/Sample7merge_trimmed_2.fastq.gz-.Aligned.sortedByCoord.out.bam
/mnt/data/GROUP-sbiim1/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/star/sortedbycoord/Sample8merge_trimmed_2.fastq.gz-.Aligned.sortedByCoord.out.bam
/mnt/data/GROUP-sbiim1/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/star/sortedbycoord/Sample9merge_trimmed_2.fastq.gz-.Aligned.sortedByCoord.out.bam

Figured it out lol. Permission status is as follows:

drwxr-xr-x. 3 c1818206 biosi    4096 Jun 30 17:42 sortedbycoord

Hi all,

I got a similar error: ERROR: temporary directory is not writable: 'Users/Chris/Bash_script/quants'.

My code:

featureCounts -s 2 -a Users/Chris/Bash_script/hg38/Homo_sapiens.GRCh38.106.gtf -o Users/Chris/Bash_script/quants/demo_featurecounts.txt Users/Chris/Bash_script/HISAT2/demo_trimmed.bam

Would anyone please tell me how to fix it? Thank you so much!

You are most likely missing a leading / in front of all file paths.

Users/Chris/Bash_script/hg38/Homo_sapiens.GRCh38.106.gtf

needs to be

/Users/Chris/Bash_script/hg38/Homo_sapiens.GRCh38.106.gtf

Thank GenoMax for your suggestion!

I tried to add / like this:

featureCounts -s 2 -a /Users/Chris/Bash_script/hg38/Homo_sapiens.GRCh38.106.gtf -o /Users/Chris/Bash_script/quants/demo_featurecounts.txt /Users/Chris/Bash_script/HISAT2/demo_trimmed.bam

Then I got a different error:

Failed to open the annotation file /Users/Chris/Bash_script/hg38/Homo_sapiens.GRCh38.106.gtf, or its format is incorrect, or it contains no 'exon' features.

Looks like /Users/Chris/Bash_script/hg38/Homo_sapiens.GRCh38.106.gtf file path is not correct. Make sure you provide correct path for all files. I assume you have simply downloaded Ensembl GTF file and have not made any changes, so "exon" part is not applicable.

You are right. For some reasons, the correct path is:

/Users/Chris/Bash_script/hg38/Homo_sapiens.GRCh38.107.gtf

1 answer

I think it's because you have an error in your code, you have the directory appearing twice.

LIST=$workingdir/*Aligned.sortedByCoord.out.bam

for i in $LIST;
do
        echo $i
        featureCounts -T 4 -s 0 \
                -a $refdir/Mus_musculus.GRCm39.104.gtf \
                -o $workingdir/featurecounts/$i.featurecount \

## so here you are actually getting -o $workingdir/featurecounts/$workingdir/(SAMPLE_X)Aligned.sortedByCoord.out.bam


                $workingdir/$i
done

Try this instead:

LIST=$workingdir/*Aligned.sortedByCoord.out.bam

for i in $LIST;
do
        echo $i
SAMPLE=$basename($i .bam).featurecount

        featureCounts -T 4 -s 0 \
                -a $refdir/Mus_musculus.GRCm39.104.gtf \
                -o $SAMPLE
                $workingdir/$i
done

Also as a side note you don't need to loop, you can easily just go with one line:

featureCounts -T 4 -s 0 -a /mnt/scratch/c1818206/fastqs/merged_files/trimmedfiles/trimmedfiles_final/genomeDir/Mus_musculus.GRCm39.104.gtf -o counts.file *.Aligned.sortedByCoord.out.bam

Hope you get it working!

Hi,

Yes - I figured out that I didn't need to loop featurecounts. So I did away with the loop and it worked! This has been my first time going through an RNAseq pipline with my own data so its been a challenge but also rewarding.

Thank you very much for your comment; it is the answer so I'll mark it now :)

Log in to answer this question.