I am trying to create a code that will use all the bam files stored on a separate drive (/media/cmccabe/C2F8EFBFF8EFAFB9/pool_I_090215), run them in a program that I have changed the directory to, and the output gets re-directed to (/home/cmccabe/Desktop/NGS/pool_I_090215). I have tried the script two ways getting two different errors and cant seem to fix it. the bold in the second error is the output so why is it looking for those files Thank you :).
cmccabe@HPZ640:~$ cd "/home/cmccabe/Desktop/NGS"
cmccabe@HPZ640:~/Desktop/NGS$ for f in /media/cmccabe/C2F8EFBFF8EFAFB9/pool_I_090215/*.bam do prefix=${f%%.bam} samtools view -H $f | sed '/^@PG/d' | samtools reheader - $f > /home/cmccabe/Desktop/NGS/pool_I_090215/${prefix}_newheader.bam done
bash: syntax error near unexpected token `|'
cmccabe@HPZ640:~/Desktop/NGS$ for f in /media/cmccabe/C2F8EFBFF8EFAFB9/pool_I_090215/*.bam
> do
> prefix=${f%%.bam}
> samtools view -H $f | sed '/^@PG/d' | samtools reheader - $f > /home/cmccabe/Desktop/NGS/pool_I_090215/${prefix}_newheader.bam
> done
bash: /home/cmccabe/Desktop/NGS/pool_I_090215//media/cmccabe/C2F8EFBFF8EFAFB9/pool_I_090215/IonXpress_008_150902_newheader.bam: No such file or directory
bash: /home/cmccabe/Desktop/NGS/pool_I_090215//media/cmccabe/C2F8EFBFF8EFAFB9/pool_I_090215/IonXpress_015_rawlib_newheader.bam: No such file or directory
bash: /home/cmccabe/Desktop/NGS/pool_I_090215//media/cmccabe/C2F8EFBFF8EFAFB9/pool_I_090215/IonXpress_016_150902_newheader.bam: No such file or directory
The below code runs but no output is created. Thank you :).
cmccabe@HPZ640:~/Desktop/NGS$ FILE=$(basename "$FILE")
cmccabe@HPZ640:~/Desktop/NGS$ for f
> do
> prefix=${f%%.bam}
> samtools view -H $f | sed '/^@PG/d' | samtools reheader - $f > /home/cmccabe/Desktop/NGS/pool_I_090215/${prefix}_newheader.bam
> done
tried this as well:
cmccabe@HPZ640:~/Desktop/NGS$ for f in /media/cmccabe/C2F8EFBFF8EFAFB9/pool_I_090215/*.bam
> FILE=$(basename "$FILE")
bash: syntax error near unexpected token `FILE=$(basename "$FILE")'
cmccabe@HPZ640:~/Desktop/NGS$ do
bash: syntax error near unexpected token `do'
cmccabe@HPZ640:~/Desktop/NGS$ prefix=${f%%.bam}
cmccabe@HPZ640:~/Desktop/NGS$ samtools view -H $f | sed '/^@PG/d' | samtools reheader - $f > /home/cmccabe/Desktop/NGS/pool_I_090215/${prefix}_newheader.bam
bash: /home/cmccabe/Desktop/NGS/pool_I_090215//media/cmccabe/C2F8EFBFF8EFAFB9/pool_I_090215/IonXpress_016_150902_newheader.bam: No such file or directory
There was nothing in this thread that set or referenced the shell variable pref until you asked this question. Without knowing how you set pref , there is no way that we can guess whether or not the shell variable expansion $pref will expand to the same string as the shell variable expansion $prefix .
for f in /media/cmccabe/C2F8EFBFF8EFAFB9/pool_I_090215/*.bam ; do
bname=`basename $f`
pref=${bname%%.bam}
samtools view -H $f | sed '/^@PG/d' | samtools reheader - $f > /home/cmccabe/Desktop/NGS/pool_I_090215/${pref}_newheader.bam
done
I also tried the below with no luck:
for f in /media/cmccabe/C2F8EFBFF8EFAFB9/pool_I_090215/*.bam ; do
bname=`basename $f`
prefix=${f%%.bam}
samtools view -H $f | sed '/^@PG/d' | samtools reheader - $f > /home/cmccabe/Desktop/NGS/pool_I_090215/${prefix}_newheader.bam
done
bash: /home/cmccabe/Desktop/NGS/pool_I_090215/media/cmccabe/C2F8EFBFF8EFAFB9/pool_I_090215/IonXpress_008_150902_newheader.bam: No such file or directory
bash: /home/cmccabe/Desktop/NGS/pool_I_090215/media/cmccabe/C2F8EFBFF8EFAFB9/pool_I_090215/IonXpress_015_rawlib_newheader.bam: No such file or directory
bash: /home/cmccabe/Desktop/NGS/pool_I_090215/media/cmccabe/C2F8EFBFF8EFAFB9/pool_I_090215/IonXpress_016_150902_newheader.bam: No such file or directory
I am just curious why the second command was looking for the output in the directory. Thank you :).