我正在尝试使用biopython(http://biopython.org/DIST/docs/tutorial/Tutorial.html#sec345)重新创建带注释的染色体。我有一个测试代码,可以创建一个染色体和一个带注释的功能(5,10," 1"," Gm18_5133882_G_A","蓝")。
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对象,也可以是值的元组:start(int),end(int) ,strand(+ 1,-1,O或None),label(字符串),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__'
答案 0 :(得分:1)
更改
features = 5, 10, "1", "Gm18_5133882_G_A", "blue"
到
features = [(5, 10, +1, "Gm18_5133882_G_A", "blue")]
应该让它发挥作用。
请注意:
BasicChromosome.AnnotatedChromosomeSegment()
会获取一系列功能,因此即使您只有一个功能"Gm18_5133882_G_A"
,也必须在列表中。
Strand
应该是+1
,-1
或None
。因此,如果您将"1"
作为链,Biopython会将其解释为None
。