使用Biopython制作标注染色体

-1 投票
1 回答
510 浏览
提问于 2025-04-17 21:49

我正在尝试使用biopython重新创建带注释的染色体,具体可以参考这个链接:http://biopython.org/DIST/docs/tutorial/Tutorial.html#sec345。我有一段测试代码,可以创建一个染色体和一个注释特征(5, 10, "1", "Gm18_5133882_G_A", "blue")。

from reportlab.lib.units import cm
from Bio.Graphics import BasicChromosome
max_len = 150000 #Could compute this
telomere_length = 50000 #For illustration

chr_diagram = BasicChromosome.Organism()
chr_diagram.page_size = (29.7*cm, 21*cm) #A4 landscape
cur_chromosome = BasicChromosome.Chromosome(name)
#Set the scale to the MAXIMUM length plus the two telomeres in bp,
#want the same scale used on all five chromosomes so they can be
#compared to each other
cur_chromosome.scale_num = max_len + 2 * telomere_length

#Add an opening telomere
start = BasicChromosome.TelomereSegment()
start.scale = telomere_length
cur_chromosome.add(start)

#location of the chromosome
features = 5, 10, "1", "Gm18_5133882_G_A", "blue"

#Add a body - again using bp as the scale length here.
body = BasicChromosome.AnnotatedChromosomeSegment(max_len, features)
body.scale = max_len
cur_chromosome.add(body)

#Add a closing telomere
end = BasicChromosome.TelomereSegment(inverted=True)
end.scale = telomere_length
cur_chromosome.add(end)

#This chromosome is done
chr_diagram.add(cur_chromosome)

chr_diagram.draw("simple_chrom.pdf", "Dummy_chromsome")

但是它出现了以下错误。根据biopython的说明,注释特征应该以SeqFeature对象或元组的形式提供(“特征可以是SeqFeature对象,或者是值的元组:起始位置(整数)、结束位置(整数)、链(+1, -1, O或None)、标签(字符串)、ReportLab颜色(字符串或对象),以及可选的ReportLab填充颜色。”)。我不太确定问题出在哪里,任何帮助都将不胜感激。

TypeError                                 Traceback (most recent call last)
<ipython-input-67-a67e6230693f> in <module>()
 25 chr_diagram.add(cur_chromosome)
 26 
 ---> 27 chr_diagram.draw("simple_chrom.pdf", "Dummy_chromsome")

User/lib/python2.7/site-packages/Bio/Graphics/BasicChromosome.pyc in draw(self,     output_file, title)
146 
147             # do the drawing
--> 148             sub_component.draw(cur_drawing)
149 
150             # update the locations for the next chromosome

User/lib/python2.7/site-packages/Bio/Graphics/BasicChromosome.pyc in draw(self, cur_drawing)
274             sub_component._left_labels = []
275             sub_component._right_labels = []
--> 276             sub_component.draw(cur_drawing)
277             left_labels += sub_component._left_labels
278             right_labels += sub_component._right_labels

User/lib/python2.7/site-packages/Bio/Graphics/BasicChromosome.pyc in draw(self, cur_drawing)
419         self._draw_subcomponents(cur_drawing)  # Anything behind
420         self._draw_segment(cur_drawing)
--> 421         self._overdraw_subcomponents(cur_drawing)  # Anything on top
422         self._draw_label(cur_drawing)
423 

User/lib/python2.7/site-packages/Bio/Graphics/BasicChromosome.pyc in _overdraw_subcomponents(self, cur_drawing)
667             except AttributeError:
668                 #Assume tuple of ints, string, and color
--> 669                 start, end, strand, name, color = f[:5]
670                 color = _color_trans.translate(color)
671                 if len(f) > 5:

TypeError: 'int' object has no attribute '__getitem__' 

1 个回答

1

features = 5, 10, "1", "Gm18_5133882_G_A", "blue"

改成

features = [(5, 10, +1, "Gm18_5133882_G_A", "blue")]

应该就能正常工作了。

请注意:

  1. BasicChromosome.AnnotatedChromosomeSegment() 这个函数需要一个特征列表,所以即使你只有一个特征 "Gm18_5133882_G_A",也必须把它放在一个列表里。

  2. Strand 的值应该是 +1-1 或者 None。所以如果你给 "1" 作为 strand,Biopython 会把它理解为 None

撰写回答