Skip to content

Commit

Permalink
feat: allow upper and lowercase for queries
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKellerer committed Apr 27, 2023
1 parent a5bf1ea commit b4ce361
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,60 @@ expr:
;

single:
nucleotide_mutation
nucleotide_mutation_query
| pangolineage_query
| n_of_query
| nucleotide_insertion
| aa_mutation
| aa_insertion
| nucleotide_insertion_query
| aa_mutation_query
| aa_insertion_query
| nextclade_pangolineage_query
| nextstrain_clade_lineage_query
| gisaid_clade_lineage_query
;

nucleotide_mutation : nucleotide_symbol? position ambigous_nucleotide_symbol?;
nucleotide_mutation_query : nucleotide_mutation_query_first_symbol? position nucleotide_mutation_query_second_symbol?;
nucleotide_mutation_query_first_symbol: nucleotide_symbol;
nucleotide_mutation_query_second_symbol: possible_ambigous_nucleotide_symbol;
position: NUMBER+;
nucleotide_symbol: A | C | G | T;
ambigous_nucleotide_symbol: nucleotide_symbol | M | R | W | S | Y | K | V | H | D | B | N | MINUS | DOT;
ambigous_nucleotide_symbol: M | R | W | S | Y | K | V | H | D | B | N | MINUS | DOT;
possible_ambigous_nucleotide_symbol: nucleotide_symbol | ambigous_nucleotide_symbol;


pangolineage_query: pangolineage pangolineage_include_sublineages?;
pangolineage: pangolineage_character pangolineage_character? pangolineage_character? pangolineage_number_component*;
pangolineage_character: A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z;
pangolineage_number_component: '.' NUMBER NUMBER? NUMBER?;
pangolineage_include_sublineages: DOT? ASTERISK;

n_of_query: '[' n_of_match_exactly? n_of_number_of_matchers '-of:' n_of_exprs ']';
n_of_match_exactly: 'EXACTLY-';
n_of_query: '[' n_of_match_exactly? n_of_number_of_matchers no_of_of_keyword n_of_exprs ']';
no_of_of_keyword: '-of:' | '-OF:';
n_of_match_exactly: 'EXACTLY-' | 'exactly-';
n_of_number_of_matchers: NUMBER+;
n_of_exprs: expr (',' expr)*;

nucleotide_insertion: 'ins_' position ':' (ambigous_nucleotide_symbol | '?')+;
nucleotide_insertion_query: insertion_keyword position ':' (possible_ambigous_nucleotide_symbol | '?')+;
insertion_keyword: 'ins_' | 'INS_';

aa_mutation: gene ':' aa_symbol? position ambigous_aa_symbol?;
aa_mutation_query: gene ':' aa_symbol? position possible_ambigous_aa_symbol?;
aa_symbol: A | R | N | D | C | E | Q | G | H | I | L | K | M | F | P | S | T | W | Y | V | ASTERISK;
ambigous_aa_symbol: aa_symbol | X | MINUS | DOT;
ambigous_aa_symbol: X | MINUS | DOT;
possible_ambigous_aa_symbol: aa_symbol | ambigous_aa_symbol;
gene: covid_gene;
covid_gene : E | M | N | S | ORF;

aa_insertion: 'ins_' gene ':' (ambigous_aa_symbol | '?')+;
aa_insertion_query: insertion_keyword gene ':' position ':' (possible_ambigous_aa_symbol | '?')+;

nextclade_pangolineage_query: nextclade_pango_lineage_prefix pangolineage_query;
nextclade_pango_lineage_prefix: 'nextcladePangoLineage:';
nextclade_pango_lineage_prefix: 'nextcladePangoLineage:' | 'NEXTCLADEPANGOLINEAGE:';

nextstrain_clade_lineage_query: nextstrain_clade_prefix nextstrain_clade_query;
nextstrain_clade_prefix: 'nextstrainClade:';
nextstrain_clade_prefix: 'nextstrainClade:'| 'NEXTSTRAINCLADE:';
nextstrain_clade_query: NUMBER NUMBER nextstrain_clade_character | 'RECOMBINANT';
nextstrain_clade_character: A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z;

gisaid_clade_lineage_query: gisaid_clade_prefix gisaid_clade_query;
gisaid_clade_prefix: 'gisaid:';
gisaid_clade_prefix: ('gisaid:'| 'GISAID:');
gisaid_clade_query: gisaid_clade_character gisaid_clade_character?;
gisaid_clade_character: A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package org.genspectrum.lapis.model

import VariantQueryBaseListener
import VariantQueryParser.Aa_insertionContext
import VariantQueryParser.Aa_mutationContext
import VariantQueryParser.Aa_insertion_queryContext
import VariantQueryParser.Aa_mutation_queryContext
import VariantQueryParser.AndContext
import VariantQueryParser.Gisaid_clade_lineage_queryContext
import VariantQueryParser.MaybeContext
import VariantQueryParser.N_of_queryContext
import VariantQueryParser.Nextclade_pangolineage_queryContext
import VariantQueryParser.Nextstrain_clade_queryContext
import VariantQueryParser.NotContext
import VariantQueryParser.Nucleotide_insertionContext
import VariantQueryParser.Nucleotide_mutationContext
import VariantQueryParser.Nucleotide_insertion_queryContext
import VariantQueryParser.Nucleotide_mutation_queryContext
import VariantQueryParser.OrContext
import VariantQueryParser.Pangolineage_queryContext
import org.antlr.v4.runtime.tree.ParseTreeListener
Expand All @@ -31,12 +31,12 @@ class VariantQueryCustomListener : VariantQueryBaseListener(), ParseTreeListener
return expressionStack.first()
}

override fun enterNucleotide_mutation(ctx: Nucleotide_mutationContext?) {
override fun enterNucleotide_mutation_query(ctx: Nucleotide_mutation_queryContext?) {
if (ctx == null) {
return
}
val position = ctx.position().text.toInt()
val secondSymbol = ctx.ambigous_nucleotide_symbol()?.text ?: "-"
val secondSymbol = ctx.nucleotide_mutation_query_second_symbol()?.text ?: "-"

val expr = NucleotideSymbolEquals(position, secondSymbol)
expressionStack.addLast(expr)
Expand Down Expand Up @@ -89,15 +89,15 @@ class VariantQueryCustomListener : VariantQueryBaseListener(), ParseTreeListener
expressionStack.addLast(NOf(n, matchExactly, children.reversed()))
}

override fun enterNucleotide_insertion(ctx: Nucleotide_insertionContext?) {
override fun enterNucleotide_insertion_query(ctx: Nucleotide_insertion_queryContext?) {
throw NotImplementedError("Nucleotide insertions are not supported yet.")
}

override fun enterAa_mutation(ctx: Aa_mutationContext?) {
override fun enterAa_mutation_query(ctx: Aa_mutation_queryContext?) {
throw NotImplementedError("Amino acid mutations are not supported yet.")
}

override fun enterAa_insertion(ctx: Aa_insertionContext?) {
override fun enterAa_insertion_query(ctx: Aa_insertion_queryContext?) {
throw NotImplementedError("Amino acid insertions are not supported yet.")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class VariantQueryFacadeTest {

@Test
fun `given a valid variantQuery with a 'AA insertion' expression the map should throw an error`() {
val variantQuery = "ins_S:N501EPE"
val variantQuery = "ins_S:501:EPE"

val exception = assertThrows<NotImplementedError> { underTest.map(variantQuery) }

Expand Down

0 comments on commit b4ce361

Please sign in to comment.