Tag Info

New answers tagged

1

MMA, V9: StringCases[test1, __ ~~ "uniprotkb:" ~~ x__ ~~ "(gene name)|" :> x] (*{{"Dvl1"}, {"Nxn"}, {"Lrp8"}, {"Reln"}}*)


1

If you are strictly looking for the shortest string between "|uniprotkb:" and "(gene name)" in each record, this is a way : StringCases[test1, "|uniprotkb:" ~~ x__ ~~ "(gene name)" :> x, Overlaps -> True] // (First@SortBy[#, StringLength] &) /@ # & {Dvl1,Nxn,Lrp8,Reln}


9

The behaviour we see here is due to the semantics of the regular expression pattern-matching process. Notionally, the string is scanned from left to right. At each character position, an attempt is made to match the string by looking ahead from that position. If there is no match, scanning moves onto the next character. If there is a match, then (by ...


1

The code provided in the Question seems to be selecting the first instance rather than the Shortest, as can be seen by moving |uniprotkb:Lrp8(gene name) earlier in test1[[3]]. However, the following seems to work well. StringCases[test1, "|uniprotkb:" ~~ aa__ ~~ "(gene name)" /; (StringLength[aa] <= 8) :> aa] (* {{"Dvl1"}, {"Nxn"}, {"Lrp8"}, ...


3

StringCases[test1,"|uniprotkb:" ~~ aa : (WordCharacter ..) ~~ "(gene name)" -> aa] (* {{"Dvl1"}, {"Nxn"}, {"Lrp8"}, {"Reln"}} *)


3

I may have misunderstood the requirement but this seems to work for the example at least: problem = "a { b { c d } e } aa { bb cc }"; Map[Flatten, StringSplit[problem] //. {head___, x_, "{", Shortest[y__], "}", tail___} :> {head, Sequence @@ Thread[{x, {y}}], tail}] (* {{"a", "b", "c"}, {"a", "b", "d"}, {"a", "e"}, {"aa", "bb"}, {"aa", "cc"}} *)


1

Obtaining the box form from FullForm[ToBoxes["t1"]] (that's t subscript 1) - the box form can be used in a function like so:- make[x_, n_] := ToExpression[ StringJoin["\"\\!\\(\\*SubscriptBox[\\(", ToString[x], "\\), \\(", ToString[n], "\\)]\\)\""]] make[t, 1] make[t, 1] == "t1" (* again, t subscript 1 *) True To convert a subscripted ...


4

This may be what you want. Be warned that it will include non-printable (control) characters. obfuscate[n_Integer] := FromCharacterCode @ IntegerDigits[n, 256] obfuscate[26728] "hh" Compared to your result: ConvertNumber[469785602403] obfuscate[469785602403] {"m", "a", "g", "i", "c"} "magic"


0

I found the solution MakeList[0] = {}; MakeList[num_Integer] := Append[MakeList[Quotient[num, 256]], Mod[num, 256]] ConvertNumber[num_Integer] := FromCharacterCode /@ MakeList[num] then StringJoin[ConvertNumber[310939241583]]


1

q = Import["Teste_dataMining.txt"]; identifiersPositions = StringPosition[q,"Identifiers (" ~~ CharacterRange["0", "9"] .. ~~ "):"]; notes = StringPosition[q,"Notes (" ~~ CharacterRange["0", "9"] .. ~~ ") :"]; identifiers = StringTake[q, Transpose[{identifiersPositions[[All, 2]] + 1, notes[[All, 1]] - 1}]]; StringSplit[identifiers, Whitespace ~~ ...


7

Your code StringMatchQ["ы", LetterCharacter] returns False, because only the following characters are treated as letters: StringJoin[Select[Characters[FromCharacterCode[Range[2^16 - 1]]], LetterQ]] and LetterCharacter only matches the characters for which LetterQ gives True. You can include Cyrillic symbols using: StringMatchQ["ы", ...


0

O.K. I give it a try.... I have saved your data in a file "stars.txt" on my computer. Now I do the following (... yes... a brute force attack...) ;-) Here a step by step approach... in = Import["stars.txt", "Words"]; (* Import the textfile* ) tempi = StringPosition[in, "Identifiers"] ; (*Position of "Identifieres" *) pi = Position[(Length /@ tempi), 1] // ...


0

One approach is to import the data and then parse it using Mathematica's string commands. To get you started, here is the import command and a search for the locations where the word "Object" appears: q = Import["file.txt"]; StringPosition[q, "Object"] You can replace "Object" with whatever word you want (like "Coordinates") and find where in the input ...



Top 50 recent answers are included