script bash for counting
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
• 2,037 views
•
link
2 answers
#!/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
• 0 views
•
link
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
• 0 views
•
link
Log in to answer this question.
Dear all,
Thank you so much for your responses and for your help I tried the following script
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
How many samples do you have? Are all /scratch/mapping_results/NN? The example only listed 1-10 ...
If you want to write counts for each sam file, into corresponding count file:
.
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.
thank you so much for your help the script was executed with success