As suggested by others, you could use basic understanding of LInux and bash
commands before attempting to do more complex things. What you are trying to do can't be done, and I will try to explain it briefly.
Your command:
for sam in *.sam do samtools view -bo${sam%.sam}.bam ${sam} done
should probably be like this if you want everything on a single line:
for sam in *.sam; do echo "samtools view -bo${sam%.sam}.bam ${sam}"; done
So what does for sam in *.sam
mean to you? It says to the system to look for all the files in present directory that end in .sam
(that's the *.sam
part), to iterate through them one by one, and assign real file names to a variable called sam
. Now, if you don't have any files ending in .sam
in your current directory, the command has nothing to do and will give the error you see. It doesn't matter what .fastq.bz2
or other files you have there, because they won't even be considered by your command. To see what command the system is trying to run, enclose the command itself into quotation marks and put echo
in front of it, like this:
for sam in *.sam; do echo "samtools view -bo${sam%.sam}.bam ${sam}"; done
You should get something like this:
samtools view -bo*.bam *.sam
And that command throws the error you listed above, because, again, there are no .sam
files in your directory. You can create two "fake" and empty .sam
file by typing touch empty.sam; touch empty2.sam
. If you try the for ...
command now, it will print this on the screen:
samtools view -boempty.bam empty.sam
samtools view -boempty2.bam empty2.sam
This tells you what command the system would execute when there are 2 actual files with names ending in .sam
, but of course nothing would come out of those commands because you created empty files.
I think you would do yourself a big favor by learning basics of Linux and bash scripting before moving forward. I took the time to explain in steps why your command didn't work, but don't get used to it. This forum is not meant for the type of questions you have been asking. It isn't that people don't want to help. It is that you seem so far away from being able to do something meaningful, and most people here understand that answering your questions would only move you a tiny bit closer and another similar question will be forthcoming very soon. I think you will need to learn these basic steps on your own, as I suggested to you about a week ago, and others have as well.
It's not want you want to hear but you are posting basically every problem in your analysis pipeline because it seems you are lacking both Unix knowledge and bioinformatics basics. It is hard to get started, I know, we all were at this point. I strongly suggest to either follow one of the many tutorials for preprocessing of NGS files found via your favourit search engine or use existing pipelines such as nf-core. Here, you are trying to open SAM files but you say you start with which makes no sense at all. It is fastq, then alignment to get sam or bam, and then downstream analysis. Please follow some guided tutorial first.