Hi,
I am working on a pipeline in a script, and want to have a specific section of my blast file in a txt file. But for some reason Linux can not work with the txt file. This is the code i use for this part:
blastn -db /exports/minor_data/BNGSA/refgenome/lclav.db -outfmt 6 -max_target_seqs 5 -query 50biggest.fasta > blastresults.txt
awk -F ' ' '{if ($3 >= "50.000" && $11 <="0.0") print $0}' blastresults.txt > Results_50_0.0.txt
And for some reason i get the error:
awk: cannot open blastresults.txt (No such file or directory).
The file is there, with the same size as the file when i do this manually. The code works manually, but when i use it in a script, it can not find the blastresults.txt file.
After some time looking I found that the text files are called 'blastresults.txt'$'\r'
instead of blastresults.txt
. And I have no clue why Linux makes this file, and how i fix this problem.
Can someone help me out?
Thanks!
Hope you have printed output location and awk execution path.
Well when i use the blastn command normal i will get the .txt file and the awk command works. But when i use it in the script, it says it can not find the file produced in the blastn command. But it is there, but it says TXT-file instead of textile behind the file. They are both the same size, so I'm really confused.
While a redirect
>
may work, you should use-out blastresult.txt
option since that is the proper way to specify an output file.can you try posting your script here?
Looks like you are missing the first
/
in your pathexports/minor_home/reads/test/blastresults.txt
onawk
command line.unfortunately, this doesnt solve the problem... Same error. I think for some reason, when i use the blast command with the script the .txt file have different properties then the one is done manually. As you can see in the picture the one above(done manually) looks like a text file, and works. But the other one looks a bit odd, and doesn't work...
./script.sh
orbash script.sh
on small set and let us know if error still exists?dos2unix
on the script file before execution.#! /bin/sh
to#! /bin/bash
(or wherever bash is installed.dos2unix
is not installed, I have to wait until i am able to install this (I'm working on a VM) 3 This doesn't make a different eitherOK,
let's take this from the top:
pwd
in the directory where you see (or think) the blastresults.txt file isls /exports/minor_home/reads/test/blastresults.txt
pwd
where you execute this scriptThe locations of the files look correct to me. The only thing is that i am not able to open the file in linux.
Just to ensure: there is actual output in the blastresults.txt?
Yes there is. When i open the file, with Notepad, I can see the blast results. But my PC also does not recognise this file, I have to select open with Notepad to see the results. When I use the blast command manually, the pc recognises the file.
Sounds like you are accessing this file on unix partition from windows side using
Notepad
. That may be the cause of issues you are observing.This used to be an issue once upon a time. This was supposed to have been fixed recently. If you don't try to open the file using Notepad do you still get the error?
When I open the file in Windows, it will open. I have to select notepad, but that's it. So no error, but the file does not change in Linux, the file cant be found. When I use the command on its own, the file looks different. If I open it in windows, it automatically opens, and I don't have to select notepad. And the file can be used in the next step.
I had a look at the files. Copied them both to windows, and for some reason, the script makes a
.txt_
file instead of a.txt
file. So that's the issue, but i don't see the reason why its making a.txt_
fileNot sure why that is happening. Closest issue that I could find where filenames got a trailing
_
in the name is this thread but it is not directly applicable in your case.You could try putting a
mv blastresults.txt_ blastresults.txt
before theawk
command to see if it fixes the problem.I tried, but the same result. Only at a different place. The error appears after the
mv
code now.I was thinking, I can make the file with
touch
first, and add the data to this file. But eventouch
makes a.txt_
file. But this only shows when its copied to windows. When in Linux it still shows just.txt
.I am using Notepad++ for this script. Can the problem be within the program itself?
This dindt fix the problem. But something else drew my attention. The weird text files are called:
'blastresults.txt'$'\r'
when I type in ls. But I don't know why Linux makes these type of files?how are you running this script? From your windows machine/environment?
best would be to export that script to your linux environment and then do run
dos2unix
on it . (or on the output files generated by your script)what you just descried is a typical thing when opening/running windows edited files in a linux enivronment (== differences in line endings between dos/windows and unix)
I am woking on my windows pc. Due to COVID-19 we are forced to work from home, so we made it possible, with the use of a VM(virtual machine) to work on the pc's at work, on our pc's at home. So I am working in Linux pc at a different location, from my own windows laptop.
I will have a look with
dos2unix
, but I think we need to install this, so I have to contact the right person.If there is an other solution, that would be great!
you can custom implement what dos2unix does indeed, however, more efficient would be to just download the binary from the internet and install it in you home folder or such.
if you are working remotely you might need to look into an SSH terminal option, such as putty, mobaXterm, ... these will provide you access to your linux machines at the lab.
Thank you, I will have a look at that.
We indeed work from a SSH terminal called Bitvise.
that should be OK as well ...
in any case: top tip: when switching data/scripts/... from windows to linux or viceversa do never consider it will work as such ;-)
if in any way possible it would be best to choose one environment (linux ;) ) and stick to it :) , thus try to avoid opening scripts in notepad and then run them in linux
In this instance, your windows laptop becomes a means to work on the remote server. I am not sure why you are using a VM at all. You can use a simple SSH program like
MobaXTerm
to access your linux machine at work.Then you said this in a following comment.
So perhaps you don't use a real VM and are confusing a local terminal with a virtual machine. It appears that
BitVise
program has an secure FTP/scp graphical interface. You may be accessing files that are on your server via what looks like windows explorer file interface.As @lieven said, if you only use the server for all of your work this odd behavior should not happen.
Well, I fixed the problem. It's the output of the Notepad++ file. It was still in windows format and added ^M to every line. I converted the line to Unix format, at it works fine now. Feel stupid to overlook this... But thanks for the help!
Add full explicit path to the result file. Especially if you are running the script in a separate shell.
I tried this, but it gives the same error. I think the problem is in the file it makes. I ran it one time with the script(with
-out
) and one time manually. I added a picture so you can see how the files look. the top blastresults.txt file is the one made manually, the other is made with the script.How is it possible to have two files with the same name in the same directory?