python 画基因图
Python是当下非常流行的编程语言之一,而在生物信息学领域,python也大有用途。例如,我们可使用python来画基因图。
# 导入需要使用的库 from reportlab.lib import colors from reportlab.lib.units import cm from Bio.Graphics import GenomeDiagram from Bio import SeqIO # 读取序列数据 record = SeqIO.read("NC_000964.gbk", "genbank") # 创建基因图对象 gd_diagram = GenomeDiagram.Diagram("Escherichia coli str. K⑴2 substr. MG1655") # 添加一个轴线 gd_track_for_features = gd_diagram.new_track(1, name="Annotated Features") gd_feature_set = gd_track_for_features.new_set() # 遍历特点 for feature in record.features: if feature.type != "gene": # 只绘制基因特点 continue # 绘制基因的外围 color = colors.blue start, end = feature.location.start, feature.location.end gene_feature = gd_feature_set.add_feature(feature, sigil="ARROW", color=color, label=True, label_size=14, label_angle=0) # 绘制内部注释 for site, name, color in [("TSS", "green", colors.green), ("promoter", "blue", colors.blue), ("RBS", "purple", colors.purple), ("CDS", "orange", colors.orange)]: if site in feature.qualifiers: site_feature = SeqFeature(FeatureLocation(feature.qualifiers[site][0]-start, feature.qualifiers[site][0]-start+1), strand=feature.strand) gd_feature_set.add_feature(site_feature, sigil="OCTO", color=color, label=True, label_size=10, label_color=color, label_angle=0) # 设置图象参数并生成输出 gd_diagram.draw(format="circular", circular=True, pagesize=(20*cm,20*cm), start=0, end=len(record), circle_core=0.5) gd_diagram.write("ecoli_gene_map.pdf", "PDF")
上述代码可以用于读取NCBI数据库中的Escherichia coli str. K⑴2 substr. MG1655基因序列并画出基因图,其中利用了reportlab和Bio库中的一些函数和类来绘图。使用python画基因图可让我们更好地了解基因结构和功能,有助于进一步的生物信息学研究和分析。
文章来源:丸子建站
文章标题:python 画基因图
https://www.wanzijz.com/view/58116.html