Entering edit mode
4.0 years ago
C_sinensis
▴
30
Hello,
I am trying to execute a very simple grep command, but I can't get it to work and I cannot figure out why. Here is exactly what I am doing:
echo 'ACTTTATTA' > myseq
cat myseq
ACTTTATTA
grep -E '^.{2}TTT' myseq
No results
I am trying to grep a sequence that has 3 Ts starting from the third nucleotide, just like the one I am creating above. But I get no output. The error seems to come from {2}, because I have been able to reproduce this behaviour only when I introduce {number} and it gets solved when I replace it by something else.
I have:
Tested it in a different computer
Tested it in google colab
Tested it in regex101 (it works as expected)
What am I doing wrong?
What's the exclamation mark before the
grep
?This worked for me:
ACTTTATTA
This should work too
Thank you! The "!" sign is used in google colab to execute a terminal command. I included it by mistake and have corrected it.
It looks like your command works in my computer but does not work in google colab. Can this be due to some different version of grep? Do you think you could check that your code indeed does not work in your hands in google colab jut to make sure I am not messing up?
I don't use googlecolab, but maybe you can use
awk
or try using"
instead of'
and see if it works there:The following worked for me:
You should also be able to use
egrep
, as well as the more constrained pattern^[ACTG]{2}TTT
, if you need to:Thank you! As I replied to Fatima above, those seem to work in my computer, but not in google colab, which I need to use for this project. Any chance you have some idea why this might be?
I don't use Google Colab. I'm afraid I'm not much help there. If you have a reproducible issue, you could maybe file it here? https://github.com/googlecolab/colabtools/issues
I wonder if python is doing something to the
{2}
. Could you try:and then check the file?
I think you hit the nail on the head. Something is off:
grep -E ^.2TTT myseq
I was able to solve it by first defining a python string and then executing such string:
XCTTTATTA
Thank you! That was a very good catch. I wonder if there is another solution though...
It could maybe be solved by different quoting or escaping characters, but I never use such things for shell commands so I wouldn't know.
Have you tried this one?
@OP, is this solved, can one or many of the comments be moved to answer?