I have a list of strings like this:
test1 = {
"psi-mi:dvl1_mouse(display_long)|uniprotkb:Dvl1(gene name)|psi-mi:Dvl(display_short)|uniprotkb:Dvl(gene name synonym)|uniprotkb:DSH homolog 1(gene name synonym)",
"psi-mi:nxn_mouse(display_long)|uniprotkb:Nxn(gene name)|psi-mi:Nxn(display_short)|uniprotkb:Gn25(gene name synonym)|uniprotkb:Protein Red-1(gene name synonym)",
"psi-mi:lrp8_mouse(display_long)|uniprotkb:Apolipoprotein Ereceptor 2(gene name synonym)|uniprotkb:Lrp8(gene name)|psi-mi:Lrp8(display_short)|uniprotkb:Apoer2(gene name synonym)",
"psi-mi:reln_mouse(display_long)|uniprotkb:Reln(gene name)|psi-mi:Reln(display_short)|uniprotkb:Rl(gene name synonym)|uniprotkb:Reeler protein(gene name synonym)"}
and I want to get the gene name, which is between the "uniprotkb:"
and "(gene name)|"
. So I'm using StringCases
and Shortest
:
Map[StringCases[#, Shortest["|uniprotkb:" ~~ aa__ ~~ "(gene name)"] -> aa] &, test1]
and the result is
{{"Dvl1"}, {"Nxn"}, {"Apolipoprotein E receptor 2(gene name synonym)|uniprotkb:Lrp8"}, {"Reln"}}
where the third element is not correct, because I just want to get "Lrp8"
. Can somebody tell me why this happens, and what should I do? Any suggestions will be appreciated. Thank you very much.
StringCases[test1, "|uniprotkb:" ~~ a : Except["|"] .. ~~ "(gene name)" :> a]
$\endgroup$