script bash for counting
2
0
Entering edit mode
4.5 years ago
dorra.fass • 0

Hello,

I'm a beginner in writing script bash. I need your help to execute the featurecounts command for counting purposes for 10 mapped files corresponding to 10 samples located in 10 different directories. Please help me to get a right script. bash start code

#!/bin/bash

SOURCE_DIR_1=$/scratch/mapping_results/1
SOURCE_DIR_2=$/scratch/mapping_results/2
SOURCE_DIR_3=$/scratch/mapping_results/3
SOURCE_DIR_4=$/scratch/mapping_results/4
SOURCE_DIR_5=$/scratch/mapping_results/5
SOURCE_DIR_6=$/scratch/mapping_results/6
SOURCE_DIR_7=$/scratch/mapping_results/7
SOURCE_DIR_8=$/scratch/mapping_results/8
SOURCE_DIR_9=$/scratch/mapping_results/9
SOURCE_DIR_10=$/scratch/mapping_results/10

TARGET_DIR=$/scratch/counting

echo 'Going to $SOURCE_DIR'
cd $SOURCE_DIR

FILE_ARRAY=/$(locate Alignment.sam)

for file in $FILE_ARRAY; do
  featureCounts -t $SOURCE_DIR/$file -a /scratch/human/hg19.gtf -o $TARGET_DIR$....
  done
rna-seq • 1.5k views
ADD COMMENT
1
Entering edit mode

If you want to write counts for each sam file, into corresponding count file:

$ for i in $(seq 1 10); do
echo featureCounts -t "/scratch/mapping_results/$i/Alignment.sam" -a /scratch/human/hg19.gtf -o "/scratch/counting/$i.txt";
done

featureCounts -t /scratch/mapping_results/1/Alignment.sam -a /scratch/human/hg19.gtf -o /scratch/counting/1.txt
featureCounts -t /scratch/mapping_results/2/Alignment.sam -a /scratch/human/hg19.gtf -o /scratch/counting/2.txt
featureCounts -t /scratch/mapping_results/3/Alignment.sam -a /scratch/human/hg19.gtf -o /scratch/counting/3.txt
featureCounts -t /scratch/mapping_results/4/Alignment.sam -a /scratch/human/hg19.gtf -o /scratch/counting/4.txt
featureCounts -t /scratch/mapping_results/5/Alignment.sam -a /scratch/human/hg19.gtf -o /scratch/counting/5.txt
featureCounts -t /scratch/mapping_results/6/Alignment.sam -a /scratch/human/hg19.gtf -o /scratch/counting/6.txt
featureCounts -t /scratch/mapping_results/7/Alignment.sam -a /scratch/human/hg19.gtf -o /scratch/counting/7.txt
featureCounts -t /scratch/mapping_results/8/Alignment.sam -a /scratch/human/hg19.gtf -o /scratch/counting/8.txt
featureCounts -t /scratch/mapping_results/9/Alignment.sam -a /scratch/human/hg19.gtf -o /scratch/counting/9.txt
featureCounts -t /scratch/mapping_results/10/Alignment.sam -a /scratch/human/hg19.gtf -o /scratch/counting/10.txt

.

parallel --dry-run featureCounts -t /scratch/mapping_results/{}/Alignment.sam -a /scratch/human/hg19.gtf -o /scratch/counting/{}.txt ::: $(seq 1 10)

Probably you would not need a loop, as featurecounts writes each sample in a separate column. For all the samples (.sam), you can generate one single counts files where in each sample is represented one column with sample name.

ADD REPLY
0
Entering edit mode

thank you so much for your help the script was executed with success

ADD REPLY
0
Entering edit mode

Dear all,

Thank you so much for your responses and for your help I tried the following script

#!/bin/bash

SOURCE_DIR=/scratch/mapping_results/
TARGET_DIR=/scratch/counting

for SUBDIR in $(seq 1 10); do
featureCounts -t "$SOURCE_DIR/$SUBDIR/Alignment.sam" -a /scratch/human/hg19.gtf -o "$TARGET_DIR$"
done

Unfortunaltely i obtained only the counting results of sample 10 not all the samples. What can i do to resolve this problem in order to obtain counting results for each sample? Thanks a lot

ADD REPLY
0
Entering edit mode

How many samples do you have? Are all /scratch/mapping_results/NN? The example only listed 1-10 ...

ADD REPLY
1
Entering edit mode
4.5 years ago
JC 13k
#!/bin/bash

SOURCE_DIR=/scratch/mapping_results/
TARGET_DIR=/scratch/counting

for SUBDIR in $(seq 1 10); do
  featureCounts -t "$SOURCE_DIR/$SUBDIR/Alignment.sam" -a /scratch/human/hg19.gtf -o "$TARGET_DIR/$...".
done

Check https://www.gnu.org/software/bash/manual/

ADD COMMENT
0
Entering edit mode
4.5 years ago

I think, It would be like this:

for i in /scratch/mapping_results*
do 
    cd $i
    #optional; use echo pwd and check the where you are
    x=$(pwd)
    echo $(pwd)   
    featureCounts -t alignment.sam (or $x/alignment.sam) /scratch/human/hg19.gtf -o $TARGET_DIR$
    cd ../
done
ADD COMMENT

Login before adding your answer.

Traffic: 1850 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6