Skip to content

Commit f14bae3

Browse files
authored
motif search fixes (#177)
1 parent 42afee5 commit f14bae3

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/components/motifsearch/motifsearchresultset.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export const MotifSearchResultSet: React.FC<{
154154
<MotifResult
155155
key={i}
156156
alignment={alignment}
157-
query={rpwm}
157+
query={pwm}
158158
/>
159159
),
160160
info: (

src/components/motifsearch/motifutil.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,23 @@ const PCMAP: { [letter: string]: number[] } = {
4343
};
4444

4545
export const regexToPWM = (regex: any) => {
46+
//brackets being seen as 5%B and 5%D, have to decode first
47+
const decodedpwm = decodeURIComponent(regex);
4648
const pwm = [];
47-
const lregex = regex.toLowerCase();
49+
const lregex = decodedpwm.toLowerCase();
4850
let inBracket = false,
4951
cbracket = [0.0, 0.0, 0.0, 0.0],
5052
ccount = 0.0;
5153
for (let i = 0; i < lregex.length; ++i) {
54+
console.log(cbracket)
5255
if (inBracket) {
5356
if (lregex[i] === "]") {
5457
inBracket = false;
5558
for (let j = 0; j < cbracket.length; ++j) cbracket[j] /= ccount;
5659
pwm.push(cbracket);
5760
cbracket = [0.0, 0.0, 0.0, 0.0];
5861
ccount = 0.0;
59-
} else if (ACMAP[lregex[i]] && cbracket[ACMAP[lregex[i]]] === 0.0) {
62+
} else if ((ACMAP[lregex[i]] || lregex[i] === "a") && cbracket[ACMAP[lregex[i]]] === 0.0) {
6063
ccount += 1.0;
6164
cbracket[ACMAP[lregex[i]]] = 1.0;
6265
}

src/components/motifsearchbar.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@ const MotifSearchbar: React.FC<MotifSearchBarProps> = ({dark}) => {
2828
const regex = /^[acgtwsmkrybdhvn\[\]]*$/i; // Match allowed letters and brackets
2929
const bracketBalanced = (input.match(/\[/g)?.length || 0) === (input.match(/\]/g)?.length || 0);
3030

31-
if (regex.test(input) && bracketBalanced) {
31+
// Find all content inside brackets
32+
const bracketMatches = input.match(/\[([^\[\]]+)\]/g);
33+
34+
const onlyACGTInside = bracketMatches
35+
? bracketMatches.every(group =>
36+
/^[acgt]+$/i.test(group.slice(1, -1))
37+
)
38+
: true;
39+
40+
if (regex.test(input) && bracketBalanced && onlyACGTInside) {
3241
setValidSearch(true);
3342
} else {
3443
setValidSearch(false);

0 commit comments

Comments
 (0)