Skip to content

Commit

Permalink
Feat: Add auto-filter to excel output
Browse files Browse the repository at this point in the history
  • Loading branch information
skchronicles committed Dec 1, 2023
1 parent acf5e49 commit d3b3fc3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.0
1.3.1
2 changes: 2 additions & 0 deletions workflow/rules/paired-end.smk
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ rule blast_metaspades_xlsx:
# of aligning the metaspades
# contigs against NCBI viral db
{params.script} \\
--add-auto-filters \\
--rm-suffix "{params.extension}" \\
--input {output.tsv} {input.blasts} \\
--output {output.excel}
Expand Down Expand Up @@ -888,6 +889,7 @@ rule blast_megahit_xlsx:
# of aligning the megahit
# contigs against NCBI viral db
{params.script} \\
--add-auto-filters \\
--rm-suffix "{params.extension}" \\
--input {output.tsv} {input.blasts} \\
--output {output.excel}
Expand Down
33 changes: 29 additions & 4 deletions workflow/scripts/files2spreadsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@

# Script metadata
__author__ = "Skyler Kuhn"
__version__ = "v0.1.0"
__version__ = "v0.2.0"

_help = textwrap.dedent(
"""./file2spreadsheet.py:
Creates an excel file from a list of input files.
@Usage:
$ ./file2spreadsheet.py [-h] [--version] \\
[--add-auto-filters] \\
[--rm-suffix RM_SUFFIX] \\
[--comment-symbol COMMENT_SYMBOL] \\
--input FILE_1 [FILE_2 ...] \\
Expand Down Expand Up @@ -63,6 +64,12 @@
this character will be skipped. By
default, all lines of the file will
be included and nothing is skipped.
-a, --add-auto-filters
Adds auto-filters to all columns
in a worksheet. Excel auto-filters
apply drop-down filters/selectors
to the column headers in a sheet.
--h, --help Shows this help message and exits.
Expand Down Expand Up @@ -154,6 +161,17 @@ def parse_arguments():
help = argparse.SUPPRESS
)

# Applies auto-filters
# to column headers
parser.add_argument(
'-a',
'--add-auto-filters',
required=False,
default=False,
action = 'store_true',
help = argparse.SUPPRESS
)

# Add custom help message
parser.add_argument(
'-h', '--help',
Expand Down Expand Up @@ -266,7 +284,7 @@ def csv(filename, subset=[], skip='#', **kwargs):
return pd.read_csv(filename, comment=skip, **kwargs)


def excel_writer(files, spreadsheet, skip_comments=None, remove_suffix = ''):
def excel_writer(files, spreadsheet, skip_comments=None, remove_suffix = '', add_auto_filters=False):
"""Takes a list of files and creates one excel spreadsheet.
Each file will becomes a sheet in the spreadsheet where the
name of the sheet is the basename of the file with the extension
Expand Down Expand Up @@ -317,6 +335,8 @@ def excel_writer(files, spreadsheet, skip_comments=None, remove_suffix = ''):
)
) + 2 # adding a little extra space
worksheet.set_column(idx, idx, max_len) # set column width
if add_auto_filters:
worksheet.autofilter(0, 0, df.shape[0], df.shape[1])


def main():
Expand All @@ -335,16 +355,21 @@ def main():
# X tab/worksheet name
rm_suffix = args.rm_suffix

# Apply auto filters to
# column headers in a sheet
auto_filter = args.add_auto_filters

# Create XLSX file from the list
# of input files
excel_writer(
files=inputs,
spreadsheet=output,
skip_comments=comment_char,
remove_suffix=rm_suffix
remove_suffix=rm_suffix,
add_auto_filters=auto_filter
)


if __name__ == '__main__':
# Call main method
main()
main()

0 comments on commit d3b3fc3

Please sign in to comment.