最近了解到的生物信息学技术.

前段时间写了个脚本抓取基因数据,在这里记录下用到的资源.

KEGG:

Kyoto Encyclopedia of Genes and Genomes

KEGG 是一个生物基因和基因组数据库。由GenomeNet网站(目前由京都大学生物信息学研究中心系维护) 继续维护和提供分析服务.

KEGG 有一点非常好,就是提供了KEGG API。方便研究人员自己写脚本定制数据. PS. KEGG提供了SOAP/REST两种方式.

TogoWS

Intergration of the bioinfomatics web services

由于我前面探索的时候走过了一些弯路,需要用到比较复杂的关系查询. 所以找到了 TogoWS 。

它集合了大部分的生物信息中心的数据包括 NCBIEBIDDBJKEGGPDBj, and CBRC提供了统一的查询接口(API). 使用起来很方便。提供了 SOAP/REST 两种调用方式. 还能返回多种数据格式

 

以下分别是由perl, python, ruby 编写的生物信息学编程工具库. 详细的资料请到官方网站了解.

BioPerl

BioPerl is a toolkit of perl modules useful in building bioinformatics solutions in Perl.

BioPython

Biopython is a set of freely available tools for biological computation written in Python by an international team of developers。

这个库的KEGG模块还很不完善,没有API, 没有KEGG数据格式的分析.

BioRuby

Open source bioinformatics library for Ruby。

vim 配置

 

"background color
:colorscheme desert
"show line counter
:set nu!
"hight light
syntax on
set shiftwidth=4
set autoindent
" every tab switch to 4 space
set softtabstop=4
" change tab to space
set expandtab
" 根据文件类型进行缩进
filetype plugin indent on
" 
set nocompatible

set guifont=Monaco\ 10

set hlsearch

""""""""""""""""""""""""""""""
" NERDTree插件的快捷键
""""""""""""""""""""""""""""""
nmap <silent> <leader>nt :NERDTree<cr>
nmap <silent> <leader>nc :NERDTreeClose<cr>

" 在输入命令时列出匹配项
set wildmenu

" 分割窗口时保持等宽高
set equalalways

" 取消自动备份
set nobackup
" 保存关闭文件之前保留一个备份
set writebackup

" 察看其它编码格式的文件或者解决乱码问题
set encoding=utf-8 fileencodings=ucs-bom,utf-8,cp936

""""""""""""""""""""""""""""""
" bufExplorer插件的设置
""""""""""""""""""""""""""""""
let g:bufExplorerSortBy='mru'
let g:bufExplorerSplitRight=0
let g:bufExplorerSplitVertical=1
let g:bufExplorerSplitVertSize=20 
let g:bufExplorerUseCurrentWindow=1 
autocmd BufWinEnter \[Buf\ List\] setl nonumber

wos2 WSF/PHP soap header 认证实现

用SwA模式上传附件, 下载的包里有相关实例。但是看产生的soap消息包不是SwA模式的, 依然是MTOM模式的.

 

$uri = "http://wsi.portalservice.dpf.huawei.com";
$key = "asdf";
$pwd = "asdf";
$time = date("mdhms");
$pwd = base64_encode(hash("SHA256",$key.$pwd.$time));

$url = "http://127.0.0.1:1234/Service";
$reqPayload = <<<XML
<ns1:AddRequest xmlns:ns1="http://localhost/namespace">
<albumId>1106011156080031</albumId>
<fileName>
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:content"></xop:Include>
</fileName>
</ns1:AddRequest>
XML;

$auth_data = array(
	new WSHeader(array('name'=>'operatorId','data'=>$key)),
	new WSHeader(array('name'=>'password','data'=>$pwd)),
	new WSHeader(array('name'=>'timeStamp','data'=>$time)),
);

$header_options = array(
	"ns"=>$uri,
	'prefix'=>"ns1",
	"name"=>"RequestSOAPHeader",
	"data"=>$auth_data,
);
$header = new WSHeader($header_options);

$filePath = "/path/to/file/file.jpg";
$f = file_get_contents($filePath);

$msg = new WSMessage($reqPayload,
	array(
		'inputHeaders'=>array($header),
		'attachments'=>array('content'=>$f),
		'defaultAttachmentContentType'=>"image/jpeg",
	)
);
$options = array(
	'to'=>$url,
	'useMTOM'=>"swa",
);
$api = new WSClient($options);

