Skip to content

Commit

Permalink
Black on all python files
Browse files Browse the repository at this point in the history
Attempt of normalizing the format of the tools.

[#1]
  • Loading branch information
curtisim0 committed Dec 7, 2022
1 parent a90b65b commit a7cfc0f
Show file tree
Hide file tree
Showing 126 changed files with 7,871 additions and 3,790 deletions.
2 changes: 1 addition & 1 deletion blast/blasttab_dice_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def blasttsv2gff3(blasttsv, min_dice=50):
line = line.strip("\n")
data = line.split("\t")
dice = 2 * float(data[14]) / (float(data[22]) + float(data[23]))

if dice >= min_dice:
yield line

Expand Down
10 changes: 5 additions & 5 deletions blast/blasttab_to_gapped_gff3.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ def blasttsv2gff3(
continue

dc = {k: v for (k, v) in zip(columns, (x.strip() for x in record.split("\t")))}
#print(columns)
#print(dc)
#exit()
# print(columns)
# print(dc)
# exit()

rec = SeqRecord(Seq("ACTG"), id=dc["qseqid"])
#print(record_idx)
#print(type(record_idx))
# print(record_idx)
# print(type(record_idx))
feature_id = "blast.%s.%s.%s" % (record_idx, dc["qseqid"], dc["sseqid"])
feature_id = re.sub("\|", "_", feature_id) # Replace any \ or | with _
feature_id = re.sub(
Expand Down
2 changes: 1 addition & 1 deletion blast/relatedness.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def scoreMap(blast):
# data = expand_taxIDs(data)
# data = deform_scores(data)
if not args.noFilter:
data = filter_phage(data, phageTaxLookup)
data = filter_phage(data, phageTaxLookup)
# data = expand_titles(data)

if args.protein or args.canonical:
Expand Down
96 changes: 56 additions & 40 deletions comparative/mist3.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@

class FancyRecord(object):
def __init__(self, record, tmpdir):
self.temp = tempfile.NamedTemporaryFile(mode='w', dir=tmpdir, delete=False, suffix=".fa")
self.temp = tempfile.NamedTemporaryFile(
mode="w", dir=tmpdir, delete=False, suffix=".fa"
)
self.temp_path = self.temp.name
self.id = self.temp_path.rsplit("/")[-1]
self.record = record
Expand Down Expand Up @@ -110,8 +112,7 @@ def __repr__(self):
return "Subplot [%s]" % self.get_description()

def run_gepard(self, matrix, window, global_rescale="35%"):
"""Run gepard on two sequences, with a specified output file
"""
"""Run gepard on two sequences, with a specified output file"""
log.info("Running Gepard on %s", self.get_description())

destination_fn = (
Expand All @@ -138,8 +139,8 @@ def run_gepard(self, matrix, window, global_rescale="35%"):
"--silent",
]
log.debug(subprocess.list2cmdline(cmd))
#log.info(subprocess.check_output("convert -list type"))
#exit(2)
# log.info(subprocess.check_output("convert -list type"))
# exit(2)
failure_count = 0
while True:
try:
Expand Down Expand Up @@ -209,8 +210,7 @@ def char_height(font_size):
return int(float(font_size) * 30 / 40)

def est_pixels(string, font_size):
"""guess pixel width of a string at a given font size
"""
"""guess pixel width of a string at a given font size"""
return char_width(font_size) * len(string)

j_ticks = int(Misty.BestTick(self.j.length, 5))
Expand Down Expand Up @@ -246,7 +246,10 @@ def est_pixels(string, font_size):
primary_header = self.i.header
secondary_head = self.i.description
cmd += (
["-rotate", "-90",]
[
"-rotate",
"-90",
]
+ FONT_30pt
+ [
# Side label (i/row)
Expand All @@ -266,7 +269,10 @@ def est_pixels(string, font_size):
]
)

if est_pixels(self.i.description, 10) < original_dims[1] and secondary_head != "":
if (
est_pixels(self.i.description, 10) < original_dims[1]
and secondary_head != ""
):
cmd += FONT_10pt + [
# Side label (i/row)
"-annotate",
Expand Down Expand Up @@ -340,7 +346,10 @@ def est_pixels(string, font_size):
]
)

if est_pixels(self.j.description, 10) < original_dims[0] and secondary_head != "":
if (
est_pixels(self.j.description, 10) < original_dims[0]
and secondary_head != ""
):
cmd += FONT_10pt + [
"-annotate",
"+%s+%s"
Expand Down Expand Up @@ -379,25 +388,23 @@ def est_pixels(string, font_size):
cmd += ["-annotate", "+%s+%s" % (x + 5, y), self.label_formatter(z)]

cmd.append(outfile)
#tmpFile = open(outfile, "w")
#tmpFile.close()
log.info(subprocess.check_output( ["cp", infile, outfile] ))
# tmpFile = open(outfile, "w")
# tmpFile.close()
log.info(subprocess.check_output(["cp", infile, outfile]))
log.info(subprocess.list2cmdline(cmd))
log.info(subprocess.check_output( "ls" ))
log.info(subprocess.check_output("ls"))
log.info(self.tmpdir)
log.info(subprocess.check_output( ["ls", self.tmpdir]))
log.info(subprocess.check_output(["ls", self.tmpdir]))
log.info(outfile[2:])
log.info("Above was ls\n")
try:
subprocess.check_output(cmd)# + [" 2>&1"])
subprocess.check_output(cmd) # + [" 2>&1"])
except:
log.info("Excepted")



class Misty(object):
"""MIST Class for building MIST Plots
"""
"""MIST Class for building MIST Plots"""

def __init__(self, window=10, zoom=50, matrix="edna", files_path="mist_images"):
self.tmpdir = tempfile.mkdtemp(prefix="cpt.mist3.", dir=".")
Expand Down Expand Up @@ -563,7 +570,7 @@ def _generate_montage(self):
MONTAGE_BORDER_COORD = "%sx%s" % (MONTAGE_BORDER, MONTAGE_BORDER)

m0 = os.path.join(self.tmpdir, "m0.png")
# log.info(subprocess.check_output( ["cp", image_list[0], m0] ))
# log.info(subprocess.check_output( ["cp", image_list[0], m0] ))
cmd = ["montage"] + image_list
cmd += [
"-tile",
Expand All @@ -581,9 +588,9 @@ def _generate_montage(self):

log.debug(" ".join(cmd))
try:
subprocess.check_call(cmd)
subprocess.check_call(cmd)
except:
log.debug("Excepted, 2")
log.debug("Excepted, 2")
# Add grey borders
montage_path = os.path.join(self.tmpdir, "montage.png")
cmd = [
Expand All @@ -602,9 +609,9 @@ def _generate_montage(self):

log.debug(" ".join(cmd))
try:
subprocess.check_call(cmd)
subprocess.check_call(cmd)
except:
log.debug("Excepted, 2")
log.debug("Excepted, 2")
os.unlink(m0)
return montage_path

Expand All @@ -629,38 +636,47 @@ def _annotate_montage(self, base_path):
current_sum_width = MONTAGE_BORDER
current_sum_height = MONTAGE_BORDER

convert_arguments_top+= [
"-rotate",
"-90"
]
convert_arguments_top += ["-rotate", "-90"]
# Top side
for j in range(len(self.matrix_data[0])):
subplot = self.matrix_data[0][j]["subplot"]
convert_arguments_top += [
"-fill",
LABEL_COLOUR,
"-annotate",
"-%s+%s" % (0, str(cumulative_width - current_sum_width -(subplot.get_thumb_dims()[0]/2) + (2 * MONTAGE_BORDER) + IMAGE_BORDER)),
"-%s+%s"
% (
0,
str(
cumulative_width
- current_sum_width
- (subplot.get_thumb_dims()[0] / 2)
+ (2 * MONTAGE_BORDER)
+ IMAGE_BORDER
),
),
subplot.j.header,
]
current_sum_width += subplot.get_thumb_dims()[0] + (2 * IMAGE_BORDER)
log.debug("CSW %s", current_sum_width)
convert_arguments_top+= [
"-rotate",
"90"
]
convert_arguments_top += ["-rotate", "90"]
# Left side
#convert_arguments_left += [
# convert_arguments_left += [
# "-rotate",
# "90"
#]
# ]
for i in range(len(self.matrix_data)):
subplot = self.matrix_data[i][0]["subplot"]
convert_arguments_left += [
"-fill",
LABEL_COLOUR,
"-annotate",
"+2+%s" % str(current_sum_height + (subplot.get_thumb_dims()[1]/2.0) + IMAGE_BORDER),
"+2+%s"
% str(
current_sum_height
+ (subplot.get_thumb_dims()[1] / 2.0)
+ IMAGE_BORDER
),
"\n" + subplot.i.header,
]
current_sum_height += subplot.get_thumb_dims()[1] + (2 * IMAGE_BORDER)
Expand All @@ -669,15 +685,15 @@ def _annotate_montage(self, base_path):
cmd = [
"convert",
base_path,
# "-rotate",
# "-90",
# "-rotate",
# "-90",
"-pointsize",
"20",
"-font",
TYPEFONT,
]
cmd += convert_arguments_left
# cmd += ["-rotate", "90"]
# cmd += ["-rotate", "90"]
cmd += convert_arguments_top

output_path = os.path.join(self.tmpdir, "large.png")
Expand All @@ -694,7 +710,7 @@ def _annotate_montage(self, base_path):
subprocess.check_call(cmd)
except:
log.debug("Excepted, 3")
#subprocess.check_output(cmd)
# subprocess.check_output(cmd)
return output_path

def run(self):
Expand Down
9 changes: 3 additions & 6 deletions comparative/xmfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@


def parse_xmfa(xmfa):
"""Simple XMFA parser until https://github.com/biopython/biopython/pull/544
"""
"""Simple XMFA parser until https://github.com/biopython/biopython/pull/544"""
current_lcb = []
current_seq = {}
for line in xmfa.readlines():
Expand Down Expand Up @@ -103,8 +102,7 @@ def to_xmfa(lcbs, handle=sys.stdout):


def percent_identity(a, b):
"""Calculate % identity, ignoring gaps in the host sequence
"""
"""Calculate % identity, ignoring gaps in the host sequence"""
match = 0
mismatch = 0
for char_a, char_b in zip(list(a), list(b)):
Expand All @@ -121,8 +119,7 @@ def percent_identity(a, b):


def id_tn_dict(sequences, tmpfile=False):
"""Figure out sequence IDs
"""
"""Figure out sequence IDs"""
label_convert = {}
correct_chrom = None
if not isinstance(sequences, list):
Expand Down
3 changes: 1 addition & 2 deletions comparative/xmfa2tbl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@


def _id_tn_dict(sequences):
"""Figure out sequence IDs AND sequence lengths from fasta file
"""
"""Figure out sequence IDs AND sequence lengths from fasta file"""
label_convert = {}
if sequences is not None:
if len(sequences) == 1:
Expand Down
8 changes: 4 additions & 4 deletions cpt_annotation_table/gff3.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ def feature_test_type(feature, **kwargs):
if "type" in kwargs:
return str(feature.type).upper() == str(kwargs["type"]).upper()
elif "types" in kwargs:
for x in kwargs["types"]:
if str(feature.type).upper() == str(x).upper():
return True
return False
for x in kwargs["types"]:
if str(feature.type).upper() == str(x).upper():
return True
return False
raise Exception("Incorrect feature_test_type call, need type or types")


Expand Down
Loading

0 comments on commit a7cfc0f

Please sign in to comment.