Repository: mwang87/MassQueryLanguage (language: python)

Issue:
[WIP] Adjusting tests for Formulas



Discussion / hints:

Fix patch:
diff --git a/msql.ebnf b/msql.ebnf
index 3d82c95..8626729 100644
--- a/msql.ebnf
+++ b/msql.ebnf
@@ -42,7 +42,11 @@ equal: "="
 lessthan: "<"
 greaterthan: ">"
 positivepolarity: "POSITIVE"
+    | "positive"
+    | "Positive"
 negativepolarity: "NEGATIVE"
+    | "negative"
+    | "negative"
 
 conditionfields: ms2productcondition
     | ms2precursorcondition
@@ -89,13 +93,15 @@ function: functionscannum
     | functionscanmz
     | functionscaninfo
 
-functionscannum: "SCANNUM"
-functionscansum: "SCANSUM" 
-functionscanrangesum: "SCANRANGESUM"
-functionscanmz: "SCANMZ"
-functionscaninfo: "SCANINFO"
+functionscannum: "scannum"
+functionscansum: "scansum" 
+functionscanrangesum: "scanrangesum"
+functionscanmz: "scanmz"
+functionscaninfo: "scaninfo"
 
 booleanconjunction: "AND"
+    | "and"
+    | "And"
 
 param: "TOLERANCE"
 floating: /[-+]?([0-9]*\.[0-9]+|[0-9]+)/
@@ -111,17 +117,17 @@ term: factor
     | term multiply factor
     | term divide factor
 factor: floating
-    | "FORMULA(" moleculeformula ")"
-    | "AMINOACIDDELTA(" aminoacids ")"
+    | "formula(" moleculeformula ")"
+    | "aminoaciddelta(" aminoacids ")"
     | peptidefunction
     | "(" numericalexpression ")"
-peptidefunction: "PEPTIDE(" peptide "," "CHARGE=" peptidecharge "," "ION=" peptideion ")"
+peptidefunction: "peptide(" peptide "," "charge=" peptidecharge "," "ion=" peptideion ")"
 multiply: "*"
 divide: "/"
 plus: "+"
 minus: "-"
 
-moleculeformula: /[A-Z][A-Z1-9]*/
+moleculeformula: /[A-Z][A-Za-z1-9]*/
 aminoacids: /[A-Z][A-Z]*/
 peptide: /[A-Z][A-Z]*/
 peptidecharge: /[1-9]/
diff --git a/msql_parser.py b/msql_parser.py
index dfa79c2..483ef7c 100644
--- a/msql_parser.py
+++ b/msql_parser.py
@@ -5,7 +5,6 @@
 from py_expression_eval import Parser
 math_parser = Parser()
 
-from molmass import Formula
 from pyteomics import mass
 
 
@@ -310,8 +309,8 @@ def floating(self, n):
 
 
 def parse_msql(input_query, path_to_grammar="msql.ebnf"):
-   # Force capitalization on the input_query
-   input_query = input_query.upper()
+   # Force capitalization on the input_query, turning this off due to needing lower case in formulas
+   #input_query = input_query.upper()
 
    # Lets try to strip off any comments
    query_splits = input_query.split("\n")


Test patch:
diff --git a/test_parse.py b/test_parse.py
index 7ebb7b6..5e8e48c 100644
--- a/test_parse.py
+++ b/test_parse.py
@@ -41,6 +41,11 @@ def test_formula_expression_parse():
     print(json.dumps(parsed_output, indent=4))
     assert(parsed_output["conditions"][0]["value"][0] > 28)
 
+def test_formula2_expression_parse():
+    query = "QUERY scaninfo(MS2DATA) WHERE MS2PROD=formula(Fe)"
+    parsed_output = msql_parser.parse_msql(query)
+    print(json.dumps(parsed_output, indent=4))
+    assert(parsed_output["conditions"][0]["value"][0] > 28)
 
 def test_aminoacids_expression_parse():
     query = "QUERY scaninfo(MS2DATA) WHERE MS2PROD=aminoaciddelta(G)"
@@ -64,7 +69,8 @@ def main():
     #test_number_expression_parse()
     #test_formula_expression_parse()
     #test_aminoacids_expression_parse()
-    test_peptide_expression_parse()
+    #test_peptide_expression_parse()
+    test_formula2_expression_parse()
 
 if __name__ == "__main__":
     main()
\ No newline at end of file