Posts
Biopython
GenomeDiagram
#
Find similar titles
- 최초 작성자
- 최근 업데이트
Structured data
- Category
- Software
GenomeDiagram #
바이오파이썬의 기능 중 하나는 유전체의 구조를 그림으로 그려주는 기능이 있다. 이를 위해서 Graphics 모듈이 필요하다. 바이오파이썬 중 Bio.Graphics는 파이썬의 3rd-party 모듈인 ReportLab을 이용하는데 이는 Postscript 및 SVG 파일을 만들어 낼 수 있다. 또한 벡터 이미지 사용을 위해 파이썬이 이미지 라이브러리인 PIL(python imaging library)을 이용한다. reportlab은 JPEG, PNG, GIF, BMP, PICT 포맷을 지원한다.
Bio.Graphics.GenomeDiagram 모듈은 이전 버전에서는 분리되어 사용되어지다가 1.50 버전에서 통합되었다. GenomeDiagram은 Digrams, Tracks, Feature-set 및 features를 표현할 수 있다
먼저 GenomeDiagram은 유전체의 전체 길이를 일정 비율로 나누어 선형이나 원형으로 표현해준다. 이는 여러 개의 tracks을 가질 수 있으며 각 track별로 유전자 구조 즉 CDS 정보 및 tRNA 정보를 표현할 수 있다.
이를 위해 두가지 모듈이 필요한데 reportlab 및 Bio.Graphics가 필요하다. 먼저 컬러 셋 및 Unit 단위 프로그램에 필요한 모듈이 reportlab에 있고 GenomeDiagram은 Bio.Graphics에 있다.
>>> from reportlab.lib import colors
>>> from reportlab.lib.units import cm
>>> from Bio.Graphics import GenomeDiagram
보통 GenomeDiagram은 genbank 파일로 잘 정리되어 있다. 전체 유전체 길이, 유전자 구조 및 다른 서브 구조의 위치 정보 및 서열 정보를 상세하게 포함하고 있기 때문에 이전에 다루었던 SeqIO를 가져와야 한다. 여기에서 주의할 점은 genomediagram은 하나의 유전체 이기 때문에 SeqIO.read()를 사용해야 한다. parse()를 이용하면 멀티로 처리하기 때문에 오류 및 원하지 않는 결과를 초래할 수 있다.
>>> from Bio import SeqIO
>>> record = SeqIO.read("NC_005816.gb", "genbank")
먼저 탑다운 방식에서는 비어 있는 Diagram, track 및 feature set를 만들어준다.
>>> gd_diagram = GenomeDiagram.Diagram("Yersinia pestis biovar Microtus plasmid pPCP1")
>>> gd_track_for_features = gd_diagram.new_track(1, name="Annotated Features")
>>> gd_feature_set = gd_track_for_features.new_set()
비어 있는 features(SeqRecord의 SeqFeature) 정보를 가져와서 사용한다. 여기에서는 각 feature의 구조를 짝수번에서는 블루 색상, 홀수번에서는 연한 블루 색상을 나타내도록 하는 예제이다.
>>> for feature in record.features:
... if feature.type != "gene":
... #Exclude this feature
... continue
... if len(gd_feature_set) % 2 == 0:
... color = colors.blue
... else:
... color = colors.lightblue
... gd_feature_set.add_feature(feature, color=color, label=True)
이제 구조가 만들어졌다. 그 후에 draw(format="포맷", orientation="방향정보", pagesize='사이즈',fragments=4, start=0, end=len(record))를 이용하면 된다. 아래의 예제는 선형 유전(체)를 그리는 예제이다.
>>> gd_diagram.draw(format="linear", orientation="landscape", pagesize='A4', fragments=4, start=0, end=len(record))
>>> gd_diagram.write("plasmid_linear.pdf", "PDF")
그림1. 선형 다이어그램
위에서 언급했듯이 PDF, EPS, SVG, PNG 등 파일 포맷으로의 저장을 지원하는데 각 예제는 다음과 같다.
>>> gd_diagram.write("plasmid_linear.eps", "EPS")
>>> gd_diagram.write("plasmid_linear.svg", "SVG")
>>> gd_diagram.write("plasmid_linear.png", "PNG")
아래 예제에서는 원형 다이어그램을 표현하는 예제이다.
>>> gd_diagram.draw(format="circular", circular=True, pagesize=(20*cm,20*cm), start=0, end=len(record), circle_core=0.7)
>>> gd_diagram.write("plasmid_circular.pdf", "PDF")
그림2. 원형 다이어그램
위에서 언급했던 기능을 하나의 파일로 만든다면 다음과 같이 만들 수 있다.
>>> from reportlab.lib import colors
>>> from reportlab.lib.units import cm
>>> from Bio.Graphics import GenomeDiagram
>>> from Bio import SeqIO
>>> record = SeqIO.read("NC_005816.gb", "genbank")
#Create the feature set and its feature objects,
>>> gd_feature_set = GenomeDiagram.FeatureSet()
>>> for feature in record.features:
... if feature.type != "gene":
... #Exclude this feature
... continue
... if len(gd_feature_set) % 2 == 0:
... color = colors.blue
... else:
... color = colors.lightblue
... gd_feature_set.add_feature(feature, color=color, label=True)
#(this for loop is the same as in the previous example)
#Create a track, and a diagram
>>> gd_track_for_features = GenomeDiagram.Track(name="Annotated Features")
>>> gd_diagram = GenomeDiagram.Diagram("Yersinia pestis biovar Microtus plasmid pPCP1")
#Now have to glue the bits together...
>>> gd_track_for_features.add_set(gd_feature_set)
>>> gd_diagram.add_track(gd_track_for_features, 1)
Suggested Pages #
- 0.025 염기서열
- 0.025 Maxam–Gilbert sequencing
- 0.025 아미노산
- 0.025 파이썬
- 0.025 GenBank
- 0.025 코돈
- 0.025 FASTA
- 0.025 DNA
- 0.025 시퀀싱장비
- 0.025 프리온
- More suggestions...
Other Posts #
- newer 생물정보동향2016-0701호
- older Kinship index