Although it will be further explain in each corresponding binary section, there are a series of guidelines that work for the majority of commands.
For the binaries that are given an input table flag (in most cases with the -i flag, but in other cases such as intersect_columns with the -a and -b flags), these tables can be provided in plain text format, but they can also be loaded compressed in gzip format using the --compressed_in flag. For example:
Additionally, for commands that require only a single input table (such as aggregate_column_data, desaggregate_column_data, or transpose_table, but not intersect_columns), a dash - can be used with the input flag to indicate that the table content comes from stdout (for example, as the result of piping from a previous command), and it may also be compressed. For example:
In scripts that produce some type of output (generally using the -o flag), similarly, the --compressed_out flag can be used so that the result is returned compressed in gzip format. Additionally, if no output flag is specified (omitting -o output_file) and the script returns only a single table, the content is sent to stdout instead of being written to a file, so it can be piped into another script. For example:
Both flags may be used at the same time, recieving and returning a compressed table. For example:
We can also use pipes:
Finally, the --transposed flag can be used in all scripts that load and/or write tables. When used, the table will be transposed at load time as well as immediately before being written.
We’ll use this in a table that contains a reference column with repeated values (i.e., an ID) to aggregate values from another column or columns based on that reference. In all instances, we will use the --aggregate flag.
In this case, values from the second column will be aggregated based on the values from the first column. To do that, the -i flag references the input table, the --agg_ref_col_index flag is the column we want to use as reference (base 1) and the --agg_col flag is the column we want to aggregate (base 1). Moreover, with the --agg_sep flag, we can choose the separator we want in our aggregated column.
| as | 1 | 20 |
| as | 2 | 30 |
| zz | 3 | 100 |
| zz | 4 | 110 |
| as | 1,2 |
| zz | 3,4 |
In this case, values from the second and third columns will be aggregated based on the first one.
| as | 1 | 20 |
| as | 2 | 30 |
| zz | 3 | 100 |
| zz | 4 | 110 |
| as | 1,2 | 20,30 |
| zz | 3,4 | 100,110 |
If we have two columns as reference and we don't want to aggregate them but we also don't want to lose them, we can use the --agg_ref_col_index flag to select more than one column as reference (as well as selecting more than one aggregation column).
| A | as | 1 | 20 |
| A | as | 2 | 30 |
| B | zz | 3 | 100 |
| B | zz | 4 | 110 |
| A | as | 1,2 | 20,30 |
| B | zz | 3,4 | 100,110 |
Besides concatenating values in our column(s) of interest (default mode), we can also use different methods of aggregation using the --agg_mode flag, such as calculating the average ("mean"), median ("median"), maximum ("max") and minimum values ("min"), sum ("sum"), standard deviation ("std"), variance ("var"), interquartile range ("IQR"), 25th percentile ("P25"), 75th percentile ("P75") as well as counts ("count").
Let's see and example with the average of values from columns 2 and 3 based on column 1.
| as | 1 | 20 |
| as | 2 | 30 |
| zz | 3 | 100 |
| zz | 4 | 110 |
| as | 1.5 | 25.0 |
| zz | 3.5 | 105.0 |
Useful to obtain a table with the ID in one column and the number of times said ID appears in the table when it was desaggregated in the other column.
| as | 1 | 20 |
| as | 2 | 30 |
| zz | 3 | 100 |
| zz | 4 | 110 |
| as | 2 |
| zz | 2 |
We'll use it to filter entries from one or more tables based on one or a few keywords in one or more columns.
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.
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").
The most essential part is understanding how the keyword search string is built. The pattern is as follows: key1_col1&key2_col1%key1_col2&key2_col2 where each keyword is separated by a "&" (when you want a keyword or another in a specific column) and each column by a "%".
We'll start with a basic example in which we'll keep the entries that contain the keyword MONDO:0017999 (--ext_keywords) in column 1 (--ext_col_match) from the input table long_disease_cluster (-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)
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_rand |
| MONDO:0014823 | 25_ref |
| MONDO:0017999 | 36_rand |
| MONDO:0017999 | 53_ref |
| MONDO:0017999 | 53_rand |
| MONDO:0011142 | 53_rand |
| MONDO:0009833 | 53_ref |
| MONDO:0009594 | 54_rand |
| MONDO:0010193 | 54_ref |
| MONDO:0012176 | 62_rand |
| MONDO:0011142 | 66_ref |
| MONDO:0013969 | 1189_rand |
| MONDO:0017999 | 36_rand |
| MONDO:0017999 | 53_ref |
| MONDO:0017999 | 53_rand |
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)
| MONDO:0017999 | 53_ref |
We'll get the rows that contain either "MONDO:0008995" or "MONDO:0013969".
| MONDO:0008995 | 19_ref |
| MONDO:0013969 | 1189_rand |
We'll get the rows that contain the substring "ref" in the second column (changing the --ext_match_mode flag to i (include))
| MONDO:0008995 | 19_ref |
| MONDO:0014823 | 25_ref |
| MONDO:0017999 | 53_ref |
| MONDO:0009833 | 53_ref |
| MONDO:0010193 | 54_ref |
| MONDO:0011142 | 66_ref |
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").
| MONDO:0007172 | 22_rand |
| MONDO:0017999 | 36_rand |
| MONDO:0017999 | 53_rand |
| MONDO:0011142 | 53_rand |
| MONDO:0009594 | 54_rand |
| MONDO:0012176 | 62_rand |
| MONDO:0013969 | 1189_rand |
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.
| MONDO:0017999 | 53_ref |
| MONDO:0017999 | 53_rand |
And to only get MONDO:0017999 from random clusters
| MONDO:0017999 | 36_rand |
| MONDO:0017999 | 53_rand |
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).
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:
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_rand |
| MONDO:0011142 | 66_ref |
| MONDO:0013969 | 1189_rand |
Changing a table from long to wide format.
When we work with workflows like autoflow's, we sometimes launch parallelized tasks with different job combinations, like: network (ORPHA and MONDO) and clustering type (CPM and HLC) and we write all the different metrics into a common file, such as:
| ORPHA | CPM | N_CLUSTERS | 500 |
| ORPHA | CPM | CLUSTER_SIZE | 10 |
| ORPHA | HLC | N_CLUSTERS | 600 |
| ORPHA | HLC | CLUSTER_SIZE | 12 |
| MONDO | CPM | N_CLUSTERS | 550 |
| MONDO | CPM | CLUSTER_SIZE | 11 |
| MONDO | HLC | N_CLUSTERS | 650 |
| MONDO | HLC | CLUSTER_SIZE | 13 |
In the table above, we can see that the first two columns are factors (network and clustering type), the third one is the measured metric and the last one is its value. This format would be called the "long" format (long and wide format examples). However, in order to be able to use some graphing methods from CanvasXpress or to see the metrics table in a simpler way, we need to transform this table onto a "wide" format. To do so, we'll use the create_metric_table method.
Here, we'll specify the input table in the -i flag, the output table in the -o flag and the names of the columns that will be factors in the output table (separated by commas) in the --sample_attributes flag. You may also redirect corrupted fields to a file with the --corrupted flag.
Imagining we have an input file with columns that represent "network name, clustering type, network type, metric, value", the command would be as follows:
| red1 | HLC | genes | cl_num | 1988 |
| red1 | HLC | genes | cl_size_mean | 10 |
| red2 | CPM | genes | cl_num | 2000 |
| red2 | CPM | genes | cl_size_mean | 15 |
| red3 | HLC | phenotypes | cl_num | 3000 |
| red3 | HLC | phenotypes | cl_size_mean | 20 |
| red4 | CPM | phenotypes | cl_num | 4000 |
| red4 | CPM | phenotypes | cl_size_mean | 25 |
| network | method | type | cl_num | cl_size_mean |
| red1 | HLC | genes | 1988 | 10 |
| red2 | CPM | genes | 2000 | 15 |
| red3 | HLC | phenotypes | 3000 | 20 |
| red4 | CPM | phenotypes | 4000 | 25 |
We can optionally add a -c flag to obtain another table with corrupt values that could not be transformed into a "wide" format due to having a missing value in one(some) factor(s).
We’ll use this in a table that contains a reference column with repeated values (i.e., an ID) to disaggregate values from another column or columns based on that reference. In all instances, we will use the --desaggregate flag.
In this case, values from the third column will be disaggregated, adjusting the remaining columns according to the number of values in each row of the third column. We'll used the -i flag to specify the input table, the --desagg_col flag for the column we want to disaggregate (1 based) and the --desagg_sep flag to indicate the separator used in the aggregated column.
| HGNC:21197 | mRNA | 483_ref,1039_ref,1071_ref |
| HGNC:21143 | mRNA | 211_ref,4705_ref |
| HGNC:21457 | tRNA | 305_ref,304_ref |
| HGNC:21197 | mRNA | 483_ref |
| HGNC:21197 | mRNA | 1039_ref |
| HGNC:21197 | mRNA | 1071_ref |
| HGNC:21143 | mRNA | 211_ref |
| HGNC:21143 | mRNA | 4705_ref |
| HGNC:21457 | tRNA | 305_ref |
| HGNC:21457 | tRNA | 304_ref |
If there is more than one aggregated column, we can specify them with the --desagg_col flag, separating them by commas. It is assumed that all aggregated columns have the same number of elements for each row (i.e. 1 column with pat1,pat2,pat3 and another with male,male,female)
| HGNC:21197 | mRNA | SNP1,SNP3,SNP4 | 483_ref,1039_ref,1071_ref |
| HGNC:21143 | mRNA | SNP5,SNP6 | 211_ref,4705_ref |
| HGNC:21457 | tRNA | SNP12,SNP13 | 305_ref,304_ref |
| HGNC:21197 | mRNA | SNP1 | 483_ref |
| HGNC:21197 | mRNA | SNP3 | 1039_ref |
| HGNC:21197 | mRNA | SNP4 | 1071_ref |
| HGNC:21143 | mRNA | SNP5 | 211_ref |
| HGNC:21143 | mRNA | SNP6 | 4705_ref |
| HGNC:21457 | tRNA | SNP12 | 305_ref |
| HGNC:21457 | tRNA | SNP13 | 304_ref |
Convert table from excel to plain format (CSV, TSV and similar).
This example shows how to convert a table from excel to plain format (CSV, TSV and similar). The two-sheet excel file is as follows:
Let's extract the first three columns from the first sheet of the file special_files/scRNAseq.xlsx and convert it to plain tabular format. We will use the -i flag to specify input file, -c to select columns to extract and -s for the sheet to retrieve data from.
| genes | cell1 | cell2 |
| gene1 | 3 | 0 |
| gene2 | 0 | 4 |
| gene3 | 0 | 0 |
| gene25000 | 0 | 3 |
In this case, we extract the first two and last two columns from the second sheet in the same file
| genes | cell5 | cell7 | cell15000 |
| gene5 | 36 | 3 | 54 |
| gene6 | 0 | 67 | 5 |
| gene8 | 50 | 3 | 9 |
| gene25000 | 6 | 87 | 8 |
If we wish to extract all columns without specifying all of them we can just leave the --excel_cols argument empty, which signals for the extraction of every column.
| genes | cell1 | cell2 | cell3 | cell10000 |
| gene1 | 3 | 0 | 7 | 4 |
| gene2 | 0 | 4 | 5 | 5 |
| gene3 | 0 | 0 | 4 | 0 |
| gene25000 | 0 | 3 | 0 | 0 |
In addition to columns, the user can also choose which rows to extract from the table. By default, every row is extracted, but we can extract a selection.
In this case we are extracting rows 1,3 and columns 1,3,4 from the first sheet
| genes | cell2 | cell3 |
| gene2 | 4 | 5 |
Este binario presenta cierto solapamiento con el el binario "column_filter", si bien el solapamiento no 100% ya que column_filter acepta los keywords mediante una string y este binario acepta un archivo de una columna con los términos a filtrar.
Se utiliza para filtrar las filas que nos interesan de una o más tablas en función a una serie de valores que se pasan
Tenemos nuestra tabla con la primera columna teniendo el identificador de una red (la que nos interesa para poder filtrar), y las otras columnas siendo factores y metrica-valor. Tenemos otro archivo en el que tenemos los identificadores de las redes que queremos filtrar (red1 y red3).
Pasamos la tabla de interés tabla como input al flag -i y la columna en la que están los valores que filtrarán las filas con el flag -c. El archivo de una columna con los IDs de redes que queremos filtrar se pasan al flag -t. Pasamos el path a la carpeta (si, a una carpeta, ya que el flag de input -f puede aceptar más de una tabla, separada por comas, para ser filtrada) en el que queremos que se escriba la/s tabla/s filtrada/s con el flag -o y podemos añadir un prefijo para el nombre de la tabla de salida si nos interesa (en este caso usamos "filtered_" en este caso) con el flag --prefix
| red1 | HLC | genes | cl_num | 1988 |
| red1 | HLC | genes | cl_size_mean | 10 |
| red2 | CPM | genes | cl_num | 2000 |
| red2 | CPM | genes | cl_size_mean | 15 |
| red3 | HLC | phenotypes | cl_num | 3000 |
| red3 | HLC | phenotypes | cl_size_mean | 20 |
| red4 | CPM | phenotypes | cl_num | 4000 |
| red4 | CPM | phenotypes | cl_size_mean | 25 |
| red1 |
| red3 |
| red1 | HLC | genes | cl_num | 1988 |
| red1 | HLC | genes | cl_size_mean | 10 |
| red3 | HLC | phenotypes | cl_num | 3000 |
| red3 | HLC | phenotypes | cl_size_mean | 20 |
Si en vez de querer quedarnos con todas las filas que tengan los términos de la tabla que pasamos con el flag -t, queremos quedarnos con todas las filas que no tengan esos términos, podemos activar el flag booleano --blacklist.
Repitiendo el mismo ejemplo anterior, pero activando ese flag, tenemos:
| red1 | HLC | genes | cl_num | 1988 |
| red1 | HLC | genes | cl_size_mean | 10 |
| red2 | CPM | genes | cl_num | 2000 |
| red2 | CPM | genes | cl_size_mean | 15 |
| red3 | HLC | phenotypes | cl_num | 3000 |
| red3 | HLC | phenotypes | cl_size_mean | 20 |
| red4 | CPM | phenotypes | cl_num | 4000 |
| red4 | CPM | phenotypes | cl_size_mean | 25 |
| red1 |
| red3 |
| red2 | CPM | genes | cl_num | 2000 |
| red2 | CPM | genes | cl_size_mean | 15 |
| red4 | CPM | phenotypes | cl_num | 4000 |
| red4 | CPM | phenotypes | cl_size_mean | 25 |
Si en vez de querer filtrar los elementos de la tabla por un match exacto, queremos que sea por un match parcial, podemos activar el flag booleano --not_exact_match
En la tabla siguiente, vamos a quedarnos con todos los clústeres de referencia y descartar los random, indicando que los valores que queremos filtrar en nuestra tabla de entrada dada con el flag -i están en la segunda columna (-c 2) y el archivo que pasamos para filtrar con el flag -t solo tiene el valor 'ref', que será usado para hacer un match parcial al haber usado el flag --not_exact_match
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_rand |
| MONDO:0014823 | 25_ref |
| MONDO:0017999 | 53_rand |
| MONDO:0009833 | 53_ref |
| MONDO:0009594 | 54_rand |
| MONDO:0010193 | 54_ref |
| MONDO:0012176 | 62_rand |
| MONDO:0011142 | 66_ref |
| MONDO:0013969 | 1189_rand |
| ref |
| MONDO:0008995 | 19_ref |
| MONDO:0014823 | 25_ref |
| MONDO:0009833 | 53_ref |
| MONDO:0010193 | 54_ref |
| MONDO:0011142 | 66_ref |
Como se ha comentado antes, el flag -f acepta múltiples tablas separadas por comas. Es por ello que el flag -o para el output indica carpeta de salida y no archivo de salida. Además, si vamos a escribir los archivos en la misma carpeta, podemos utilizar el flag --prefix para que no se escriban con el mismo nombre y nos reemplacen las tablas de entrada.
Por lo tanto, podemos filtrar varias tablas a la vez utilizando el mismo archivo de filtrado. Esto es util si tenemos distintos archivos de métricas con los mismos identificadores y queremos filtrar todos ellos por los mismos términos.
Extract a selection of columns from the original table
Input table is provided with flag -i. Columns to extract are selected with flag -c (comma-separated 1-based numeric indices), using a hyphen (-) so select a column range.
In this case, we will extract columns 1, 3, 4 and 5. We will do so by selecting column 1 and the 3-5 interval.
| col-1 | col-2 | col-3 | col-4 | col-5 |
| 1 | 2 | 3 | 4 | 5 |
| 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 |
| col-1 | col-3 | col-4 | col-5 |
| 1 | 3 | 4 | 5 |
| 6 | 8 | 9 | 10 |
| 11 | 13 | 14 | 15 |
If flag -H is active, it means the table has a header. If that is the case we can select columns by specifying their name, again selecting multiple by separating them by commas. (NOTE: even if the table has a header, columns may be selected by numerical index without activating the -H flag, exactly as in the previous example)
In this case, we will select columns col-1, col-3, col-4 and col-5, the same as in the previous example, but this time selecting them by column name. In this case it is also possible to select a range of columns, but in this case by using the "%-%" sequence of characters (as the hyphen may also be a part of the column name, as was chosen for this example)
| col-1 | col-2 | col-3 | col-4 | col-5 |
| 1 | 2 | 3 | 4 | 5 |
| 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 |
| col-1 | col-3 | col-4 | col-5 |
| 1 | 3 | 4 | 5 |
| 6 | 8 | 9 | 10 |
| 11 | 13 | 14 | 15 |
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. table_linker.
A versatile script to merge two tables.
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 (inner join), which is the default mode of the --keep flag. However, we'll also take a look at some different use cases.
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.
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_ref |
| MONDO:0010193 | 54_ref |
| MONDO:0010193 | HGNC:3527 | tRNA |
| MONDO:0008995 | HGNC:16873 | mRNA |
| MONDO:0012866 | HGNC:21197 | mRNA |
| MONDO:0008995 |
| MONDO:0010193 |
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
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_ref |
| MONDO:0010193 | 54_ref |
| MONDO:0010193 | HGNC:3527 | tRNA |
| MONDO:0008995 | HGNC:16873 | mRNA |
| MONDO:0012866 | HGNC:21197 | mRNA |
| MONDO:0008995 | 19_ref | MONDO:0008995 | HGNC:16873 | mRNA |
| MONDO:0010193 | 54_ref | MONDO:0010193 | HGNC:3527 | tRNA |
We've just seen an example of inner join, which is the default mode. With the table_linker binary, we can also use the left join and right join cases.
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).
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_ref |
| MONDO:0010193 | 54_ref |
| MONDO:0010193 | HGNC:3527 | tRNA |
| MONDO:0008995 | HGNC:16873 | mRNA |
| MONDO:0012866 | HGNC:21197 | mRNA |
| MONDO:0007172 |
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.
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_ref |
| MONDO:0010193 | 54_ref |
| MONDO:0010193 | HGNC:3527 | tRNA |
| MONDO:0008995 | HGNC:16873 | mRNA |
| MONDO:0012866 | HGNC:21197 | mRNA |
| MONDO:0007172 | 22_ref | |
| MONDO:0012866 | HGNC:21197 | mRNA |
Although this binary's use is a bit overlapped with "intersect_columns" and "table_linker", the difference is that it can join a indefinite number of tables (taking into account that the column to join all tables must be the first one)
It is used to merge N tables based on their first column when they share the same IDs.
In this script, we'll use the --tables flag to specify all input tables, separated by commas (,). The --columns2add flag will be used to indicate the column indexes (1 based) of each file added to the first one (therefore, we will not specify the first table's columns), separating the columns in each set by commas and each set of columns (pet table) by a semicolon (;). The --fill_character flag will be used to specify which character we want the empty fields to be filled with. Lastly, we'll use the --union flag to also add the rows that do not have a match to the merging table (first table).
In this case, we'll join tables tables/disease_cluster, tables/disease_gene and tables/mondo_to_orpha and we will fill the empty fields with "NA".
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_ref |
| MONDO:0010193 | 54_ref |
| MONDO:0010193 | HGNC:3527 | tRNA |
| MONDO:0008995 | HGNC:16873 | mRNA |
| MONDO:0012866 | HGNC:21197 | mRNA |
| MONDO:0008995 | ORPHA:3472 |
| MONDO:0012866 | ORPHA:171629 |
| MONDO:0008995 | 19_ref | HGNC:16873 | mRNA | ORPHA:3472 |
| MONDO:0007172 | 22_ref | NA | NA | NA |
| MONDO:0010193 | 54_ref | HGNC:3527 | tRNA | NA |
| MONDO:0012866 | NA | HGNC:21197 | mRNA | ORPHA:171629 |
It is used to obtain the number of occurrences of all the terms in a column of a table.
The input table will be specified with the -i flag and the column we want to count (1 based) will be indicated with the --count-cols flag.
Let's see the number of occurrences of the different terms in the second column of the table 'cluster_genes_dis_agg'.
| HGNC:21197 | mRNA | 483_ref,1039_ref,1071_ref |
| HGNC:21143 | mRNA | 211_ref,4705_ref |
| HGNC:21457 | tRNA | 305_ref,304_ref |
| mRNA | 2 |
| tRNA | 1 |
We can use it to sort the rows of the input table by the given column/s
Generally speaking, the logic is the following: --sort_rows_by [0-based column index OR column name],["d" if descending OR "a" if ascending OR custom_sort];[other_column],[mode];...
We have a table with 3 columns, pat (patient), name and score. We want to sort the rows of the table by the score column, in ascending order
We'll use the -i flag to specify the input table, -H if the table have header and --sort_rows_by to give the sorting behaviour we expect (sort ascending by the score column)
| pats | name | score |
| pat1 | paco | 5 |
| pat2 | jose | 3 |
| pat3 | maria | 1 |
| pat4 | abel | 3 |
| pats | name | score |
| pat3 | maria | 1 |
| pat2 | jose | 3 |
| pat4 | abel | 3 |
| pat1 | paco | 5 |
Note that we can also use a numeric column index (0-based) to set the column we want to apply the sorting, even if the table has header (What we can't do is the opposite—try to sort by specifying a column name in a table that doesn't have a header; doing so would cause an error.)
| pats | name | score |
| pat1 | paco | 5 |
| pat2 | jose | 3 |
| pat3 | maria | 1 |
| pat4 | abel | 3 |
| pats | name | score |
| pat3 | maria | 1 |
| pat2 | jose | 3 |
| pat4 | abel | 3 |
| pat1 | paco | 5 |
Using the same table, we want to sort by score descending, but when the score is equal, we then want to sort by the name ascending (A before B and so)
| pats | name | score |
| pat1 | paco | 5 |
| pat2 | jose | 3 |
| pat3 | maria | 1 |
| pat4 | abel | 3 |
| pats | name | score |
| pat1 | paco | 5 |
| pat4 | abel | 3 |
| pat2 | jose | 3 |
| pat3 | maria | 1 |
We can also sort the rows of a table in a completely arbitrary order based on a given column. In that case, we specify the column name or index and a string (or file; see the next section) that indicates the desired sort order. If using a string, the elements are separated by “|”
| pats | name | score |
| pat1 | paco | 5 |
| pat2 | jose | 3 |
| pat3 | maria | 1 |
| pat4 | abel | 3 |
| pats | name | score |
| pat4 | abel | 3 |
| pat1 | paco | 5 |
| pat3 | maria | 1 |
| pat2 | jose | 3 |
We can also specify a filepath to sort the rows by the specific column. In that case it will be a one column file with the desired order.
| pats | name | score |
| pat1 | paco | 5 |
| pat2 | jose | 3 |
| pat3 | maria | 1 |
| pat4 | abel | 3 |
| pat2 |
| pat3 |
| pat1 |
| pat4 |
| pats | name | score |
| pat2 | jose | 3 |
| pat3 | maria | 1 |
| pat1 | paco | 5 |
| pat4 | abel | 3 |
We'll use this when we have a table that contains a column with IDs (i.e., ensemblIDs and associated GO terms) and another table that we want to use as a dictionary to translate certain values for different ones (i.e., a table with ensemblIDs and their corresponding gene symbol).
We have a table with MONDO IDs and the cluster(s) where that MONDO disease has been found. We also have a file that correlates each MONDO ID with its corresponding ORPHA ID. We'll use the latter to translate all MONDO IDs to ORPHA IDs in the first table.
We'll use the -i flag to specify the input table (the first table in our case) and the -I flag for the dictionary (second table). We will then use the -c flag to select the column we want to translate, the --from flag to indicate which column from the dictionary table we want to use as the search key and the --to flag to select the column in the dictionary that contains the terms we want to use for replacing in the first table.
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_ref |
| MONDO:0010193 | 54_ref |
| MONDO:0008995 | ORPHA:3472 |
| MONDO:0012866 | ORPHA:171629 |
| ORPHA:3472 | 19_ref |
| MONDO:0007172 | 22_ref |
| MONDO:0010193 | 54_ref |
As we can observe in the previous example, if an ID term from the input file is not present in the dictionary, that ID remains untranslated. If we want to remove any untranslated entries, we can add the -u flag to the command.
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_ref |
| MONDO:0010193 | 54_ref |
| MONDO:0008995 | ORPHA:3472 |
| MONDO:0012866 | ORPHA:171629 |
| ORPHA:3472 | 19_ref |
This binary is used to get a subset from the input table, starting from row X and taking Y rows from there.
La tabla de entrada se indica con el flag -i. La fila por la que se empieza con el flag -s o --start_line (indice basado en 1) y la cantidad de filas que se extraen desde ese punto con el flag -l o --lines_to_subset. Además, si la tabla original tiene un header y se quiere mantener en la tabla subseteada, se puede utilizar el flag -H o --header
The input table is specified with the -i flag. The row were we'll start subsetting our table and the number of rows we want to extract from that point will be specified with the --offset flag (1 based), separating both numbers by a comma. We can also add the -H or --header flag.
In this case, we'll get 4 rows from the metrics table, starting from row 3 and keeping the header.
| sample | initial_total_sequences | initial_read_max_length | initial_read_min_length | initial_%gc | |
| CTL_1_cell | 11437331.0 | 76.0 | 35.0 | 45.0 | |
| CTL_1_exo | 10668412.0 | 76.0 | 35.0 | 48.0 | |
| CTL_2_cell | 20503996.0 | 76.0 | 35.0 | 44.0 | |
| CTL_2_exo | 9322480.0 | 76.0 | 35.0 | 47.0 | |
| CTL_3_cell | 20342853.0 | 76.0 | 35.0 | 46.0 | |
| CTL_3_exo | 18394272.0 | 76.0 | 35.0 | 48.0 | |
| CTL_4_cell | 15729473.0 | 76.0 | 35.0 | 45.0 | |
| CTL_4_exo | 12505200.0 | 76.0 | 35.0 | 49.0 | |
| CTL_5_cell | 12829784.0 | 76.0 | 35.0 | 45.0 | |
| CTL_5_exo | 9072750.0 | 76.0 | 35.0 | 49.0 | |
| DOX_1_cell | 37629252.0 | 76.0 | 35.0 | 45.0 | |
| DOX_1_exo | 21945299.0 | 76.0 | 35.0 | 46.0 | |
| DOX_2_cell | 17915632.0 | 76.0 | 35.0 | 44.0 | |
| DOX_2_exo | 5919977.0 | 76.0 | 35.0 | 50.0 |
| sample | initial_total_sequences | initial_read_max_length | initial_read_min_length | initial_%gc | |
| CTL_2_cell | 20503996.0 | 76.0 | 35.0 | 44.0 | |
| CTL_2_exo | 9322480.0 | 76.0 | 35.0 | 47.0 | |
| CTL_3_cell | 20342853.0 | 76.0 | 35.0 | 46.0 | |
| CTL_3_exo | 18394272.0 | 76.0 | 35.0 | 48.0 |
If we want to subset the table in different files, each one containing K number of lines, we can use the --sp_chunk_size flag, indicating the number of lines we want per file, keeping in mind that we will also need to add the --split_out flag. The -o flag is used to state the ouput directory where the files will be stored.
In this case, we'll separate the disease clusters table in different files, each one of them containing 4 lines (we'll see that the last one only has 2 due to the input table having 10 entries).
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_rand |
| MONDO:0014823 | 25_ref |
| MONDO:0017999 | 53_rand |
| MONDO:0009833 | 53_ref |
| MONDO:0009594 | 54_rand |
| MONDO:0010193 | 54_ref |
| MONDO:0012176 | 62_rand |
| MONDO:0011142 | 66_ref |
| MONDO:0013969 | 1189_rand |
| MONDO:0009833 | 53_ref |
| MONDO:0009594 | 54_rand |
| MONDO:0010193 | 54_ref |
| MONDO:0012176 | 62_rand |
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_rand |
| MONDO:0014823 | 25_ref |
| MONDO:0017999 | 53_rand |
| MONDO:0011142 | 66_ref |
| MONDO:0013969 | 1189_rand |
Si se quiere partir la tabla en una cantidad fija de N archivos , cada uno de ellos con la misma cantidad de registros, se puede utilizar el flag -n o --number_of_files en vez de los flags -s y -l o --chunk_size. En este caso el flag de output -o también indica la carpeta donde se guardarán los archivos.
If we want to subset the table in a fixed number of N files, each one of them containing the same number of entries, we can use the --sp_file_number flag, indicating the number of files you want. Just like before, we will also have to add the --split_out flag. The -o output flag will also indicated where we will store the files.
In this case, we will separate the disease clusters table in 2 files.
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_rand |
| MONDO:0014823 | 25_ref |
| MONDO:0017999 | 53_rand |
| MONDO:0009833 | 53_ref |
| MONDO:0009594 | 54_rand |
| MONDO:0010193 | 54_ref |
| MONDO:0012176 | 62_rand |
| MONDO:0011142 | 66_ref |
| MONDO:0013969 | 1189_rand |
| MONDO:0009594 | 54_rand |
| MONDO:0010193 | 54_ref |
| MONDO:0012176 | 62_rand |
| MONDO:0011142 | 66_ref |
| MONDO:0013969 | 1189_rand |
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_rand |
| MONDO:0014823 | 25_ref |
| MONDO:0017999 | 53_rand |
| MONDO:0009833 | 53_ref |
Parte del comportamiento de este binario se puede emular usando el binario "intersect_columns" con los flags adecuados, pero no sé si hay algo que no sea redudante entre los dos binarios
Se utiliza para realizar un merge de dos tablas en base a una columna con identificadores compartidos.
Se utiliza como tabla base la que se da con el flag -i, y la que se va a mergear con el flag -l, la co. Esto sería equivalente a un left join. Para obtener un right join, tan solo tendríamos que alternar los flags que damos a cada tabla (hacer un left join pero con la linker como input)
Por defecto, se espera que el identificador en la tabla input esté en la primera columna, y todo el resto de columnas de esta tabla se mantendrán. Con respecto a la tabla linker, podemos indicar la columna que contiene el identificador con el flag --id_linker (por defecto a 0), y las columnas que queremos mantener en el merge, separadas por comas, con el flag --columns2linker (por defecto a 1)
Tambien tenemos el flag -s para indicar que separador queremos para la tabla resultante (por defecto tabulación)
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_ref |
| MONDO:0010193 | 54_ref |
| MONDO:0010193 | HGNC:3527 | tRNA |
| MONDO:0008995 | HGNC:16873 | mRNA |
| MONDO:0012866 | HGNC:21197 | mRNA |
| MONDO:0008995 | 19_ref | HGNC:16873 |
| MONDO:0007172 | 22_ref | |
| MONDO:0010193 | 54_ref | HGNC:3527 |
Utilizamos el flag --columns2linker para indicar que queremos las dos columnas de la tabla linker, no solo la primera. Usamos también el flag --id_linker para indicar qué columna contiene los identificadores para el merge en la tabla linker, aunque en este caso coincida con el valor por defecto
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_ref |
| MONDO:0010193 | 54_ref |
| MONDO:0010193 | HGNC:3527 | tRNA |
| MONDO:0008995 | HGNC:16873 | mRNA |
| MONDO:0012866 | HGNC:21197 | mRNA |
| MONDO:0008995 | 19_ref | HGNC:16873 | mRNA |
| MONDO:0007172 | 22_ref | ||
| MONDO:0010193 | 54_ref | HGNC:3527 | tRNA |
Para mantener solo los registros comunes a ambas tablas podemos usar el flag --drop. Esto sería equivalente a un inner join
| MONDO:0008995 | 19_ref |
| MONDO:0007172 | 22_ref |
| MONDO:0010193 | 54_ref |
| MONDO:0010193 | HGNC:3527 | tRNA |
| MONDO:0008995 | HGNC:16873 | mRNA |
| MONDO:0012866 | HGNC:21197 | mRNA |
| MONDO:0008995 | 19_ref | HGNC:16873 | mRNA |
| MONDO:0010193 | 54_ref | HGNC:3527 | tRNA |
This binary adds one or more tags (i.e. additional factors of a variable and their value) to all rows in a table.
We'll specify the table we want the tags added to with the -i flag and a string with comma separated tags with the --tags flag
| cl_num | 1988 |
| cl_size_min | 1 |
| cl_size_max | 296 |
| cl_size_median | 3.0 |
| cl_size_mean | 4.667505030181086 |
| cl_nodes_mean | 1.0 |
| cl_nodes | 9279 |
| cl_pairs | 147578 |
| network1 | collapsed | translated | cl_num | 1988 |
| network1 | collapsed | translated | cl_size_min | 1 |
| network1 | collapsed | translated | cl_size_max | 296 |
| network1 | collapsed | translated | cl_size_median | 3.0 |
| network1 | collapsed | translated | cl_size_mean | 4.667505030181086 |
| network1 | collapsed | translated | cl_nodes_mean | 1.0 |
| network1 | collapsed | translated | cl_nodes | 9279 |
| network1 | collapsed | translated | cl_pairs | 147578 |
If a file name is specified with the --tags flag instead of a comma separated string, cmdtabs can recognize it a load the file to use it as tags. In this case, the -x flag will be used to specify said file separator.
| cl_num | 1988 |
| cl_size_min | 1 |
| cl_size_max | 296 |
| cl_size_median | 3.0 |
| cl_size_mean | 4.667505030181086 |
| cl_nodes_mean | 1.0 |
| cl_nodes | 9279 |
| cl_pairs | 147578 |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm | cl_num | 1988 |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm | cl_size_min | 1 |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm | cl_size_max | 296 |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm | cl_size_median | 3.0 |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm | cl_size_mean | 4.667505030181086 |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm | cl_nodes_mean | 1.0 |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm | cl_nodes | 9279 |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm | cl_pairs | 147578 |
If we indicate a few files separated by commas to the --tags flag, cmdtabs will read and use each one of them to add the tags.
| cl_num | 1988 |
| cl_size_min | 1 |
| cl_size_max | 296 |
| cl_size_median | 3.0 |
| cl_size_mean | 4.667505030181086 |
| cl_nodes_mean | 1.0 |
| cl_nodes | 9279 |
| cl_pairs | 147578 |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm | MERGED_net_no_raw_cpm | MERGED | no | no | cpm | cl_num | 1988 |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm | MERGED_net_no_raw_cpm | MERGED | no | no | cpm | cl_size_min | 1 |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm | MERGED_net_no_raw_cpm | MERGED | no | no | cpm | cl_size_max | 296 |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm | MERGED_net_no_raw_cpm | MERGED | no | no | cpm | cl_size_median | 3.0 |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm | MERGED_net_no_raw_cpm | MERGED | no | no | cpm | cl_size_mean | 4.667505030181086 |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm | MERGED_net_no_raw_cpm | MERGED | no | no | cpm | cl_nodes_mean | 1.0 |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm | MERGED_net_no_raw_cpm | MERGED | no | no | cpm | cl_nodes | 9279 |
| MERGED_net_no_raw_cpm | MERGED | no | no | cpm | MERGED_net_no_raw_cpm | MERGED | no | no | cpm | cl_pairs | 147578 |
It is used to convert a table in TSV, CSV, etc. format into a table with the required syntax to be added to LaTeX.
We'll specify the table to convert with the -i flag and add the --latex flag for this binary to be used.
| as | 1 | 20 |
| as | 2 | 30 |
| zz | 3 | 100 |
| zz | 4 | 110 |
| \hline |
| as & 1 & 20 \\ \hline |
| as & 2 & 30 \\ \hline |
| zz & 3 & 100 \\ \hline |
| zz & 4 & 110 \\ \hline |
If we want to get a more detailed backbone to fill the remaining fields, we can used the --whole or -w flag.
| as | 1 | 20 |
| as | 2 | 30 |
| zz | 3 | 100 |
| zz | 4 | 110 |
| \begin{table}[!htbp] |
| \centering |
| \caption{} |
| \begin{tabular}{|l|l|l|} |
| \hline |
| as & 1 & 20 \\ \hline |
| as & 2 & 30 \\ \hline |
| zz & 3 & 100 \\ \hline |
| zz & 4 & 110 \\ \hline |
| \end{tabular} |
| \label{table:cluster_genes_dis_desagg_3cols} |
| \end{table} |
Used to transpose a table.
We'll transpose the specified table with the -i flag and add the --transposed flag for this binary to be used.
| as | 1 | 20 |
| as | 2 | 30 |
| zz | 3 | 100 |
| zz | 4 | 110 |
| as | as | zz | zz |
| 1 | 2 | 3 | 4 |
| 20 | 30 | 100 | 110 |