# bedtools unable to open file despite being tab-delimited

I got the following error when attempting to intersect two files. The file below is supposed to be the -a file.

Error: Unable to open file compare_me_to.txt. Exiting.


When I attempted to make it tab-delimited through Ubuntu (see code below)

perl -p -i -e 's/ /\t/g' compare_me_to.txt


I got the following error:

Can't open compare_me_to: Permission denied.


Additionally, the ownership of the folder the files are in is of my username. I can't tell if this is a bedtools problem or a Ubuntu problem or something else.

• Just a quick check since you said you have ownership of the file... The file isn't open anywhere else (like in another shell or on desktop) when you try to convert right? – d_kennetz Mar 6 '19 at 21:18

I suspect the reason is the "-i". The following will work,

perl -pe 's/  */\t/g' compare_me_to.txt > compare_me_to.txt2


-i will want to write onto the file and create a backup. I suspect you'll have spotted chmod +w compare_me_to.txt.

Just make sure that a double space is inserted before the * character, otherwise it will go wrong. Copying and pasting will avoid this.

This is a clearer solution because it avoids missing a space character,

perl -e 's/[ ][ ]*/\t/g' compare_me_to.txt > compare_me_to.txt2


and the solution you used .. (I did on OS X), what I'd recommend is,

perl -p -e 's/[ ][ ]*/\t/g' compare_me_to.txt # to see if it works by printing on screen without altering the file

perl -i -e 's/[ ][ ]*/\t/g' compare_me_to.txt


The -i flag will alter the original file and store a backup without requiring renaming the file.

What's it doing? The regex [ ][ ]* structure is saying look a space and if one or more spaces occur adjacent to each other replace everything with a single tab. [ ]* means a "space" that is present or absent and if present it can be present an infinite number of times. If the [ ]* is by itself the command risks saying replace '' (zip) or 'space' with a tab, so tabs can appear at every '' (zilch), so tabs can appear everywhere. The "*" symbol in regex work differently to the "*" wildcard character in shell.

• The following error appears: Can't open compare_me_to.txt: Permission denied. – DangIt Mar 11 '19 at 6:51
• I was able to give myself permission (askubuntu.com/questions/466605/…), but the file still can't be opened when intersecting. I ran the line of code you wrote; when I opened the resulting file, every character was separated by a tab. – DangIt Mar 11 '19 at 7:20
• Oh I know, you put a single space into the term ... its a double space followed by a *. so its ... 's/ */\t/g' ... if you only put a single space into the first / */ then it will result in tabs going everywhere. I can explain later. – Michael G. Mar 11 '19 at 12:39
• chmod 700 file_name is another way in, I'm surprised chmod +w file_name didn't work if you were the file owner. I assumed you knew about chown and chmod – Michael G. Mar 11 '19 at 12:42