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
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.
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