try {
	$resMsg = $api->request($msg);
} catch (Exception $e) {
	if ($e instanceof WSFault)
		printf("Soap Fault: %s\n", $e->Reason);
	else
		printf("Message = %s\n", $e->getMessage());
}

 

PHP: Soap 通过 soap header 认证(non-wsdl 模式)

 

soap service 是 java的 axis2

soap client 是 php. = =

                 $url = "http://localhost:8000/PortalService";
                // 对应wsdl 文件定义中的targetNamespace
		$uri = "http://localhost/partalService";

		$key = "xxx";
		$pwd = "xxx";

		$options=array(
			//'soap_version'=>SOAP_1_2,
			'trace'=>1,
			//"exceptions"=>1,
			'location'=>$url,
			'uri'=>$uri,
		);

		$auth_header = array(
			'user'=>$key,
			'password'=>$pwd,
		);
                // 下面的RequestSOAPHeader 对应 wsdl 定义里面的 <xsd:element name="RequestSOAPHeader">.....
		$authvalues = new SoapVar($auth_header, SOAP_ENC_OBJECT,"RequestSOAPHeader",$uri);  
		$header = new SoapHeader($uri, 'RequestSOAPHeader', $authvalues);

		$api = new SoapClient(null,$options);
		$api->__setSoapHeaders(array($header));
		
                // 在调用 java axis2 soap 的使用要这么定义, 不然会变成 <param0><item>xxx</item><value>xxx</value></param0>
                // 所以会报错. 用一下定义生成的就是这样的格式: <user>asdf</user>
		$p = array(
			new SoapParam("asdf",'user'),
			new SoapParam(1,'password'),
		);
		try {
			$call="Login";
			$result = $api->__soapCall($call,$p);
			print_r($result);
		} catch(SoapFault $e) {
			if(1) {
				var_dump($api->__getLastRequestHeaders());
				var_dump($api->__getLastRequest());
				var_dump($api->__getLastResponseHeaders());
				var_dump($api->__getLastResponse());
				echo $e->getMessage();
			}
		}

 

triple_des(des3) 算法 - php,python 实现

调用电信那边的接口. 要用到 triple_des 加密算法. 整了python 和 php 两个版本的实现.

iv, key 变量指向的都是 hex 字符串.

php:

 

#!/usr/bin/php
<?php

function PaddingPKCS7($data) {
	$block_size = mcrypt_get_block_size("tripledes", "cbc");
	$padding_char = $block_size - (strlen($data) % $block_size);
	$data .= str_repeat(chr($padding_char),$padding_char);
	return $data;
}

function fmt3DESEx($data, $key, $iv) {
	$td = mcrypt_module_open(MCRYPT_3DES,"", MCRYPT_MODE_CBC, "");
	$key = pack("H48",$key);
	$iv = pack("H16",$iv);
	mcrypt_generic_init($td, $key, $iv);
	$data = PaddingPKCS7($data);
	$desResult = mcrypt_generic($td, $data);
	mcrypt_generic_deinit($td);
	mcrypt_module_close($td);
	return base64_encode($desResult);     
}



$data = "asdf";
$key = "313233343536373839303132333435363738393031323334";
$iv = "3132333435363738";
$code = fmt3DESEx(mhash(MHASH_SHA1,$data), $key, $iv);
echo $code;
?>

python:

 

#!/usr/bin/env python
# -*- coding:utf-8 -*-

import binascii
import hashlib
import base64
import pyDes

iv = '3132333435363738'
key = '313233343536373839303132333435363738393031323334'
data = "asdf"

iv = binascii.unhexlify(iv)
key = binascii.unhexlify(key)
data = hashlib.sha1(data)

k = pyDes.triple_des(key, pyDes.CBC, iv, pad=None, padmode=pyDes.PAD_PKCS5)
d = k.encrypt(data.digest())
print base64.encodestring(d)

 

python 拖拉桌面小程序. :)

descript: 拖拉两个xls文件到此小程序中, 自动进行比对并输出比对结果(xls)

 

# -*- coding: utf-8 -*-

# Import wx.Python
import wx
import xlrd,xlwt
import os.path

