sam files
2
0
Entering edit mode
21 months ago

Hi,

I am trying to turn my .fastq.bz2 files into sam files. I am using the following script:

module load intel/2017c impi/2017.4.239 SAMtools/1.9

for sam in *.sam
do
    samtools view -bo${sam%.sam}.bam ${sam}
done

My files I'm trying to convert are in this format:

JZCY_RNAseq_ITB_CAACCATG_Arabidopsis_I1187_L1.R2.cutadapt.fastq.bz2

I am getting this error:

samtools view: failed to open "*.sam" for reading: No such file or directory

Has anyone ever gotten the error? Can someone fix my script? I have looked up similar articles on boosters, but can't find an answer to why this problem is occurring.

sam • 1.5k views
ADD COMMENT
4
Entering edit mode

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.

ADD REPLY
2
Entering edit mode
21 months ago

1) merely converting a fastq to an uncompressed, unmapped sam is almost never a useful process

2) it should be obvious from just looking at the command there, if not the error, that that command can't possibly do anything to your fastq files at all.

ADD COMMENT
1
Entering edit mode
21 months ago
Mensur Dlakic ★ 27k

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.

ADD COMMENT

Login before adding your answer.

Traffic: 2131 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