python: find repeat masked intervals in fasta files

通常fasta文件用N来表示重复序列(用小写的atgc也很常见),下面的代码就是找出fasta文件中用N标记的区域。

首先导入biopython包,然后用SeqIO.to_dict()函数把fasta文件的记录转换成python字典。

然后用firstN标记是否在连续的N字符中间,如果不在,则firstN == True, 否则False。其他的不言自明啦。

其中用到了python两个很方便的函数:

一是字典的items()函数: for key,value in dict.items(),返回由dict的键值对组成的list;

一是list的enumerate()函数: for index, element in enumerate(list),枚举出list元素的下标和元素本身。

输出的是 chromosome_id Nstart Nend (下标从1开始,包括起点和终点)

以下是代码:

from Bio import SeqIO

fastafile = 'tair8.at.chromosomes.fas.masked'

chrD = SeqIO.to_dict(SeqIO.parse(open(fastafile),'fasta'))

for chrid,sequence in chrD.items():
    firstN = True
    for i,x in enumerate(sequence.seq.tostring()):
        if x == 'N':
            if firstN:
                start = i+1
                firstN = False
        elif not firstN:
            end = i
            firstN = True
            print chrid,start,end

可以很容易的修改上述代码,用来寻找小写字母区域:

from Bio import SeqIO

fastafile = 't.fa'

chrD = SeqIO.to_dict(SeqIO.parse(open(fastafile),'fasta'))

for chrid,sequence in chrD.items():
    firstLower = True
    for i,x in enumerate(sequence.seq.tostring()):
        if x.islower():
            if firstLower:
                start = i+1
                firstLower = False
        elif not firstLower:
            end = i
            firstLower = True
            print chrid,start,end

输入文件

今天吃的通心粉

pastagfw

七月第一篇 ^^

Dropbox–不仅仅是2G免费网络硬盘

dropbox_logo_home

Dropbox提供免费的2G在线存储空间,而且支持文件同步和分享。网上介绍Dropbox的文章很多啦,所以我就不多说了。不过以下的优点还是要大赞的:

1. 支持多台电脑的同步,并支持Windows, Mac, Linux等几乎所有操作系统。于是再也不用整天拿着U盘在台式机和本本之间来回拷东西了。

2. 映射到本地文件夹,只需要把想同步的文件拖到此文件夹就自动上传和同步,告别Upload按钮。当然你非要在网页上Upload,也没问题!

3. 方便分享,只需要把文件放到Public子文件夹,比如我分享的几本书:

How to Think Like a Computer Scientist — Learning with Python 很适合作为第一本编程书。

The Music of Life — Biology Beyond the Genome 用系统生物学观点看什么是生命。

4. 界面清爽,操作简便,远离广告困扰。

5. 高级使用技巧,如BT下载,同步浏览器收藏夹。

我辛辛苦苦罗嗦这半天,亲爱滴读者你就去注册一个吧,请用下面这个链接注册

https://www.getdropbox.com/referrals/NTMwODA1ODk

会在原本的2G免费空间再加上250M哦,当然我的免费空间也会增加这么多。:)

最后小声说下,如果你是Ubuntu9.04 64bit系统,下载安装deb包后Dropbox deamon没自动运行,解决方法:

终端输入: dropbox start -i

Ubuntu9.04安装ibus输入法

看到很多人推荐 ibus,于是决定在刚装好的Ubuntu9.04里试一下:

1. 在/etc/apt/sources.list文件里添加源:
deb http://ppa.launchpad.net/ibus-dev/ppa/ubuntu jaunty main

2. sudo apt-get update

3. sudo apt-get install ibus ibus-pinyin

如果需要五笔输入法,则加上 ibus-table ibus-table-wubi

4. im-switch -s ibus

5. 重新登录

6. Panel上应该出现ibus图标,右键Preferences->Input Methods -> Select an input method -> Add

7. Ctrl+Space激活

如果能启动ibus,但不能激活输入法:
编辑/usr/lib/gtk-2.0/2.10.0/immodule-files.d/libgtk2.0-0.immodules
在文件最后添加两行:
“/usr/lib/gtk-2.0/2.10.0/immodules/im-ibus.so”
“ibus” “X Input Method” “gtk20″ “/usr/share/locale” “zh”
重新登录

参考:

http://code.google.com/p/ibus/wiki/Ubuntu

http://forum.ubuntu.org.cn/viewtopic.php?p=915368

昨天的骑车路线–PA45

昨天和pala出去,随便骑骑,发现一条不错的骑车路线,尤其是PA45,无敌飙车路!车少风景好下坡多(如果走对方向。。),特此推荐!

几张pic在此,下面上地图:


View State College south - PA 45 loop in a larger map

翻页: 往前翻 1 2 3 ...5 6 7 ...83 84 85 往后翻