PIL을 이용한 이미지 삽입

import Image, matplotlib
from pylab import *

img = imread("image.png")
#imread는 gif는 안되는것 같습니다. png가 문안하게 잘 작동합니다.
fig = plt.figure(figsize=(11.69, 8.27))
# 11.69, 8.27은 A4를 인치로 표현한 것입니다. 가로가 넓은 Format입니다.
fig.figimage(img,xo=30,yo=520)
# 기준은 좌측 하단으로 좌측 하단이 0,0이 됩니다.





크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by gwlee

2010/07/15 00:00 2010/07/15 00:00
, , , ,
Response
0 Trackbacks , 0 Comments
RSS :
http://thegreatgoodplace.com/tt/study/rss/response/345

Trackback URL : http://thegreatgoodplace.com/tt/study/trackback/345

Leave a comment

AB1 파일 작업하기


출처: interactive-biosoftware

Python이 설치된 폴더의 Lib 폴더안에 ABIFReader.py
복사하여 넣어주고 사용하면 됨.

from ABIFReader import *
# creates an instance of ABIFReader
reader = ABIFReader(<filename>)
# version of ABIF file
reader.version
# print all entries of ABIF file "<name> (<num>) / <type> (<size>)"
reader.showEntries()
# read data for entry named <name> with number <num>, by default <num> is 1
data = reader.getData(<name>[, <num>])
# close the file, since it is kept open
reader.close()

본 파일을 이용하여 ABI3730xl에서 나온 ab1파일을 분석하는 경우 중간중간
몇몇 data type은 3500xl 버전을 참고해야되는 경우가 있었음.
ABIF Type의 Description이 잘 맞지 않은 것인지 AB1파일을 로드할때 중간에 missing되는 것이 있는지 정확히는 모르겠음.


ABIFReader.py

ABI파일 일게 해주는 파이썬 코드

ABIF_File_Format.pdf

AB1 raw 파일 구조 설명

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by gwlee

2010/06/06 00:23 2010/06/06 00:23
, , , , , , ,
Response
0 Trackbacks , 1 Comments
RSS :
http://thegreatgoodplace.com/tt/study/rss/response/316

Trackback URL : http://thegreatgoodplace.com/tt/study/trackback/316

Comments List

  1. 한성 2010/08/27 13:33 # M/D Reply Permalink

    유용하게 쓰겠습니다.

Leave a comment

Python-Twitter

역시.. 세상엔 별개 다 있는듯....
python을 이용해서 twitter를 하다니... ㅋㅋ

python-twitter 프로젝트 사이트

easy_install을 이용해서 사이트에 설명되어 있는데로
simplejson을 먼저 설치하고 python-twitter을 설치하니
잘 작동하네요.. ㅎㅎ

import twitter
api = twitter.Api(username='username', passowrd='password')
users = api.GetFriends() #함수 이름과 같이 친구들 목록 반환..
print [u.name for u in users]
status = api.PostUpdate('python-twitter test!')


크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by gwlee

2010/06/01 20:34 2010/06/01 20:34
, ,
Response
0 Trackbacks , 0 Comments
RSS :
http://thegreatgoodplace.com/tt/study/rss/response/315

Trackback URL : http://thegreatgoodplace.com/tt/study/trackback/315

Leave a comment

특정 폴더 하위에 있는 파일 내용 긁어오기

import os,sys
from os.path import join

search_dirs = sys.argv[1]

for root,dirs, files in os.walk(search_dirs):
        for file in files:
                if file[-3:].find('seq') != -1 or file[-3:].find('txt') != -1:
                        print '>'+file.split('.')[0]
                        for x in open(root+'/'+file):
                                if x.find('>') != -1:
                                        pass
                                else:
                                        print x,
                        print



지금 이녀석의 경우 파일 확장자가 seq나 txt로 끝나는 파일만
인식을 하고 그냥 긁어오는 겁니다.
-물론 그냥 shell로 할 수 있습니다. ^^

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by gwlee

2010/04/29 10:31 2010/04/29 10:31
,
Response
0 Trackbacks , 0 Comments
RSS :
http://thegreatgoodplace.com/tt/study/rss/response/300

Trackback URL : http://thegreatgoodplace.com/tt/study/trackback/300

Leave a comment

gene to fasta Blast result version

이번 스크립트는 중간에 gene list 파일을 만들 필요 없는 스크립트.
-중복이 되는 유전자가 있으면 제거하고 중복되지 않게 유전자 서열 저장

import glob,sys
from Bio import SeqIO

