[python] Edinburgh-Genome-Foundry:序列标识的图形化方法sequenticon

概述

这是一个python包。

优势

  1. 给出标签Identicon,可以单个/批量标识序列。对于某些只差一两个字符的序列,识别更方便。
  2. 可以生成pdf文件

劣势

  1. 只能生成标签,不提供解码。但是可以对照pdf确认序列与图像的对应关系。
  2. 生成pdf的包是该机构自己写的,需要调整代码以调整pdf的内容排布。
    pdf输出示例

代码分析(简单)

位置:
sequenticon-master\sequenticon\sequenticon.py

# 函数
sequenticon(sequence, output_format='png', size=60, output_path=None)
'''
out_format:
One of "png", "base64", "html_image". If "png", raw PNG image data is
      returned (as bytes). If base64, the png data is base64-encoded (string),
      and if html_image, the returned string is ``<img src='data:X'/>`` where
      X is base64 image data (this string is ready to be used in a webpage).
'''      
sequenticon_batch(sequences, output_format='png', size=60, output_path=None)

sequenticon_batch_pdf(sequences, target=None, title="Sequenticons batch")

处理过程

  1. 获取序列
  2. 使用pydenticon包产生base64数据和图像
generator = pydenticon.Generator(SETTINGS["rows"], SETTINGS["columns"],
                                     foreground=SETTINGS["color_palette"])
img = generator.generate(sequence, size, size)
base_64 = base64.b64encode(img).decode()

数据转换&加密部分
实际是md5加密产生hash码,然后按照一定规则转为01矩阵,然后染色。查看:

你的路径\Lib\site-packages\pydenticon
你的路径\Lib\hashlib.py

如果找不到某些包的位置,可以在交互环境下先import 包名,然后直接输入包名,就会提示路径。(如果安装的时候失败了,会报错)

  1. 写出到图片/html/pdf
    写出到pdf看pdf_reports包。这个包仍然是该公司的,使用的是weasyprint包,这个包能将html转为pdf。

win10下安装weasyprint包可能报错

ImportError: [PDF Reports] ERROR: The Weasyprint library did not loadproperly! You will not be able to generate PDF reports untilyou fix this issue.

Maybe you haven't installed the Cairo dependency?

In any other case the weasyprint docs may be able to help:

http://weasyprint.readthedocs.io/en/stable/install.html#windows

The original import error was no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so': error 0x7e
cannot load library 'libcairo.2.dylib': error 0x7e
cannot load library 'libcairo-2.dll': error 0x7e

解决方案
其实是缺少GTK的包,这里我下载了
https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer
在这里插入图片描述
(国内速度慢的话使用工具)

安装完毕后重启电脑可以生效。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值