Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test():
cairocffi_context = cairocffi.Context(cairocffi.PDFSurface(None, 10, 20))
cairocffi_context.scale(2, 3)
pycairo_context = _UNSAFE_cairocffi_context_to_pycairo(cairocffi_context)
cairocffi_context2 = _UNSAFE_pycairo_context_to_cairocffi(pycairo_context)
assert tuple(cairocffi_context.get_matrix()) == (2, 0, 0, 3, 0, 0)
assert tuple(cairocffi_context2.get_matrix()) == (2, 0, 0, 3, 0, 0)
assert tuple(pycairo_context.get_matrix()) == (2, 0, 0, 3, 0, 0)
assert cairocffi_context2._pointer == cairocffi_context._pointer
file_obj = io.BytesIO()
# Mostly test that this runs without raising.
pango_example.write_example_pdf(file_obj)
assert file_obj.getvalue().startswith(b'%PDF')
def test_surface():
surface = ImageSurface(cairocffi.FORMAT_ARGB32, 20, 30)
similar = surface.create_similar(cairocffi.CONTENT_ALPHA, 4, 100)
assert isinstance(similar, ImageSurface)
assert similar.get_content() == cairocffi.CONTENT_ALPHA
assert similar.get_format() == cairocffi.FORMAT_A8
assert similar.get_width() == 4
assert similar.get_height() == 100
assert similar.has_show_text_glyphs() is False
assert PDFSurface(None, 1, 1).has_show_text_glyphs() is True
surface.copy_page()
surface.show_page()
surface.mark_dirty()
surface.mark_dirty_rectangle(1, 2, 300, 12000)
surface.flush()
surface.set_device_offset(14, 3)
assert surface.get_device_offset() == (14, 3)
surface.set_fallback_resolution(15, 6)
assert surface.get_fallback_resolution() == (15, 6)
context = Context(surface)
assert isinstance(context.get_target(), ImageSurface)
surface_map = cairocffi.surfaces.SURFACE_TYPE_TO_CLASS
try:
prefix=os.path.splitext(npz_file)[0]+"_kernels/"
if not os.path.isdir(prefix):
try:
os.mkdir(prefix)
except:
sys.exit()
meme_fileout=open(prefix+'motifs.meme','w')
meme_def="MEME version 4\n\nALPHABET= ACGT\n\nstrands: + -\n\n\Background letter frequencies (from uniform background):\nA 0.2500 C 0.2500 G 0.2500 T 0.2500\n\n"
meme_fileout.write(meme_def)
kernel_shape_ic_list=[]
for k in range(kernel_shape[2]):
meme_def="MOTIF kernel_"+str(k)+"\n\nletter-probability matrix: alength= 4 w= 9 nsites= 9 E= 0\n"
meme_fileout.write(meme_def)
ims1 = cairo.PDFSurface(None, width, hight)
cr = cairo.Context(ims1)
cr.set_source_rgb(0.0,0.0,0)
cr.move_to(width*0.1, y_center)
cr.line_to(width*0.9, y_center)
#cr.move_to(50, 100)
#cr.line_to(50, 412)
cr.set_line_width(2)
cr.stroke()
cr.move_to(width*0.1, y_center)
cr.line_to(width*0.1, y_center-120)
cr.set_line_width(2)
cr.stroke()
cr.move_to(width*0.1, y_center-60)
cr.line_to(width*0.08, y_center-60)
cr.set_line_width(2)
cr.stroke()
def kernel_connector(png_list):
pt_per_mm = 72 / 25.4
width, height = 210 * pt_per_mm, 297 * pt_per_mm
upper_lim=height*0.1
lateral_lim=width*0.1
x_interval=width*0.8/9.0
nodew=width*0.005
nodeh=0.0015*height
out_dir=os.path.split(png_list[0])[0]+"/kernels.pdf"
ims1 = cairo.PDFSurface(out_dir, width, height)
cr = cairo.Context(ims1)
#cr.scale(pt_per_mm,pt_per_mm)
coordinates={}
im = Image.open(png_list[0])
xwidth=int(width*0.8/10.0)+5
ywidth=int(im.size[1]*xwidth/float(im.size[0]))
#print xwidth, ywidth
for k, i in enumerate(png_list):
im = Image.open(i)
im=im.resize([xwidth, ywidth], Image.ANTIALIAS)
#im.thumbnail([xwidth, ywidth], Image.LANCZOS)
_buffer = StringIO.StringIO()
im.save(_buffer, format="PNG", quality=100)#,compress_level=0, dpi=(xwidth, ywidth))
_buffer.seek(0)
png_image=cairo.ImageSurface.create_from_png(_buffer)
def __init__(self, name, width, height, bg_color=None):
self.width = width
self.height = height
self._cairo_surface = cairo.PDFSurface(name, width, height)
reconstruct_pos_sum=np.sum(reconstruct_pos, axis=1)
reconstruct_neg_sum=np.sum(reconstruct_neg, axis=1)
max_value=reconstruct_pos_sum.max()
min_value=reconstruct_neg_sum.min()
min_value_abs=-min_value
if min_value_abs>max_value:
max_value=min_value_abs"""
#scale_factor=400/max_value
width=DNA_len*30/line_num+200
hight=1024*2*3
y_center=300
ims1 = cairo.PDFSurface(output_file, width, hight)
cr = cairo.Context(ims1)
cr.move_to(100, y_center)
cr.line_to(DNA_len/line_num*30+100, y_center)
#cr.move_to(50, 100)
#cr.line_to(50, 412)
cr.set_line_width(2)
cr.stroke()
meme_fileout=open(output_file+'.meme','w')
meme_fileout.write("MEME version 4\n\nALPHABET= ACGT\n\nstrands: + -\n\n\
Background letter frequencies (from uniform background):\nA 0.2500 C 0.2500 G 0.2500 T 0.2500\n\nMOTIF LONG_MOTIF\n\nletter-probability matrix: alength= 4 w= 1000 nsites= 20 E= 0\n")
for k in range(1000):
if not k==0 and k%(DNA_len/line_num)==0:
cr.set_source_rgba(0.0,0.0,0,1.0)
y_center+=300
def setupCairo(self, outputFormat='png'):
self.outputFormat = outputFormat
if outputFormat == 'png':
self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
self.width, self.height)
elif outputFormat == 'svg':
self.surfaceData = BytesIO()
self.surface = cairo.SVGSurface(self.surfaceData,
self.width, self.height)
elif outputFormat == 'pdf':
self.surfaceData = BytesIO()
self.surface = cairo.PDFSurface(self.surfaceData,
self.width, self.height)
res_x, res_y = self.surface.get_fallback_resolution()
self.width = float(self.width / res_x) * 72
self.height = float(self.height / res_y) * 72
self.surface.set_size(self.width, self.height)
self.ctx = cairo.Context(self.surface)
def __init__(self, filename, entity, options):
self.color = (0, 0, 0)
self.factor = 1
self.background_color = (0, 0, 0)
self.analyse_options(options)
self.surface = cairo.SVGSurface(filename, 10, 10)
self.context = cairo.Context(self.surface)
self.factor = 1
self.height = self.compute_height(entity)
self.width = self.compute_width(entity)
self.line_length = default_line_length
self.surface = cairo.PDFSurface(
filename, self.width + self.line_length * 2 + bbox_w_margin * 2, self.height + bbox_h_margin * 2)
self.context = cairo.Context(self.surface)
self.compute_wire_length(entity)
if options.format.lower() == "svg":
self.factor = 1
self.surface = cairo.SVGSurface(
filename, self.width + self.line_length * 2 + bbox_w_margin * 2, self.height + bbox_h_margin * 2)
if options.format.lower() == "pdf":
self.factor = 1
self.surface = cairo.PDFSurface(
filename, self.width + self.line_length * 2 + bbox_w_margin * 2, self.height + bbox_h_margin * 2)
if options.format.lower() == "ps":
self.line_length = default_line_length
self.surface = cairo.PDFSurface(
filename, self.width + self.line_length * 2 + bbox_w_margin * 2, self.height + bbox_h_margin * 2)
self.context = cairo.Context(self.surface)
self.compute_wire_length(entity)
if options.format.lower() == "svg":
self.factor = 1
self.surface = cairo.SVGSurface(
filename, self.width + self.line_length * 2 + bbox_w_margin * 2, self.height + bbox_h_margin * 2)
if options.format.lower() == "pdf":
self.factor = 1
self.surface = cairo.PDFSurface(
filename, self.width + self.line_length * 2 + bbox_w_margin * 2, self.height + bbox_h_margin * 2)
if options.format.lower() == "ps":
self.factor = 1
self.surface = cairo.PSSurface(
filename, self.width + self.line_length * 2 + bbox_w_margin * 2, self.height + bbox_h_margin * 2)
if options.format.lower() == "png":
self.factor = float(
options.width / (self.width + self.factor * self.line_length * 2 + self.factor * bbox_w_margin * 2))
stride = cairo.ImageSurface.format_stride_for_width(
cairo.FORMAT_ARGB32, 10000)
data = bytearray(stride * 10000)
# stride = cairo.ImageSurface.format_stride_for_width(cairo.FORMAT_ARGB32, int(self.width)+1)
# data = bytearray(stride * int(self.height))