<% meth="intersect_columns" %>
<div class="lvl1">

        <div class="alert alert-warning" role="alert">
        <p> Be careful when using this binary, since intersect_columns indexes the ID columns (that is, it retrieves the unique values) after merging the tables — which would cause you to lose records if you repeat the same values in that column. For similar functionality (i.e., merging two tables based on a column that acts as a key) but without losing records, you can use table linker.  <a href='#link_from'>table_linker</a>.</p>
    </div>

    <p> A versatile script to merge two tables. </p>

    <h3> Basic example </h3>
        <p> The most basic case will be retrieving common entried from two columns of two different tables. In this case (and all the following ones) the mechanism is simple: we'll have the -a and -b flags to specify the two input tables, and the -A and -B flags to indicate the columns from each respective table. We'll use the -s flag to specify the separator (by default: tab). The default mode will be obtaining the IDs that are present in both tables (<a href="https://www.w3schools.com/Sql/sql_join_inner.asp">inner join</a>), which is the default mode of the --keep flag. However, we'll also take a look at some different use cases.
        <p> Now we'll see an example with two tables, both of them containing a column with MONDO disease IDs, to find the common entries between them. </p>
        <%
            table_a = 'disease_cluster'
            table_b = 'disease_gene'
            table_b_text = 'Tabla B'
            args = f"-a tables/{table_a} -b tables/{table_b} -A 1 -B 1 -s '\t'"
        %>
		${show_n_exec(table_a, args, "cmdtabs_merge", supp_tables=[[table_b_text, table_b]])}


    <h3> Retrieving the rest of the columns for the common entries found </h3>
        <p> If we don't only want to get the common entries from both tables in that column, but algo get the rest of the columns from both tables, we can use the --full flag </p>
        <%
            args = f"-a tables/{table_a} -b tables/{table_b} -A 1 -B 1 -s '\t' --keep c --full"
        %>
		${show_n_exec(table_a, args, "cmdtabs_merge", supp_tables=[[table_b_text, table_b]])}

    <h3> Retrieving specific entries from a table </h3>
        <p> We've just seen an example of <a href="https://www.w3schools.com/Sql/sql_join_inner.asp">inner join</a>, which is the default mode. With the <a href="#link_from">table_linker</a> binary, we can also use the <a href="https://www.w3schools.com/Sql/sql_join_left.asp">left join</a> and <a href="https://www.w3schools.com/Sql/sql_join_right.asp">right join</a> cases. </p>

        <p> However, we can keep specific entries from a table, whether it is A or B, using the --keep flag with intersect_columns. For example, if we want to keep specific entries from table A, we can use --keep a. If we also want to keep the rest of the columns from table A for the specific entries, we can also use the --full flag. In the next example, we'll show how to return the specific entries from table A without returning the rest of the columns (we could do it by adding the --full flag). 

        <%
            args = f"-a tables/{table_a} -b tables/{table_b} -A 1 -B 1 --keep a"
        %>
		${show_n_exec(table_a, args, "cmdtabs_merge", supp_tables=[[table_b_text, table_b]])}

        <p> In the same way, if we want to keep specific entried from table B, we can use the --keep b flag. Finally, if we want the specific entries from tables A and B, we can use the --keep ab flag (in this case, it would be the complementary of --keep c, where we would get common entries to both). We'll show this case, returning the rest of the columns from both tables for those entries. </p>

        <%
            args = f"-a tables/{table_a} -b tables/{table_b} -A 1 -B 1 --keep ab --full"
        %>
		${show_n_exec(table_a, args, "cmdtabs_merge", supp_tables=[[table_b_text, table_b]])}

</div>