Ciao,
Sto cercando di trovare una formula che conterà il numero più alto di volte in cui una lettera viene ripetuta consecuteivley in una sequenza. Ho allegato un esempio in cui sto cercando di scrivere una formula per la colonna poly Ts, e genererà consecutivamente il conteggio di Ts in una sequenza.

Grazie,
Pratico
Nello spirito di "altre soluzioni", ecco un'altra forza bruta:
NamesDefaultToHere(1);
// Given a string and a single character, finds the longest sequence of that character
// and returns the length and starting position of that sequence. If the sequence
// occurs more than once, only the first is identified
findLongestRepeatedCharacter =
Function({str, char}, {Default Local},
n = Length(str);
count = 0;
currentCount = 1;
// Traverse the string except for the last character
for (i = 1, i <= n-1, i++,
thisChar = Substr(str, i, 1);
nextChar = Substr(str, i+1, 1);
// If the current character and the next are both 'char' ...
if((thisChar == char & nextChar == char),
// ... increment 'currentCount'
currentCount++,
// ... else if they're not ...
if(currentCount > count,
// ... record 'currentCount' if it's bigger than we've seen so far
count = currentCount;
);
// ... and reset 'currentCount'
currentCount = 1;
);
);
// Build the sequence we've found
seq = Repeat(char, count);
// Find where it occurs
pos = Munger(str, 1, seq);
// Return the results
if (pos == 0,
EvalList({0, pos}),
EvalList({count, pos})
);
);
// Try it out
str = "(N1:25252525)AACCAA(N1)GACGTTAACAGTTCTTTG";
Print(findLongestRepeatedCharacter(str, "T"));
Print(findLongestRepeatedCharacter(str, "A"));
Print(findLongestRepeatedCharacter(str, "X"));La formula della tabella che utilizza ShortestEditScript() ha utilizzato s2 in una parte della formula che avrebbe dovuto essere Sequenza. In allegato la tabella con la funzione corretta.
Ecco un semplice approccio di forza bruta; non sono sicuro delle prestazioni relative a @gzmorgan0 i metodi di.
s2 = "(N1:25252525)AACCAA(N1)GACGTTAACAGTTCTTTG";
len = length(s2);
tstring = repeat("T", len);
maxlen = 0;
for (i = len, i >= 1, i--,
if (contains(s2, tstring),
maxlen = i;
break();
,
tstring = substr(tstring, 2);
);
);
show(maxlen);Un esperto di espressioni regolari potrebbe avere un buon schema per scansionare e trovare tutte le corrispondenze, ma questo va oltre le mie capacità REGEX.
Ho fornito due soluzioni che possono essere eseguite utilizzando le formule di colonna. Entrambi potrebbero aver bisogno di qualche spiegazione.
Il primo utilizza funzioni di caratteri nidificati, il secondo utilizza la funzione ShortestEditScript(). A proposito, non hai specificato se stai contando le sequenze T prima di (N1), entrambe usano l'intera stringa. La tabella di esempio è allegata e le spiegazioni sono riportate di seguito

Assumiamo s2 = "(N1:25252525)AACCAA(N1)GACGTTAACAGTTCTTTG";
Funzioni carattere: Words(), Sort List(), Reverse(), list[n], Length()
Length(Reverse(Sort List(words(s2,"ACGN():0123456789")))[1]);
Ecco l'output del registro per le rispettive funzioni
//:*/
words(s2,"ACGN():0123456789")
/*:
{"TT", "TT", "TTT"}
//:*/
Reverse(Sort List(words(s2,"ACGN():0123456789")))
/*:
{"TTT", "TT", "TT"}
//:*/
Reverse(Sort List(words(s2,"ACGN():0123456789")))[1]
/*:
"TTT"
//:*/
Length(Reverse(Sort List(words(s2,"ACGN():0123456789")))[1]);
/*:
3ShortestEditScript() è una funzione interessante. Sceneggiatura 9_Extra_ShortestEditDistance.jsl scritto per JSL Companion, Applicazioni del linguaggio di scripting JMP, seconda edizione documento 4 diversi metodi per l'utilizzo di questa potente e utile funzione.Per questo esempio, sto usando Sequnces() e richiedendo l'output della matrice. Ci vorrebbe troppo spazio per documentarlo completamente, in questo forum, quindi mi limiterò a mostrare i risultati e aggiungere alcuni commenti.
msed = Shortest Edit Script( Strings(s2, Repeat("T",length(s2)),matrix(1)) );
maximum(msed[loc(msed[0,1]==0),4]);Le due stringhe confrontate sono s2 e una stringa di tutte le T create dalla funzione Repeat("T", length(s2) ).
msed = Shortest Edit Script( Strings(s2, Repeat("T",length(s2)),matrix(1)) );
/*:
[-1 1 . 27,
0 28 1 2,
-1 30 . 5,
0 35 3 2,
-1 37 . 1,
0 38 5 3,
-1 41 . 1,
1 . 8 34]
/* The matrix output n x 4 where n = nrow(msed)
Column1: -1 | 1| 0 -1-->remove, 1-->insert, 0-->common
Column2: position in the 1st string .-->missing / not found
Column3: position in the 2nd string .-->missing / not found
Column4: length
*/Quindi ora si tratta di trovare le posizioni nella prima colonna della matrice con 0 (corrispondenze/comune/T) questo può essere fatto con la funzione loc(). Quindi la lunghezza della sequenza corrispondente è nella 4a colonna, quindi trova solo il massimo.Nota msed[0,1] rappresenta la prima colonna della matrice msed.
loc(msed[0,1]==0)<BR />/*:<BR />[2, 4, 6] <BR />//:*/<BR />msed[loc(msed[0,1]==0),4]<BR />/*:<BR />[2, 2, 3]<BR />//:*/<BR /> maximum(msed[loc(msed[0,1]==0),4]);<BR />/*:<BR />3
Sarà interessante vedere altre soluzioni.