Skip to content

Commit

Permalink
Merge pull request #19314 from nsoranzo/fix_UP031_errors_pt6
Browse files Browse the repository at this point in the history
Fix UP031 errors - Part 6
  • Loading branch information
nsoranzo authored Dec 12, 2024
2 parents 21f8bc8 + 5544eff commit 3c82972
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 117 deletions.
6 changes: 3 additions & 3 deletions lib/galaxy/datatypes/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ def set_meta(
# Create the bcf index
dataset_symlink = os.path.join(
os.path.dirname(index_file.get_file_name()),
"__dataset_%d_%s" % (dataset.id, os.path.basename(index_file.get_file_name())),
f"__dataset_{dataset.id}_{os.path.basename(index_file.get_file_name())}",
)
os.symlink(dataset.get_file_name(), dataset_symlink)
try:
Expand Down Expand Up @@ -1677,15 +1677,15 @@ def set_peek(self, dataset: DatasetProtocol, **kwd) -> None:
def _makelayerstrings(layer, count, names):
"Format the layers."
if layer in tmp.layers_names:
return "\n[%s]: %d %s\n %s" % (
return "\n[{}]: {} {}\n {}".format(
layer,
count,
"layer" if count == 1 else "layers",
", ".join(sorted(names)),
)
return ""

peekstr = "[n_obs x n_vars]\n %d x %d" % tuple(tmp.shape)
peekstr = "[n_obs x n_vars]\n {} x {}".format(*tuple(tmp.shape))
peekstr += _makelayerstrings("obs", tmp.obs_count, tmp.obs_layers)
peekstr += _makelayerstrings("var", tmp.var_count, tmp.var_layers)
peekstr += _makelayerstrings("obsm", tmp.obsm_count, tmp.obsm_layers)
Expand Down
24 changes: 7 additions & 17 deletions lib/galaxy/datatypes/converters/bed_to_gff_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import sys

assert sys.version_info[:2] >= (2, 6)


def __main__():
input_name = sys.argv[1]
Expand All @@ -30,7 +28,7 @@ def __main__():
try:
feature = elems[3]
except Exception:
feature = "feature%d" % (i + 1)
feature = f"feature{i + 1}"
start = int(elems[1]) + 1
end = int(elems[2])
try:
Expand All @@ -44,17 +42,13 @@ def __main__():
try:
group = elems[3]
except Exception:
group = "group%d" % (i + 1)
group = f"group{i + 1}"
if complete_bed:
out.write(
"%s\tbed2gff\t%s\t%d\t%d\t%s\t%s\t.\t%s %s;\n"
% (chrom, feature, start, end, score, strand, feature, group)
f"{chrom}\tbed2gff\t{feature}\t{start}\t{end}\t{score}\t{strand}\t.\t{feature} {group};\n"
)
else:
out.write(
"%s\tbed2gff\t%s\t%d\t%d\t%s\t%s\t.\t%s;\n"
% (chrom, feature, start, end, score, strand, group)
)
out.write(f"{chrom}\tbed2gff\t{feature}\t{start}\t{end}\t{score}\t{strand}\t.\t{group};\n")
if complete_bed:
# We have all the info necessary to annotate exons for genes and mRNAs
block_count = int(elems[9])
Expand All @@ -64,8 +58,7 @@ def __main__():
exon_start = int(start) + int(block_starts[j])
exon_end = exon_start + int(block_sizes[j]) - 1
out.write(
"%s\tbed2gff\texon\t%d\t%d\t%s\t%s\t.\texon %s;\n"
% (chrom, exon_start, exon_end, score, strand, group)
f"{chrom}\tbed2gff\texon\t{exon_start}\t{exon_end}\t{score}\t{strand}\t.\texon {group};\n"
)
except Exception:
skipped_lines += 1
Expand All @@ -75,12 +68,9 @@ def __main__():
skipped_lines += 1
if not first_skipped_line:
first_skipped_line = i + 1
info_msg = "%i lines converted to GFF version 2. " % (i + 1 - skipped_lines)
info_msg = f"{i + 1 - skipped_lines} lines converted to GFF version 2. "
if skipped_lines > 0:
info_msg += "Skipped %d blank/comment/invalid lines starting with line #%d." % (
skipped_lines,
first_skipped_line,
)
info_msg += f"Skipped {skipped_lines} blank/comment/invalid lines starting with line #{first_skipped_line}."
print(info_msg)


Expand Down
6 changes: 2 additions & 4 deletions lib/galaxy/datatypes/converters/fasta_to_len.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"""
import sys

assert sys.version_info[:2] >= (2, 4)


def compute_fasta_length(fasta_file, out_file, keep_first_char, keep_first_word=False):
infile = fasta_file
Expand All @@ -34,7 +32,7 @@ def compute_fasta_length(fasta_file, out_file, keep_first_char, keep_first_word=
if first_entry is False:
if keep_first_word:
fasta_title = fasta_title.split()[0]
out.write("%s\t%d\n" % (fasta_title[1:keep_first_char], seq_len))
out.write(f"{fasta_title[1:keep_first_char]}\t{seq_len}\n")
else:
first_entry = False
fasta_title = line
Expand All @@ -45,7 +43,7 @@ def compute_fasta_length(fasta_file, out_file, keep_first_char, keep_first_word=
# last fasta-entry
if keep_first_word:
fasta_title = fasta_title.split()[0]
out.write("%s\t%d\n" % (fasta_title[1:keep_first_char], seq_len))
out.write(f"{fasta_title[1:keep_first_char]}\t{seq_len}\n")


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
"""
import sys

assert sys.version_info[:2] >= (2, 4)


def stop_err(msg):
sys.exit(f"{msg}")


def __main__():
infile_name = sys.argv[1]
Expand All @@ -39,7 +33,7 @@ def __main__():
if not seq_title_startswith:
seq_title_startswith = line_startswith
if seq_title_startswith != line_startswith:
stop_err("Invalid fastqsolexa format at line %d: %s." % (i + 1, line))
sys.exit(f"Invalid fastqsolexa format at line {i + 1}: {line}.")
outfile.write(f">{line[1:]}\n")
elif fastq_block_lines == 2:
# line 2 is nucleotides
Expand Down
20 changes: 6 additions & 14 deletions lib/galaxy/datatypes/converters/fastqsolexa_to_qual_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
"""
import sys

assert sys.version_info[:2] >= (2, 4)


def stop_err(msg):
sys.exit(f"{msg}")


def __main__():
infile_name = sys.argv[1]
Expand All @@ -42,7 +36,7 @@ def __main__():
if not seq_title_startswith:
seq_title_startswith = line_startswith
if line_startswith != seq_title_startswith:
stop_err("Invalid fastqsolexa format at line %d: %s." % (i + 1, line))
sys.exit(f"Invalid fastqsolexa format at line {i + 1}: {line}.")
read_title = line[1:]
elif fastq_block_lines == 2:
# second line is nucleotides
Expand All @@ -52,12 +46,11 @@ def __main__():
if not qual_title_startswith:
qual_title_startswith = line_startswith
if line_startswith != qual_title_startswith:
stop_err("Invalid fastqsolexa format at line %d: %s." % (i + 1, line))
sys.exit(f"Invalid fastqsolexa format at line {i + 1}: {line}.")
quality_title = line[1:]
if quality_title and read_title != quality_title:
stop_err(
'Invalid fastqsolexa format at line %d: sequence title "%s" differes from score title "%s".'
% (i + 1, read_title, quality_title)
sys.exit(
f'Invalid fastqsolexa format at line {i + 1}: sequence title "{read_title}" differes from score title "{quality_title}".'
)
if not quality_title:
outfile_score.write(f">{read_title}\n")
Expand Down Expand Up @@ -87,9 +80,8 @@ def __main__():
elif quality_score_length == read_length:
quality_score_startswith = default_coding_value
else:
stop_err(
"Invalid fastqsolexa format at line %d: the number of quality scores ( %d ) is not the same as bases ( %d )."
% (i + 1, quality_score_length, read_length)
sys.exit(
f"Invalid fastqsolexa format at line {i + 1}: the number of quality scores ( {quality_score_length} ) is not the same as bases ( {read_length} )."
)
for char in line:
score = ord(char) - quality_score_startswith # 64
Expand Down
9 changes: 2 additions & 7 deletions lib/galaxy/datatypes/converters/gff_to_bed_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import sys

assert sys.version_info[:2] >= (2, 6)


def __main__():
input_name = sys.argv[1]
Expand Down Expand Up @@ -35,12 +33,9 @@ def __main__():
skipped_lines += 1
if not first_skipped_line:
first_skipped_line = i + 1
info_msg = "%i lines converted to BED. " % (i + 1 - skipped_lines)
info_msg = f"{i + 1 - skipped_lines} lines converted to BED. "
if skipped_lines > 0:
info_msg += "Skipped %d blank/comment/invalid lines starting with line #%d." % (
skipped_lines,
first_skipped_line,
)
info_msg += f"Skipped {skipped_lines} blank/comment/invalid lines starting with line #{first_skipped_line}."
print(info_msg)


Expand Down
20 changes: 7 additions & 13 deletions lib/galaxy/datatypes/converters/interval_to_bed_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,26 @@

import bx.intervals.io

assert sys.version_info[:2] >= (2, 6)


def stop_err(msg):
sys.exit(msg)


def __main__():
output_name = sys.argv[1]
input_name = sys.argv[2]
try:
chromCol = int(sys.argv[3]) - 1
except Exception:
stop_err(
sys.exit(
f"'{str(sys.argv[3])}' is an invalid chrom column, correct the column settings before attempting to convert the data format."
)
try:
startCol = int(sys.argv[4]) - 1
except Exception:
stop_err(
sys.exit(
f"'{str(sys.argv[4])}' is an invalid start column, correct the column settings before attempting to convert the data format."
)
try:
endCol = int(sys.argv[5]) - 1
except Exception:
stop_err(
sys.exit(
f"'{str(sys.argv[5])}' is an invalid end column, correct the column settings before attempting to convert the data format."
)
try:
Expand Down Expand Up @@ -63,16 +57,16 @@ def __main__():
else:
raise IndexError
except Exception:
name = "region_%i" % count
name = f"region_{count}"
try:
out.write("%s\t%i\t%i\t%s\t%i\t%s\n" % (region.chrom, region.start, region.end, name, 0, region.strand))
out.write(f"{region.chrom}\t{region.start}\t{region.end}\t{name}\t0\t{region.strand}\n")
except Exception:
skipped_lines += 1
if not first_skipped_line:
first_skipped_line = count + 1
print("%i regions converted to BED." % (count + 1 - skipped_lines))
print(f"{count + 1 - skipped_lines} regions converted to BED.")
if skipped_lines > 0:
print("Skipped %d blank or invalid lines starting with line # %d." % (skipped_lines, first_skipped_line))
print(f"Skipped {skipped_lines} blank or invalid lines starting with line # {first_skipped_line}.")


if __name__ == "__main__":
Expand Down
22 changes: 8 additions & 14 deletions lib/galaxy/datatypes/converters/interval_to_bedstrict_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@

import bx.intervals.io

assert sys.version_info[:2] >= (2, 6)


def stop_err(msg):
sys.exit(msg)


def force_bed_field_count(fields, region_count, force_num_columns):
def force_bed_field_count(fields, region_count: int, force_num_columns: int):
if force_num_columns >= 4 and len(fields) < 4:
fields.append("region_%i" % (region_count))
fields.append(f"region_{region_count}")
if force_num_columns >= 5 and len(fields) < 5:
fields.append("0")
if force_num_columns >= 6 and len(fields) < 6:
Expand All @@ -40,19 +34,19 @@ def __main__():
try:
chromCol = int(sys.argv[3]) - 1
except Exception:
stop_err(
sys.exit(
f"'{str(sys.argv[3])}' is an invalid chrom column, correct the column settings before attempting to convert the data format."
)
try:
startCol = int(sys.argv[4]) - 1
except Exception:
stop_err(
sys.exit(
f"'{str(sys.argv[4])}' is an invalid start column, correct the column settings before attempting to convert the data format."
)
try:
endCol = int(sys.argv[5]) - 1
except Exception:
stop_err(
sys.exit(
f"'{str(sys.argv[5])}' is an invalid end column, correct the column settings before attempting to convert the data format."
)
try:
Expand Down Expand Up @@ -176,7 +170,7 @@ def __main__():
else:
raise IndexError
except Exception:
name = "region_%i" % count
name = f"region_{count}"
try:
fields = [str(item) for item in (region.chrom, region.start, region.end, name, 0, region.strand)]
if force_num_columns is not None and len(fields) != force_num_columns:
Expand All @@ -186,9 +180,9 @@ def __main__():
skipped_lines += 1
if first_skipped_line is None:
first_skipped_line = count + 1
print("%i regions converted to BED." % (count + 1 - skipped_lines))
print(f"{count + 1 - skipped_lines} regions converted to BED.")
if skipped_lines > 0:
print("Skipped %d blank or invalid lines starting with line # %d." % (skipped_lines, first_skipped_line))
print(f"Skipped {skipped_lines} blank or invalid lines starting with line # {first_skipped_line}.")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/datatypes/converters/interval_to_fli.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def main():
entries = []
for name in sorted(name_loc_dict.keys()):
loc = name_loc_dict[name]
entry = "{}\t{}\t{}".format(name.lower(), name, "%s:%i-%i" % (loc["contig"], loc["start"], loc["end"]))
entry = "{}\t{}\t{}:{}-{}".format(name.lower(), name, loc["contig"], loc["start"], loc["end"])
if len(entry) > max_len:
max_len = len(entry)
entries.append(entry)
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/datatypes/converters/lped_to_fped_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def main():
"""
nparm = 3
if len(sys.argv) < nparm:
sys.exit("## %s called with %s - needs %d parameters \n" % (prog, sys.argv, nparm))
sys.exit(f"## {prog} called with {sys.argv} - needs {nparm} parameters \n")
inpedfilepath = sys.argv[1]
outhtmlname = sys.argv[2]
outfilepath = sys.argv[3]
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/datatypes/converters/lped_to_pbed_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def main():
"""
nparm = 4
if len(sys.argv) < nparm:
sys.exit("## %s called with %s - needs %d parameters \n" % (prog, sys.argv, nparm))
sys.exit(f"## {prog} called with {sys.argv} - needs {nparm} parameters \n")
inpedfilepath = sys.argv[1]
outhtmlname = sys.argv[2]
outfilepath = sys.argv[3]
Expand Down
6 changes: 2 additions & 4 deletions lib/galaxy/datatypes/converters/maf_to_fasta_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

from galaxy.datatypes.util import maf_utilities

assert sys.version_info[:2] >= (2, 6)


def __main__():
output_name = sys.argv.pop(1)
Expand All @@ -28,13 +26,13 @@ def __main__():
maf_utilities.get_fasta_header(
c,
{"block_index": count, "species": spec, "sequence_index": spec_counts[spec]},
suffix="%s_%i_%i" % (spec, count, spec_counts[spec]),
suffix=f"{spec}_{count}_{spec_counts[spec]}",
)
)
)
out.write(f"{c.text}\n")
out.write("\n")
print("%i MAF blocks converted to FASTA." % (count))
print(f"{count} MAF blocks converted to FASTA.")


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 3c82972

Please sign in to comment.