<% meth="column_filter" %>
## ${f'<div class={"divImpar" if sect % 2 == 1 else "divPar"}>'}
<div class="lvl1">

    <p> We'll use it to filter entries from one or more tables based on one or a few keywords in one or more columns. </p>

    <h3> Basic example </h3>
        <p> This script enables filtering entries from one or more tables. If the wildcard * is used in the file path with the -i flag, multiple tables can be selected, and everything described in this chapter can be applied to those tables (although the examples below demonstrate each case using a single table). Filtering can be performed based on one or more keywords and applied to one or more columns. Despite its complex appearance, the script is highly versatile and comprehensive. Several examples are provided below, with increasing complexity, to help you better understand how to use it. </p>

        <p> The basic arguments that are always required are: the input table (-i flag); the columns to be returned (--extract_cols); the column containing the keywords (--ext_col_match); the keyword(s) to search for (--ext_keywords); and the match mode (--ext_match_mode) , which specifies whether the keyword should be included in the column as a partial match (option "i") or as an exact match (option "c"). Finally, the --ext_search_mode option is used when matching across multiple columns. It allows you to specify whether the match must be satisfied in all columns (option "c") or only in some of them (option "s"). </p>

        <p> The most essential part is understanding how the keyword search string is built. The pattern is as follows: <code>key1_col1&key2_col1%key1_col2&key2_col2</code> where each keyword is separated by a "&" (when you want a keyword or another in a specific column) and each column by a "%". </p>

        <p> We'll start with a basic example in which we'll keep the entries that contain the keyword <code>MONDO:0017999</code> (--ext_keywords) in column 1 (--ext_col_match) from the input table <code>long_disease_cluster</code> (-i flag). Moreover, we want the match to be complete (--ext_match_mode c) and we want to get columns 1 and 2 from the result (--extract_cols) </p>
        <%
            table_name = 'long_disease_cluster'
            args= f"-i tables/{table_name} --extract_cols 1,2 --ext_col_match 1 --ext_keywords MONDO:0017999 --ext_search_mode c --ext_match_mode c"
        %>
        ${show_n_exec(table_name, args, "cmdtabs")}

    <h3> Complete match in ALL specified columns (two keys, one in each column) </h3>
        <p> As we observed, the previous example returns a few MONDO terms that meet the condition of a complete match in column 1. We'll extend the previous case to only get the MONDO term that has cluster "53_ref" in the second column (--ext_col_match) </p>

        <%
            args= f"-i tables/{table_name} --extract_cols 1,2 --ext_col_match 1,2 --ext_keywords MONDO:0017999%53_ref --ext_search_mode c --ext_match_mode c"
        %>
        ${show_n_exec(table_name, args, "cmdtabs", skip_input=True)}

    <h3> Searching two (or more entries) in the same column (complete match) </h3>
    <p> We'll get the rows that contain either "MONDO:0008995" or "MONDO:0013969". </p>

        <%
            args= f"-i tables/{table_name} --extract_cols 1,2 --ext_col_match 1 --ext_keywords MONDO:0008995&MONDO:0013969 --ext_search_mode c --ext_match_mode c"
        %>
        ${show_n_exec(table_name, args, "cmdtabs", skip_input=True)}

    <h3> Partial match in the second column </h3>
        <p> We'll get the rows that contain the substring "ref" in the second column (changing the --ext_match_mode flag to i (include)) </p>

        <%
            args= f"-i tables/{table_name} --extract_cols 1,2 --ext_col_match 2 --ext_keywords ref --ext_search_mode c --ext_match_mode i"
        %>
        ${show_n_exec(table_name, args, "cmdtabs", skip_input=True)}

    <h3> Reverse partial match in the second column </h3>
       <p> If what we want is not obtaining the entries that match the pattern, but those that do not, we can use the --ext_reverse flag.
       This situation is valid for both complete and patial matches. In this case, we will use the same example as before adding the reverse condition. This way, instead of obtaining entries that contain "ref", we will get those that don't have it ("rand").  </p>
        <%
            args= f"-i tables/{table_name} --extract_cols 1,2 --ext_col_match 2 --ext_keywords ref --ext_search_mode c --ext_match_mode i --ext_reverse"
        %>
        ${show_n_exec(table_name, args, "cmdtabs", skip_input=True)}

    <h3> Partial match in ALL specified columns (two columns) </h3> 
        <p> In the previous case where we filtered by MONDO:0017999 in the first column, we found 3 clusters: 36_rand, 53_ref and 53_rand.
        In this case, to only get the different subsets, we can use the partial match. For example, to only get with MONDO:0017999 from cluster 53. </p>
        <%
            args= f"-i tables/{table_name} --extract_cols 1,2 --ext_col_match 1,2 --ext_keywords MONDO:0017999%53 --ext_search_mode c --ext_match_mode i"
        %>
        ${show_n_exec(table_name, args, "cmdtabs", skip_input=True)}

        <p> And to only get MONDO:0017999 from random clusters </p> 
        <%
            args= f"-i tables/{table_name} --extract_cols 1,2 --ext_col_match 1,2 --ext_keywords MONDO:0017999%rand --ext_search_mode c --ext_match_mode i"
        %>
        ${show_n_exec(table_name, args, "cmdtabs", skip_input=True)}
    

    <h3> Complete match in SOME of the specified columns (two columns) </h3>
        <p> So far, we've seen how to make matches that happen in all columns. If we want to search for keywords in more than one column but we want the pattern to only be found in SOME of the columns, we can change the --ext_search_mode flag to "s" (some). </p>

        <p> For example, if we want to keet the entries that contain MONDO:0008995 or MONDO:0013969 in the first column or 22_rand or 66_ref in the second column, we can do as follows: </p>

        <%
            args= f"-i tables/{table_name} --extract_cols 1,2 --ext_col_match 1,2 --ext_keywords MONDO:0008995&MONDO:0013969%22_rand&66_ref --ext_search_mode s --ext_match_mode c"
        %>
        ${show_n_exec(table_name, args, "cmdtabs", skip_input=True)}
</div>