Skip to content

Commit

Permalink
Fix all flake8 linter problems (#6189)
Browse files Browse the repository at this point in the history
* fix flake8 linter problems

* one more
  • Loading branch information
bernt-matthias authored Aug 25, 2024
1 parent a773446 commit 02d2f93
Show file tree
Hide file tree
Showing 9 changed files with 593 additions and 335 deletions.
33 changes: 26 additions & 7 deletions tools/add_input_name_as_column/add_input_name_as_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,28 @@

def Parser():
the_parser = argparse.ArgumentParser(description="add label to last column of file")
the_parser.add_argument('--input', required=True, action="store", type=str, help="input tabular file")
the_parser.add_argument('--output', required=True, action="store", type=str, help="output file path")
the_parser.add_argument('--label', required=True, action="store", type=str, help="label to add in last column")
the_parser.add_argument('--header', action="store", type=str, help="column label for last column")
the_parser.add_argument('--prepend', action='store_true', default=False, help='Prepend column instead of appending' )
the_parser.add_argument(
"--input", required=True, action="store", type=str, help="input tabular file"
)
the_parser.add_argument(
"--output", required=True, action="store", type=str, help="output file path"
)
the_parser.add_argument(
"--label",
required=True,
action="store",
type=str,
help="label to add in last column",
)
the_parser.add_argument(
"--header", action="store", type=str, help="column label for last column"
)
the_parser.add_argument(
"--prepend",
action="store_true",
default=False,
help="Prepend column instead of appending",
)

args = the_parser.parse_args()
return args
Expand All @@ -17,9 +34,11 @@ def Parser():
args = Parser()


with io.open(args.input, encoding="utf-8") as input, io.open(args.output, 'w', encoding="utf-8") as output:
with io.open(args.input, encoding="utf-8") as input, io.open(
args.output, "w", encoding="utf-8"
) as output:
for i, line in enumerate(input):
line = line.strip('\n')
line = line.strip("\n")
if (i == 0) and args.header:
new_entry = args.header
else:
Expand Down
32 changes: 21 additions & 11 deletions tools/column_order_header_sort/column_order_header_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,35 @@
key_column = sys.argv[4]

try:
key_column = int( key_column ) - 1
key_column = int(key_column) - 1
except Exception:
key_column = None

header = None
with open( input_filename, 'r' ) as fh:
header = fh.readline().strip( '\r\n' )
header = header.split( delimiter )
assert len( header ) == len( set( header ) ), "Header values must be unique"
sorted_header = list( header )
with open(input_filename, "r") as fh:
header = fh.readline().strip("\r\n")
header = header.split(delimiter)
assert len(header) == len(set(header)), "Header values must be unique"
sorted_header = list(header)
if key_column is None:
columns = []
else:
columns = [ key_column ]
sorted_header.pop( key_column )
columns = [key_column]
sorted_header.pop(key_column)
sorted_header.sort()

for key in sorted_header:
columns.append( header.index( key ) )
columns.append(header.index(key))

awk_cmd = AWK_CMD % ( delimiter, delimiter, ",".join( map( lambda x: "$%i" % ( x + 1 ), columns ) ) )
sys.exit( subprocess.call( [ 'gawk', awk_cmd, input_filename ], stdout=open( output_filename, 'wb+' ), shell=False ) )
awk_cmd = AWK_CMD % (
delimiter,
delimiter,
",".join(map(lambda x: "$%i" % (x + 1), columns)),
)
sys.exit(
subprocess.call(
["gawk", awk_cmd, input_filename],
stdout=open(output_filename, "wb+"),
shell=False,
)
)
93 changes: 71 additions & 22 deletions tools/cwpair2/cwpair2.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,63 @@

import cwpair2_util

if __name__ == '__main__':
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--input', dest='inputs', action='append', nargs=2, help="Input datasets")
parser.add_argument('--method', dest='method', default='mode', help='Method of finding match.')
parser.add_argument('--up_distance', dest='up_distance', type=int, default=50, help='Distance upstream from a pair.')
parser.add_argument('--down_distance', dest='down_distance', type=int, default=100, help='Distance downstream of a pair.')
parser.add_argument('--binsize', dest='binsize', type=int, default=1, help='Width of bins for plots and mode.')
parser.add_argument('--threshold_format', dest='threshold_format', help='Percentage to filter the 95th percentile.')
parser.add_argument('--relative_threshold', dest='relative_threshold', type=float, default=0.0, help='Percentage to filter the 95th percentile.')
parser.add_argument('--absolute_threshold', dest='absolute_threshold', type=float, default=0.0, help='Absolute value to filter.')
parser.add_argument('--output_files', dest='output_files', default='matched_pair', help='Restrict output dataset collections.')
parser.add_argument('--statistics_output', dest='statistics_output', help='Statistics output file.')
parser.add_argument(
"--input", dest="inputs", action="append", nargs=2, help="Input datasets"
)
parser.add_argument(
"--method", dest="method", default="mode", help="Method of finding match."
)
parser.add_argument(
"--up_distance",
dest="up_distance",
type=int,
default=50,
help="Distance upstream from a pair.",
)
parser.add_argument(
"--down_distance",
dest="down_distance",
type=int,
default=100,
help="Distance downstream of a pair.",
)
parser.add_argument(
"--binsize",
dest="binsize",
type=int,
default=1,
help="Width of bins for plots and mode.",
)
parser.add_argument(
"--threshold_format",
dest="threshold_format",
help="Percentage to filter the 95th percentile.",
)
parser.add_argument(
"--relative_threshold",
dest="relative_threshold",
type=float,
default=0.0,
help="Percentage to filter the 95th percentile.",
)
parser.add_argument(
"--absolute_threshold",
dest="absolute_threshold",
type=float,
default=0.0,
help="Absolute value to filter.",
)
parser.add_argument(
"--output_files",
dest="output_files",
default="matched_pair",
help="Restrict output dataset collections.",
)
parser.add_argument(
"--statistics_output", dest="statistics_output", help="Statistics output file."
)
args = parser.parse_args()

cwpair2_util.create_directories()
Expand All @@ -41,28 +86,32 @@
else:
threshold = 0
for (dataset_path, hid) in args.inputs:
stats = cwpair2_util.process_file(dataset_path,
hid,
args.method,
threshold,
args.up_distance,
args.down_distance,
args.binsize,
args.output_files)
stats = cwpair2_util.process_file(
dataset_path,
hid,
args.method,
threshold,
args.up_distance,
args.down_distance,
args.binsize,
args.output_files,
)
statistics.extend(stats)
# Accumulate statistics.
by_file = {}
for stats in statistics:
# Skip "None" statistics from failed files
if not stats:
continue
path = stats['stats_path']
path = stats["stats_path"]
if path not in by_file:
by_file[path] = []
by_file[path].append(stats)
# Write tabular statistics file.
keys = ['fname', 'final_mode', 'preview_mode', 'perc95', 'paired', 'orphans']
statistics_out = csv.writer(open(args.statistics_output, 'wt'), delimiter='\t', lineterminator="\n")
keys = ["fname", "final_mode", "preview_mode", "perc95", "paired", "orphans"]
statistics_out = csv.writer(
open(args.statistics_output, "wt"), delimiter="\t", lineterminator="\n"
)
statistics_out.writerow(keys)
for file_path, statistics in by_file.items():
for stats in statistics:
Expand Down
Loading

0 comments on commit 02d2f93

Please sign in to comment.