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

Fix blurry pVACvector visualization images #1071

Merged
merged 1 commit into from Mar 13, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions pvactools/lib/vector_visualization.py
@@ -1,6 +1,7 @@
import turtle
import os
import sys
import math
from PIL import Image

class VectorVisualization:
Expand Down Expand Up @@ -228,11 +229,16 @@ def draw_arc_junct(self, peptide, length):
#print turtle screen to a postscript file, convert to pdf
def output_screen(self):
ps_file = os.path.join(self.output_directory, "vector.ps")
out_file = os.path.join(self.output_directory, "vector.jpg")
out_file = os.path.join(self.output_directory, "vector.png")
ts = self.turtle.getscreen()
ts.getcanvas().postscript(file=ps_file)
with Image.open(ps_file) as img:
img.save(out_file)
with Image.open(ps_file, formats=["EPS"]) as img:
original = [float(d) for d in img.size]
dpi = 300
scale = dpi / 72.0
img.load(scale = math.ceil(scale))
img.thumbnail([round(scale * d) for d in original], Image.Resampling.LANCZOS)
img.save(out_file, dpi=(300.0, 300.0))
os.remove(ps_file)

#select color from scheme
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pvacvector.py
Expand Up @@ -191,7 +191,7 @@ def test_pvacvector_fa_input_runs_and_produces_expected_output(self):
))

if 'DISPLAY' in os.environ.keys():
image_out = os.path.join(output_dir.name, 'vector.jpg')
image_out = os.path.join(output_dir.name, 'vector.png')
#vaccine visualization producing image
self.assertTrue(os.path.exists(image_out))
self.assertTrue(os.stat(image_out).st_size > 0)
Expand Down Expand Up @@ -226,7 +226,7 @@ def test_pvacvector_generate_fa_runs_and_produces_expected_output(self):


if 'DISPLAY' in os.environ.keys():
image_out = os.path.join(output_dir.name, 'vector.jpg')
image_out = os.path.join(output_dir.name, 'vector.png')
#vaccine visualization producing image
self.assertTrue(os.path.exists(image_out))
self.assertTrue(os.stat(image_out).st_size > 0)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_vector_visualization.py
Expand Up @@ -28,7 +28,7 @@ def test_fasta_with_spacers(self):
output_dir,
self.spacers
).draw())
self.assertTrue(os.path.exists(os.path.join(output_dir, 'vector.jpg')))
self.assertTrue(os.path.exists(os.path.join(output_dir, 'vector.png')))

def test_fasta_with_long_peptide(self):
if 'DISPLAY' in os.environ.keys():
Expand All @@ -41,4 +41,4 @@ def test_fasta_with_long_peptide(self):
output_dir,
self.spacers
).draw())
self.assertTrue(os.path.exists(os.path.join(output_dir, 'vector.jpg')))
self.assertTrue(os.path.exists(os.path.join(output_dir, 'vector.png')))