From 822cd9413ebfa56ce7dbbebbfb08693f08060895 Mon Sep 17 00:00:00 2001 From: sami-chaaban <36083637+sami-chaaban@users.noreply.github.com> Date: Sat, 20 Nov 2021 09:40:13 +0000 Subject: [PATCH] Update v1.38 --- README.md | 2 +- starparser/__init__.py | 2 +- starparser/argparser.py | 2 +- starparser/decisiontree.py | 11 +++++++++-- starparser/particleplay.py | 10 +++++++++- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4a83967..242ffdd 100644 --- a/README.md +++ b/README.md @@ -219,7 +219,7 @@ Column query term(s). E.g. *\_rlnMicrographName*. This is used to look for a spe **```--q```** *```query(ies)```* -Particle query term(s) to look for in the values within the specified column. To enter multiple queries, separate them with a slash (e.g. 20200101/20200203 to request matching either of the two queries). Use ```--e``` if the query(ies) should exactly match the values in the column. +Particle query term(s) to look for in the values within the specified column. To enter multiple queries, separate them with a slash (e.g. 20200101/20200203 to request matching either of the two queries). To escape a slash, precede it with "," (i.e. ,/). Use ```--e``` if the query(ies) should exactly match the values in the column (see below). **```--e```** diff --git a/starparser/__init__.py b/starparser/__init__.py index f74260f..07d137d 100644 --- a/starparser/__init__.py +++ b/starparser/__init__.py @@ -1,4 +1,4 @@ import os -__version__ = '1.37' +__version__ = '1.38' _ROOT = os.path.abspath(os.path.dirname(__file__)) \ No newline at end of file diff --git a/starparser/argparser.py b/starparser/argparser.py index ab2238c..4fa4174 100644 --- a/starparser/argparser.py +++ b/starparser/argparser.py @@ -200,7 +200,7 @@ def argparse(): query_opts.add_option("--q", action="store", dest="parser_query", type="string", default="", metavar='query(ies)', - help="Particle query term(s) to look for in the values within the specified column. To enter multiple queries, separate them with a slash: 20200101/20200203. Use --e if the query should exactly match the value.") + help="Particle query term(s) to look for in the values within the specified column. To enter multiple queries, separate them with a slash: 20200101/20200203. To escape a slash, use a \",\". Use --e if the query should exactly match the value.") query_opts.add_option("--e", action="store_true", dest="parser_exact", default=False, metavar="match-exactly", diff --git a/starparser/decisiontree.py b/starparser/decisiontree.py index 81b0921..defcc10 100644 --- a/starparser/decisiontree.py +++ b/starparser/decisiontree.py @@ -119,8 +119,15 @@ def decide(): totalparticles = len(allparticles.index) #If a query was passed, then turn it into a list. Since queries are split by a slash, .split("/") creates the list for us + #Escape a / with a , preceding it (i.e. ,/). + #!!This needs to be updated in particleplay if change here!! if params["parser_query"] != "": - query = params["parser_query"].split("/") + query = params["parser_query"] + escape = ",/" + query = str.replace(params["parser_query"],escape, ",") + query = query.split("/") + for i,q in enumerate(query): + query[i] = str.replace(q,",", "/") #If no column was passed, the query can't be checked. if params["parser_column"] == "": @@ -933,7 +940,7 @@ def decide(): particles2use = particleplay.checksubset(allparticles, queryexact) """ - --extract_particles + --extract """ if params["parser_extractparticles"]: diff --git a/starparser/particleplay.py b/starparser/particleplay.py index dff713f..bc17ef7 100644 --- a/starparser/particleplay.py +++ b/starparser/particleplay.py @@ -130,8 +130,16 @@ def checksubset(particles, queryexact): params = argparser.argparse() if params["parser_column"] != "" and params["parser_query"] != "": - query = params["parser_query"].split("/") + + query = params["parser_query"] + escape = ",/" + query = str.replace(params["parser_query"],escape, ",") + query = query.split("/") + for i,q in enumerate(query): + query[i] = str.replace(q,",", "/") + columns = params["parser_column"].split("/") + subsetparticles, extractednumber = extractparticles(particles, columns, query, queryexact) print("\n>> Created a subset of " + str(extractednumber) + " particles (out of " + str(len(particles.index)) + ", " + str(round(extractednumber*100/len(particles.index),1)) + "%) that match " + str(query) + " in the columns " + str(columns) + ".")