No Such File Or Directory - Errno::Enoent - Error Only Occurs In Ubuntu - It Works Perfectly In Windows
1
0
Entering edit mode
10.7 years ago
IsmailM ▴ 110

Hello,

I'm trying to extract sequence IDs from a fasta file. This script (see below) works perfectly in windows 8, however when I run the script in Ubuntu, it gives me the following error message

./extract_name.rb:5:in `read': No such file or directory - ./motif_search.txt (Errno::ENOENT)                   from ./extract_name.rb:5

This occurs despite a motif_search.txt file present in the right directory. In Windows, the folder is in a hard drive, which I copied and pasted into the home folder in Ubuntu - i.e. everything is the same.

The Script:

#!/usr/bin/env ruby

filename = ARGV.first
text = File.read(filename)
entryid = />.\S+/i

text.scan(entryid) do |output|
    puts output
end

I run it by typing this into the terminal/ command prompt

ruby ./extract_name.rb ./motif_search.txt > ./seq_ID.txt

I need the script to run in ubuntu since I will be developing the script further to include one or two things that are only supported in ubuntu or mac.

What I have done so far...

If I remove the script and replace it with - puts "hello" - (and type into the terminal -- ruby ./extract_name.rb > ./seq_ID.txt), It works perfectly.

Also I have removed everything and typed the below and it gave the right directory.

puts Dir.pwd

Any help would be most appreciated

error • 11k views
ADD COMMENT
2
Entering edit mode
10.7 years ago

This question is probably better suited to be asked on StackOverflow - I am answering it mainly because it is clear that you are solving a bioinformatics problem - hence it is on topic ;-)

A general advice is that whenever you have a stupefying error that just can't be explained you need to think outside the box and revaluate your tacit assumptions. For example in your case just copying over files from windows to Unix is bound to lead to some troubles as new line representation are different between the platforms.

A 'file does not exist error' is always correct. You get it when the file does not exist. End of story. What you need to reevaluate why is it that you are convinced that the file exists - or alternatively what are you actually passing to the program that is not the file.

what happens if you just do a

more motif_search.txt

note that prepending filenames with ./ do nothing in your case, it just makes the command uglier. What kind of ruby is being started up?

which ruby

what happens with a program that would just directly open the file by name etc.

text = File.read("motif_search.txt")

Write your program with a Linux editor. etc

ADD COMMENT
0
Entering edit mode

The new line issue can definitely cause a 'file does not exist error'. I've had that happen a few times when copying files from a Windows box to a Unix server.

ADD REPLY
0
Entering edit mode

Many Thanks, I carried out the above suggestions and when it did not work when directly specifying the file within the script, I decided to use the terminal to 'ls' all the files in the directory. This showed the file as "motif_search.txt?". What was actually happening was that, the executable .bat file that was used to run a different script, creating the motif_search.txt file, actually put a space or something after the name so that the second script (this one) wasn't recognising the filename Simply rewriting the bat solved the problem.

Thank you all for all of your help - it is most appreciated. Many Thanks

ADD REPLY

Login before adding your answer.

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