# Declare GUI Constants
DRAG_SOURCE    = wx.NewId()

#=====================================
def encoding(s,coding=None):
    cl = ['utf8', 'gb2312','gb18030']
    if coding:
        cl.append(coding)
    for a in cl:
        try:
            s.decode(a)
            return a
        except UnicodeEncodeError:
            pass
    return 'unknown'

def toUnicode(s,coding=None):
    if isinstance(s,unicode):
        return s
    return s.decode(encoding(s,coding))
#=================================================

# Define File Drop Target class
class FileDropTarget(wx.FileDropTarget):
    """ This object implements Drop Target functionality for Files """
    def __init__(self, obj):
        """ Initialize the Drop Target, passing in the Object Reference to
          indicate what should receive the dropped files """
        # Initialize the wxFileDropTarget Object
        wx.FileDropTarget.__init__(self)
        # Store the Object Reference for dropped files
        self.obj = obj
        self._initContent()

    def _initContent(self):
        self.content = {'same':[],'diff':[]}

    def _log(self,string):
        self.obj.WriteText(toUnicode(string))

    def _analyze(self,xls={}):

        def combine_rows(sheet):
            rows = []
            for rownum in range(sheet.nrows):
                rows.append("-".join([toUnicode(str(row) if isinstance(row,float) else row) \
                        for row in sheet.row_values(rownum)]))
            return rows

        #FIXME optime
        name = xls.keys()
        self._log(u"正在比对 "+name[0]+u" , "+name[1]+u" 中...... \n")
        rows = []
        for sheet in xls.values():
            rows.append(combine_rows(sheet))
        same_rows = list(set(rows[0]) & set(rows[1]))
        file1_rows = list(set(rows[0]) - set(rows[1]))
        file2_rows = list(set(rows[1]) - set(rows[0]))
        self.content['same'].extend(same_rows)
        self.content['diff'].extend(\
                [{'name':name[0],'rows':file1_rows},
                {'name':name[1],'rows':file2_rows}])
        self._log("比对完成 \n")
        return 1

    def _dumpToXls(self,path):
        self._log("生成比对结果中...... \n")
        xls = xlwt.Workbook()
        sheet_same = xls.add_sheet(u'相同数据',cell_overwrite_ok=True)
        same_rows = self.content['same']
        def write_rows(sheet,rows):
            for r in range(len(rows)):
                cells = rows[r].split('-')
                for c in range(len(cells)):
                    sheet.write(r,c,cells[c])
        write_rows(sheet_same,same_rows)

        sheet_diff = {}
        for diff in self.content['diff']:
            name = diff.get('name','default')
            rows = diff.get('rows',[])
            sheet_diff[name] = xls.add_sheet(name+u"独有",cell_overwrite_ok=True)
            write_rows(sheet_diff[name],rows)
        result = os.path.join(path,u" 和 ".join(sheet_diff.keys())+u'的比对结果.xls')
        xls.save(result)
        self._log(u"生成比对结果如下:\n%s\n" % (result,))
        self._initContent()

    def _compare(self,filenames):
        filenames = filenames if isinstance(filenames,list) else list(filenames)
        #for mutiple files
        xls={}
        try:
            for file in filenames:
                name = os.path.basename(file).split('.')[0]
                xls[name] = xlrd.open_workbook(file).sheets()[0]
        except xlrd.biffh.XLRDError,e:
            self._log("请载入xls格式文件")
            return False
        #filenames.sort(self._analyze)
        self._analyze(xls)
        self._dumpToXls(os.path.dirname(filenames[0]))

    def OnDropFiles(self, x, y, filenames):
        """ Implement File Drop """
        # For Demo purposes, this function appends a list of the files dropped at the end of the widget's text
        # Move Insertion Point to the end of the widget's text
        self.obj.SetInsertionPointEnd()
        # append a list of the file names dropped
        self._log("\n加载了 %d 个文件:\n" % (len(filenames)))
        if len(filenames) != 2:
            self._log("只能比对两个文件\n")
            return False
        self._compare(filenames)