blast_result_file = sys.argv[1]
db_fasta_file = sys.argv[2]
output_file = sys.argv[3]

lists = []
for x in open(blast_result_file):
        lists.append((x.split('\t')[1]).strip())

if len(lists) > 1:
        lists.sort()
        last = lists[-1]
        for i in range(len(lists)-2,-1,-1):
                if last == lists[i]:
                        del lists[i]
                else:
                        last=lists[i]


db = SeqIO.parse(open(db_fasta_file), format='fasta')

ow = open(output+'.txt','w')

for rec in db:
        name = rec.description
        seq = rec.seq.tostring()

        for x in lists:
                if name.strip() == x.strip() or (name.strip()).find(x.strip()) != -1:
                        if name[:1] == '>':
                                ow.write(name+'\n'+seq+'\n')
                        else:
                                ow.write('>'+name+'\n'+seq+'\n')

ow.close()


사용법은 지난번 스크립트와 동일
ex) this.py blast_output_file db_file output_file

blast_output_file의 형식은 blast돌릴때 -m 8 형식입니다.
db_file은 fasta 형식이면 됩니다. 물론 blast_output_file에 gene 이름이 있어야
db_file에서도 찾아주겠죠..

ex) Blast프로그램 query db -m 8 -o blast_output_file
여기서 나온 blast_output_file에서 두번째 컬럼의 gene 이름으로 db_file에서
서열을 추출하는 방식입니다.
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by gwlee

2009/05/22 11:48 2009/05/22 11:48
, , ,
Response
0 Trackbacks , 0 Comments
RSS :
http://thegreatgoodplace.com/tt/study/rss/response/146

Trackback URL : http://thegreatgoodplace.com/tt/study/trackback/146

Leave a comment

유전자 리스트에서 서열 저장

Blast 수행 이후 필요한 유전자의 서열들을 확보하는 스크립트

유전자 리스트(검색하는 DB 파일의 유전자 리스트로부터 유래된) 파일과
검색하고자 하는 db 파일 그리고 유전자 이름과 서열을 FASTA 형식으로
저장하는 파일 이름 필요
저장 파일의 확장자는 항상 ".txt"가 붙음
결과로 나오는 저장파일의 유전자 서열들에 대해서는 중복으로 존재 가능합니다.

import glob,sys
from Bio import SeqIO

list_file = sys.argv[1]
db_file = sys.argv[2]
output_file = sys.argv[3]

lists = []
for x in open(list_file):
        lists.append(x.strip())

db = SeqIO.parse(open(db_file), format='fasta')

ow = open(output+'.txt','w')

for rec in db:
        name = rec.description
        seq = rec.seq.tostring()

       
for x in lists:
                if name.strip() == x.strip() or (name.strip()).find(x.strip()) != -1:
                        if name[:1] == '>':
                                ow.write(name+'\n'+seq+'\n')
                        else:
                                ow.write('>'+name+'\n'+seq+'\n')
   
ow.close()


사용 예
[test]$ python this.py gene_list_file db_file output_file_name

-빨간색으로 강조된 부분은 필요에 따라 수정 할것.

-파이썬 파일을 실행하는 경우 각 파일들이 실행되어지는
 폴더에 있지 아니한 경우 절대 경로를 지정해줘야 잘 작동할께요.. 아마도..
 
약간의 응용을 하면 input file을 blast 결과파일로도 할 수 있음 (단, output format -m 8로 했을 경우)

input_file인 gene_list_file의 format

gene_list_file 보기


db_file의 경우 일반 fasta format이면 사용 가능


ex) Blast프로그램 query db -m 8 -o blast_output_file
여기서 나온 blast_output_file에서 두번째 컬럼의 gene 이름으로 db_file에서
서열을 추출하는 방식입니다.



gene_list에서 중복으로 나오는 유전자 서열이 있을경우

중복 서열 제거 스크립트


 

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by gwlee

2009/05/13 14:34 2009/05/13 14:34
,
Response
0 Trackbacks , 0 Comments
RSS :
http://thegreatgoodplace.com/tt/study/rss/response/133

Trackback URL : http://thegreatgoodplace.com/tt/study/trackback/133

Leave a comment

Fasta 형식의 파일에서 빈서열 제거

가끔씩 Blast를 수행하고자 formatdb를 수행 할 때,
다음과 같은 에러를 접한 적이 있으리라 본다.

[formatdb] WARNING: Cannot add sequence number XXXXX XX.XXX.XXX.
 because it has zero-length.

[formatdb] FATAL ERROR: Fatal error when adding sequence to BLAST database.


formatdb를 수행하려는 fasta 서열에
빈 서열을 가지고 있기 때문에 나오는 에러로
빈 서열을 제거하면 OK!

vi check.py

import glob,sys
from Bio import SeqIO

file = sys.argv[1]

ow = open(file.split('.')[0]+'.check','w')
seqs = SeqIO.parse(open(file), format='fasta')
 for rec in seqs:
        name = rec.description
        seq = rec.seq.tostring()

        if len(seq.strip()) != 0:
                ow.write('>'+name+'\n')
                ow.write(seq+'\n')

ow.close()



[test]$python check.py test.fasta

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by gwlee

2009/05/08 19:30 2009/05/08 19:30
, , ,
Response
0 Trackbacks , 0 Comments
RSS :
http://thegreatgoodplace.com/tt/study/rss/response/128

Trackback URL : http://thegreatgoodplace.com/tt/study/trackback/128

Leave a comment

대용량 파일을 위한 shelve


출처: 파이썬마을


파이썬에 이런 모듈이..
참.. 대단한듯...
-파이썬에 감탄하면 지는거다..
난 자바를 공부하고 있어야돼... ㅠ.ㅠ

쉽게말해 대용량 사전
-사전이라는 자료형 은근히 편했는데..


실제 사용 예로 EMBL CDS fasta파일을 읽어서 E. coli에서 나온 것만 골라서
뽑아주는 소스는 이렇게 만들 수 있습니다.

코드:

from Bio import SeqIO
import shelve

seqs = SeqIO.parse(open('/data/embl/cds_nr.fasta'), format='fasta')
db = shelve.open('ecoli.db')

for rec in seqs:
    if ('Escherichia coli' in rec.description and
        'hypothetical' not in rec.description):
            name = rec.description.split()[0].split(':')[1]
            seq = rec.seq.tostring()
            db[name] = seq


나중에 EMBL ID로 검색할 때는 다음과 같이 open만 하면 검색할 수 있습니다.

코드:

import shelve
db = shelve.open('ecoli.db')
genes = ['100746833', '1008171518']
for gene in genes:
    print db[gene]



32G가 30여분 소요 됐다니.. 난 4.1G(nr, 한국시간 2009.3.5에 다운로드) 밖에 안돼네.. ㅋㅋ

5분이면 끝나야 하는거 아니야..;;
왜 안끝나..;;
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by gwlee

2009/03/05 20:42 2009/03/05 20:42
,
Response
0 Trackbacks , 0 Comments
RSS :
http://thegreatgoodplace.com/tt/study/rss/response/79

Trackback URL : http://thegreatgoodplace.com/tt/study/trackback/79

Leave a comment

리스트에서 중복된 원소 삭제

if len(list) > 1:
  list.sort()

  last = list[-1]

  for i in range(len(list)-2,-1,-1):
    if last == list[i]:
      del list[i]
    else:
      last=list[i]


리스트에 존재하는 중복되는 항목을 삭제


Python Grimoire 중에서...


Comment 달린것입니다.
tempDic = {}
   if len( list ) > 1:
      list.sort() for i in list:
         tempDic[i] = ''
         print tempDic.keys()
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by gwlee

2008/08/25 02:32 2008/08/25 02:32
Response
0 Trackbacks , 0 Comments
RSS :
http://thegreatgoodplace.com/tt/study/rss/response/41

Trackback URL : http://thegreatgoodplace.com/tt/study/trackback/41

Leave a comment

Win32com Python


파이썬에서 좀더 다양한 윈도우 프로그래밍이 가능하게 하는 모듈?
여하튼.... 좋은거~ ㅋ

Win32com

다양한 윈도우 프로그램과 연동되어
프로그래밍을 더 시키게 만든 녀석.. ㅡ.-a

여하튼.... python 2.3이후부터는 없는줄 알았는데..
역시 sourceForge에는 있었다는...;;;

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by gwlee

2008/08/25 01:33 2008/08/25 01:33
,
Response
0 Trackbacks , 0 Comments
RSS :
http://thegreatgoodplace.com/tt/study/rss/response/19

Trackback URL : http://thegreatgoodplace.com/tt/study/trackback/19

Leave a comment

블로그 이미지

Stay Hungry Stary Foolish!

- gwlee

TC-Cumulus by reznoa requires Flash Player 9 or better.

Site Stats

Total hits:
62336
Today:
17
Yesterday:
65