Skip to content

Commit

Permalink
Merge pull request #1071 from griffithlab/vector_png
Browse files Browse the repository at this point in the history
Fix blurry pVACvector visualization images
  • Loading branch information
susannasiebert committed Mar 13, 2024
2 parents dd495dd + 6f3db87 commit d6e9acb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
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')))

0 comments on commit d6e9acb

Please sign in to comment.