class MainWindow(wx.Frame):
    """ This window displays the GUI Widgets. """
    def __init__(self,parent,id,title):
        #wx.Frame.__init__(self,parent,-4, title, size = (430,270), style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
        wx.Frame.__init__(self,parent,-4, title, size = (430,270), \
                style=wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN )
        self.SetBackgroundColour(wx.WHITE)

        wx.StaticText(self, -1, u"请将要比对的EXCEL文件拖拉进下面区域进行比对",(3,0))
        self.text = wx.TextCtrl(self, -1, "", pos=(2,15),size=(418,220), style = wx.TE_MULTILINE|wx.HSCROLL|wx.TE_READONLY)

        dt = FileDropTarget(self.text)
        self.text.SetDropTarget(dt)

        # Display the Window
        self.Show(True)

    def CloseWindow(self, event):
        """ Close the Window """
        self.Close()

    def OnDragInit(self, event):
        """ Begin a Drag Operation """
        # Create a Text Data Object, which holds the text that is to be dragged
        tdo = wx.PyTextDataObject(self.text.GetStringSelection())
        # Create a Drop Source Object, which enables the Drag operation
        tds = wx.DropSource(self.text)
        # Associate the Data to be dragged with the Drop Source Object
        tds.SetData(tdo)
        # Intiate the Drag Operation
        tds.DoDragDrop(True)

class MyApp(wx.App):
    """ Define the Drag and Drop Example Application """
    def OnInit(self):
        """ Initialize the Application """
        # Declare the Main Application Window
        frame = MainWindow(None, -1, u"Excel文件比对小程序")
        # Show the Application as the top window
        self.SetTopWindow(frame)
        return True

# Declare the Application and start the Main Loop
app = MyApp(0)
app.MainLoop()

 

Python Web Site Process Bus v1.0 - 翻译

 Abstract

This document specifies a proposed standard interface between operating system events and web components (including web servers, web applications, and frameworks), to promote web component interoperability and portability.
 
摘要
这个文档指定了一个被提倡的标准接口,介于系统事件和web组件(例如web服务器,web应用程序,和框架).该接口促进网络组件之间的互操作性和可移植性.
 
Rationale and Goals
The Python community has produced many useful web application frameworks, including Django, Pylons, Turbogears, Zope, CherryPy, Paste, and many more [1]. Recently, many of these frameworks have attempted to decentralize their architectures and become more component-based, specifically using the WSGI specification [2] to decouple servers from applications, and even framework components from each other.
 
意向和目标
Python社区已经产出了许多很有用的web应用框架,例如 Django, Pylons, Turbogears, Zope, CherrPy, Paste等等.最近,许多这些框架已经试图使它们的结构分散化,从而变得更基于组件(组件化).特别使用WSGI规范去使"服务"从程序脱离,甚至是框架组件之间的脱离.
 
In general, however, each of these frameworks' and servers' natural assumption is that it alone must be in control of the OS process, generating and responding to process-wide events: startup, shutdown, and restart. As various people have tried to combine components from multiple frameworks, they generally select one framework or server as the primary process controller, and then write ad-hoc adapters to translate the startup/shutdown style of foreign components into the style of the primary controller. In many cases, this adaptation has simply not been possible when frameworks or servers are too tightly coupled to process-wide events; for example, when two frameworks register signal handlers for the same process.
 
但是一般来说, 这些框架和服务原本(自然)假设是必须由一个单独的系统进程来控制.产生和响应进程事件:启动,关闭和重启.当一些人已经尝试将不同框架的一些组件进行组合时, 他们一般都会选择一个框架或者服务作为主进程控制器.然后,编写特设的适配器将外来组件风格的启动/关闭事件翻译转换成主控制器的风格.很多情况下, 这个适配器

搭建 vsftpd 服务(虚拟用户)

环境

Linux localhost.localdomain 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
 

准备

要使用到以下软件包
db4-4.3.29-10.el5 (默认安装)

db4-devel-4.3.29-10.el5 (默认安装)

vsftpd-2.0.5-16.el5 (默认安装)

db4-utils-4.3.29-10.el5 (需要下载)
 
我们需要db4-utils 来生成数据库文件,安装db4-utils, 执行如下指令
rpm -ivh db4-utils-4.3.29-10.el5.x86_64.rpm
 
 

archlinux TL-WN322G+(2.0) usb无线网卡安装

详情看ubuntu-cn论坛的帖子.这里摘录下

首先安装 : NDISwrapper (点击进去看arch wiki 的解释).

