Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace percent with % in assembly.kmer #666

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions jcvi/assembly/kmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def run_optimization(termination=0.999, maxiter=100):
print(ll, rr, GG, file=sys.stderr)

# Ready for genome summary
m = "\n==> Kmer (K={0}) Spectrum Analysis\n".format(K)
m = f"\n==> Kmer (K={K}) Spectrum Analysis\n"

genome_size = int(round(self.totalKmers / ll))
inferred_genome_size = 0
Expand All @@ -270,7 +270,7 @@ def run_optimization(termination=0.999, maxiter=100):
inferred_genome_size += g * mid * (end - start + 1)
inferred_genome_size = int(round(inferred_genome_size))
genome_size = max(genome_size, inferred_genome_size)
m += "Genome size estimate = {0}\n".format(thousands(genome_size))
m += f"Genome size estimate = {thousands(genome_size)}\n"
copy_series = []
copy_messages = []
for i, g in enumerate(GG):
Expand All @@ -279,15 +279,15 @@ def run_optimization(termination=0.999, maxiter=100):
copy_num = start if start == end else "{}-{}".format(start, end)
g_copies = int(round(g * mid * (end - start + 1)))
copy_series.append((mid, copy_num, g_copies, g))
copy_message = f"CN {copy_num}: {g_copies / 1e6:.1f} Mb ({ g_copies * 100 / genome_size:.1f} percent)"
copy_message = f"CN {copy_num}: {g_copies / 1e6:.1f} Mb ({ g_copies * 100 / genome_size:.1f} %)"
copy_messages.append(copy_message)
m += copy_message + "\n"

if genome_size > inferred_genome_size:
g_copies = genome_size - inferred_genome_size
copy_num = "{}+".format(end + 1)
copy_series.append((end + 1, copy_num, g_copies, g_copies / (end + 1)))
m += f"CN {copy_num}: {g_copies / 1e6:.1f} Mb ({ g_copies * 100 / genome_size:.1f} percent)\n"
m += f"CN {copy_num}: {g_copies / 1e6:.1f} Mb ({ g_copies * 100 / genome_size:.1f} %)\n"

# Determine ploidy
def determine_ploidy(copy_series, threshold=0.15):
Expand All @@ -302,7 +302,7 @@ def determine_ploidy(copy_series, threshold=0.15):

ploidy = determine_ploidy(copy_series)
self.ploidy = ploidy
self.ploidy_message = "Ploidy: {}".format(ploidy)
self.ploidy_message = f"Ploidy: {ploidy}"
m += self.ploidy_message + "\n"
self.copy_messages = copy_messages[:ploidy]

Expand All @@ -317,7 +317,7 @@ def calc_repeats(copy_series, ploidy, genome_size):
return 1 - unique / genome_size

repeats = calc_repeats(copy_series, ploidy, genome_size)
self.repetitive = "Repeats: {:.1f} percent".format(repeats * 100)
self.repetitive = f"Repeats: {repeats * 100:.1f} %"
m += self.repetitive + "\n"

# SNP rate
Expand All @@ -336,7 +336,7 @@ def calc_snp_rate(copy_series, ploidy, genome_size, K):
return 1 - (1 - L / genome_size) ** (1 / K)

snp_rate = calc_snp_rate(copy_series, ploidy, genome_size, K)
self.snprate = "SNP rate: {:.2f} percent".format(snp_rate * 100)
self.snprate = f"SNP rate: {snp_rate * 100:.2f} %"
m += self.snprate + "\n"
print(m, file=sys.stderr)

Expand Down Expand Up @@ -475,22 +475,18 @@ def analyze_allpaths(self, ploidy=2, K=23, covmax=1000000):
GR = int(_genome_size_repetitive)
coverage = int(_coverage)

m = "Kmer (K={0}) Spectrum Analysis\n".format(K)
m += "Genome size estimate = {0}\n".format(thousands(G))
m += "Genome size estimate CN = 1 = {0} ({1})\n".format(
thousands(G1), percentage(G1, G)
)
m += "Genome size estimate CN > 1 = {0} ({1})\n".format(
thousands(GR), percentage(GR, G)
)
m += "Coverage estimate: {0} x\n".format(coverage)
self.repetitive = "Repeats: {0} percent".format(GR * 100 // G)
m = f"Kmer (K={K}) Spectrum Analysis\n"
m += f"Genome size estimate = {thousands(G)}\n"
m += f"Genome size estimate CN = 1 = {thousands(G1)} ({percentage(G1, G)})\n"
m += f"Genome size estimate CN > 1 = {thousands(GR)} ({percentage(GR, G)})\n"
m += f"Coverage estimate: {coverage} x\n"
self.repetitive = f"Repeats: {GR * 100 // G} %"

if ploidy == 2:
d_SNP = int(_d_SNP)
self.snprate = "SNP rate ~= 1/{0}".format(d_SNP)
self.snprate = f"SNP rate ~= 1/{d_SNP}"
else:
self.snprate = "SNP rate not computed (Ploidy = {0})".format(ploidy)
self.snprate = f"SNP rate not computed (Ploidy = {ploidy})"
m += self.snprate + "\n"

self.genomesize = int(round(self.totalKmers * 1.0 / self.max2))
Expand Down
4 changes: 2 additions & 2 deletions jcvi/graphics/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,15 +708,15 @@ def draw_cmap(ax, cmap_text, vmin, vmax, cmap=None, reverse=False):
ax.text(x, ymin - 0.005, "%.1f" % v, ha="center", va="top", size=10)


def write_messages(ax, messages, ypad=0.04):
def write_messages(ax, messages: List[str], ypad: float=0.04):
"""
Write text on canvas, usually on the top right corner.
"""
tc = "gray"
axt = ax.transAxes
yy = 0.95
for msg in messages:
ax.text(0.95, yy, msg, color=tc, transform=axt, ha="right")
ax.text(0.95, yy, markup(msg), color=tc, transform=axt, ha="right")
yy -= ypad


Expand Down