Skip to content

Commit

Permalink
Add merge convenience method
Browse files Browse the repository at this point in the history
  • Loading branch information
matentzn committed Feb 25, 2024
1 parent 754cf49 commit 19d86c0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/babelon/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# Click input options common across commands
input_argument = click.argument("input", required=False, type=click.Path())

multiple_inputs_argument = click.argument("inputs", nargs=-1, required=False, type=click.Path())

input_format_option = click.option(
"--input-format",
"-f",
Expand Down Expand Up @@ -171,6 +173,25 @@ def statistics_translation_profile_command(
statistics_translation_profile(input)


@click.command("merge")
@multiple_inputs_argument
@output_option
def merge(inputs, output):
"""Merge multiple babelon files into one."""

df = pd.read_csv(inputs[0], sep='\t')

# Loop through the rest of the input files and concatenate each DataFrame
for input_file in inputs[1:]:
df_temp = pd.read_csv(input_file, sep='\t')
df = pd.concat([df, df_temp], axis=0, ignore_index=True)

if output:
df.to_csv(output, sep="\t", index=False)
else:
click.echo(df.to_string(index=False))


@click.command("example")
@input_argument
def example(input):
Expand Down Expand Up @@ -204,6 +225,7 @@ def example(input):


babelon.add_command(example)
babelon.add_command(merge)
babelon.add_command(parse)
babelon.add_command(prepare_translation)
babelon.add_command(translate)
Expand Down

0 comments on commit 19d86c0

Please sign in to comment.