下面 Wikipedia 的解释摘录:

NDISwrapper works by implementing the Windows kernel and NDIS APIs, and dynamically linking the driver to this implementation.

sudo pacman -S  ndiswrapper ndiswrapper-utils

在TP-Link 的驱动盘里面着到TL-WN322G+的驱动...里面有分 xp , vista, windows 7 几个目录。

我的机子是32 位的。所以复制32位的驱动。

取出xp目录下的 athuw.sys 将其文件名改成于 vista 目录下 .sys 文件相同的名字:

mv athuw.sys athur.sys

再将vista驱动目录下的 netathur.inf 与 athur.sys 复制到同一路径下.

执行以下命令安装驱动(详情看 arch wiki):

# 安装驱动
sudo ndiswrapper -i netathur.inf
#查看已经安装了的驱动
ndiswrapper -l
# 如出没有出现类似于如下信息的话,就说明驱动安装成功了.
#netathur : driver installed

# -m               write configuration for modprobe
sudo ndiswrapper -m

#重新加载所有内核模块
depmod -a

#最后手动加载驱动程序的内核模块
modprobe ndiswrapper

#查看是否是否识别到网卡
iwconfig
 

ok. 顺利执行完的话就应该能顺利的看到usb无线网卡的等亮了...而且能连接上网喽!

学习视觉传递:生态学理论

 按顺序本来应该讲对“符号论”的初步印象的。但是,上次去了图书馆看第二章(讲历史,和对应时期的流派)的时候,实在看不下,偷溜去看图标设计了。于是找到了一幅自认为能比较好展现生态学理论的图片。所以就先说"生态学理论“。第三章就是说符号文字的哦!

 
看这个理论的时候我记录的东西竟然只有”一句半话“。不过有实例就是比较有感觉(先不管感觉对否,说出自己理解再说。看来我有必要去视觉传递的一些论坛逛逛...学习视觉传递:生态学理论 - tlhl28 - { Like a Android }):
 
光,环境,行为。尺度和光。

呃.....现在回想起来..忘了差不多了....貌似还有好些点没记录...偷懒的结果....其中有一点是说光的渐变(颜色,强度), 对我们的视觉有些啥影响来着,回头补上吧. 说我脑子里剩下的东西好了。

在我现在理解看来。生态学理论,更多关注一个场景(更抽象的说是三维空间上的)所传递给我的信息, 在我认为是更多的关注与这个场景空里的事物,人或者物体,其他的都是承载或者衬托。光和尺度是非常重要的两个元素。光的强弱,变化 和 事物的比例,长度,宽度,大小。有什么影响呢? 我还讲不清楚了,只是认识上有那么句话 :)....

好吧,直接上案例,澳大利亚旅游局的宣传画册之类的东西..抱歉忘记了,我觉得很好的表现出了上面记录到的 "光,环境,行为"。 

请看从左到右或者从下到上的顺序,第一,二,三个手指指向的图。

首先,那是澳大利亚的落日,这个时候(傍晚)的让人感到很舒适安逸,很温和。在最初的目光接触时已经产生好感。女的在干啥...实在是忘记了.当时没细看,细看了第二副图和第三幅图...

第二幅图呢,同样是落日的光,这种光实在令人觉得很舒服,很温和。该图标就是这样的落日和一只向上跳跃的袋鼠.

动作
简单来看,图中女人手中貌似拿着什么,蹲在地上望着远方.她这个动作 给我的感觉是: 这是片辽阔美丽的土地,蹲下来歇歇脚望望这片地方,幸福平静的面容. 这很容易让看图的人受到这个人物动作的影响,令人也会产生兴趣,和莫名的认同感。

第二副图我看了比较久, 一个应该是很有本土风格的老头,摸起这红土像在讲些什么。周边是一群孩子。你想到什么? 老人为孩子们讲着发生在这片红土上的故事,历史,神话。恩...这是个很有"故事---历史和文化"的国家.

环境
图一,女人所在的场景是
澳大利亚艾尔斯巨石(Ayers Rock),又名乌卢鲁巨石(Uluru Rock属澳大利亚土著人 ... 艾尔斯巨石俗称为我们“人类地球上的肚脐”,号称“世界七大奇景”之一(from baidu 百科)
旅游胜地啦.....有啥效果那是不用说的。