数据展示与Diagrams库 - TBY's Blog

数据展示与Diagrams库

TBY posted @ 2012年11月27日 20:39 in Haskell with tags Haskell Bioinformatics Data Visualization , 11001 阅读

因为做的是一些数据分析相关的工作,对数据展示格外感兴趣,所以一直在尝试寻找一些好用的低层矢量图形函数库。

尝试过各类数值软件、LaTex的tikz和pgfplots包等。高级的绘图API无疑用起来很方便,但相应的可定制性就较差。tikz和pgfplots是我之前最喜欢用的,不过坏在LaTeX不是个好用的数值软件。之前用Haskell的StringTemplate包写过一个绘制约3w多个点的tex文件,这时候直接用LaTeX编译会爆内存的(LuaLaTeX OK)。用tikz和pgfplots之类的宏包,最强的地方在于完美的数学字体,这方面我仍未发现不通过调用LaTeX能达到相应效果的库。传统的cairo无疑是个很棒的矢量图库,不过太底层,无法想象用裸API能够快速开发。

Haskell的diagrams库,也就是在这里要介绍的,是个很有Haskell风格(各种combinator)的矢量图形库,尝试了一番以后,我非常满意,考虑以后大部分图形函数都移到这库上来。优点主要有以下几点:

  1. 图是“拼”出来的,而不是传统的一笔一划“画”出来的。
  2. 后端很丰富,可以导出位图(bmp、png)、矢量(svg、ps、pdf)和tex文件(tikz后端)。
  3. 表现力很强,语言(DSL)本身很抽象,API设计的也很合理。
  4. diagrams-core令人惊讶地简洁。

这里就举几个生物上的例子。最近在弄一些microRNA靶基因预测方面的算法,一个预测的靶点好坏,其实可以很直观的看出来的:

  1. Seed Match的类型(miRNA 5'端的第2~7号碱基与靶的互补情况, 1 based)
  2. 3’端特定位置的氢键数量
  3. Seed序列周围的A或U碱基含量百分比
  4. 靶点的结合区在基因3'UTR区的相对位置。
  5. 一个比较promising的预测位点应该在不同物种中趋向于保守。

网上的数据库为了展示方便,往往只用文本来展示这类信息,非常不幸的是,如果你没有在浏览器中设置等宽字体,打开我给的那个链接时,你很难直观地看出这些信息。这里“对齐”和“颜色设置”对于良好地展示数据非常重要。

 

 

上面这两块svg便是用diagrams绘制的,代码其实很简单(主要琐碎在计算下标和颜色设置上),诀窍是在需要对齐的部分,把字符当块来处理对齐。

 

-- | 黑白字母
char ch = text [ch] <>
          rect w h # lcA transparent
-- | 彩色字母
charC c ch = text [ch] # fc c <>
             rect w h # lcA transparent

-- | 下面是相应的字串             
string = hcat . map char

stringC c = hcat . map (charC c)

想了解microRNA的可以看看下面的文献。另:TargetScan的预测算法在已知结合位置的情况下是相当简单的,大约只有半小时的编程量。

 

Most Mammalian mRNAs Are Conserved Targets of MicroRNAs 
Robin C Friedman, Kyle Kai-How Farh, Christopher B Burge, David P Bartel. Genome Research, 19:92-105 (2009).

HP +1 Model Paper 20 说:
2022年8月25日 18:01

HP Board 11th Class Important Model Question Paper 2023 PDF will be Published on the Official web Portal. Himachal Pradesh 11th Class Important Model Question Paper 2023 and Marking Schemes PDF are Given Below. Important Model Question Paper 2023 are Significant Study Materials in the Exam Preparation Process. HP +1 Model Paper 2023 Science, Geography, Sociology, Psychology, and Other Subjects Important Model Question Paper 2023 Details are Provided on This Page. for More Details About the Himachal Pradesh 11th Class Important Model Question Paper 2023 and Important Model Question Paper 2023 Kindly Visit the Official Website.

celebrity heights 说:
2023年6月15日 15:11

CG in films show us a new magical world. Have you ever wonder about the real heights of actors who play Hobbits in Lord of the Rings? You can find the answer on celeb height wiki with some clicks.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter
Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee