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

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
« Previous : 1 : ... 25 : 26 : 27 : 28 : 29 : 30 : 31 : 32 : 33 : ... 128 : Next »

블로그 이미지

gwLee's Study story

- gwlee



Site Stats

Total hits:
49952
Today:
18
Yesterday:
83