|
40 | 40 | merge_msdf, |
41 | 41 | reconcile_prefix_and_data, |
42 | 42 | remove_unmatched, |
| 43 | + sort_df_rows_columns, |
43 | 44 | to_mapping_set_dataframe, |
44 | 45 | ) |
45 | 46 | from .writers import write_table |
|
77 | 78 | type=click.Path(), |
78 | 79 | help="The path to a file containing the sssom metadata (including prefix_map) to be used.", |
79 | 80 | ) |
80 | | -transpose_option = click.option("-t", "--transpose/--no-transpose", default=False) |
| 81 | +transpose_option = click.option("-t", "--transpose", default=False) |
81 | 82 | fields_option = click.option( |
82 | | - "-F", |
| 83 | + "-f", |
83 | 84 | "--fields", |
84 | 85 | nargs=2, |
85 | 86 | default=("subject_category", "object_category"), |
@@ -212,7 +213,7 @@ def dedupe(input: str, output: TextIO): |
212 | 213 |
|
213 | 214 |
|
214 | 215 | @main.command() |
215 | | -@click.option("-q", "--query", help='SQL query. Use "df" as table name.') |
| 216 | +@click.option("-Q", "--query", help='SQL query. Use "df" as table name.') |
216 | 217 | @click.argument("inputs", nargs=-1) |
217 | 218 | @output_option |
218 | 219 | def dosql(query: str, inputs: List[str], output: TextIO): |
@@ -425,7 +426,7 @@ def correlations(input: str, output: TextIO, transpose: bool, fields: Tuple): |
425 | 426 | @main.command() |
426 | 427 | @click.argument("inputs", nargs=-1) |
427 | 428 | @click.option( |
428 | | - "-r", |
| 429 | + "-R", |
429 | 430 | "--reconcile", |
430 | 431 | default=True, |
431 | 432 | help="Boolean indicating the need for reconciliation of the SSSOM tsv file.", |
@@ -501,5 +502,34 @@ def reconcile_prefixes(input: str, reconcile_prefix_file: Path, output: TextIO): |
501 | 502 | write_table(recon_msdf, output) |
502 | 503 |
|
503 | 504 |
|
| 505 | +@main.command() |
| 506 | +@input_argument |
| 507 | +@output_option |
| 508 | +@click.option( |
| 509 | + "-k", |
| 510 | + "--by-columns", |
| 511 | + default=True, |
| 512 | + help="Sort columns of DataFrame canonically.", |
| 513 | +) |
| 514 | +@click.option( |
| 515 | + "-r", |
| 516 | + "--by-rows", |
| 517 | + default=True, |
| 518 | + help="Sort rows by DataFrame column #1 (ascending).", |
| 519 | +) |
| 520 | +def sort(input: str, output: TextIO, by_columns: bool, by_rows: bool): |
| 521 | + """ |
| 522 | + Sort DataFrame columns canonically. |
| 523 | +
|
| 524 | + :param input: SSSOM TSV file. |
| 525 | + :param by_columns: Boolean flag to sort columns canonically. |
| 526 | + :param by_rows: Boolean flag to sort rows by column #1 (ascending order). |
| 527 | + :param output: SSSOM TSV file with columns sorted. |
| 528 | + """ |
| 529 | + msdf = read_sssom_table(input) |
| 530 | + msdf.df = sort_df_rows_columns(msdf.df, by_columns, by_rows) |
| 531 | + write_table(msdf, output) |
| 532 | + |
| 533 | + |
504 | 534 | if __name__ == "__main__": |
505 | 535 | main() |
0 commit comments