質問

I have a line of DNA code and I'm trying to use a Java regex expression to match the codon (3 letter sequence) to an amino acid. Below is an example of one of the patterns:

Pattern A = Pattern.compile(("gct")||("gcc")||("gca")||("gcg"));

This syntax does not seem to be working with or without the round brackets. Ultimately the aim of the code is to count the number of times the amino acid is found in the DNA string, and since there are 20 or so amino acids I have that many patterns. Can anyone help me find an elegant way of doing this?

I know I could use string1.equals(string2) etc but I would really rather use regex for it. Any help would be much appreciated!

役に立ちましたか?

解決

You're passing Pattern.compile() a boolean value, where it should be a string:

Pattern A = Pattern.compile("(gct)|(gcc)|(gca)|(gcg)");

他のヒント

This:

/("gct")||("gcc")||("gca")||("gcg")/

Equals to :

/("gtc")/

Because double || means match nothing. And guess what? It will always match!

Instead try to use one |

/("gct")|("gcc")|("gca")|("gcg")/

Or even better:

"gc[tcag]"

Edit:

Wow didn't notice the boolean :) +1 to @Tim

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top