문제

I am trying to recreate the annotated chromosome using biopython (http://biopython.org/DIST/docs/tutorial/Tutorial.html#sec345). I have a test code that would create one chromosome and one annotated feature (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")

It gives the following error and according biopython script annotation features should be provided as a SeqFeature object or tuple ("The features can either be SeqFeature objects, or tuples of values: start (int), end (int), strand (+1, -1, O or None), label (string),ReportLab color (string or object), and optional ReportLab fill color."). I am not sure where the problem is and any help would be appreciated.

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__' 
도움이 되었습니까?

해결책

Changing

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

to

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

should make it work.

Please note:

  1. BasicChromosome.AnnotatedChromosomeSegment() takes a list of features, so even when you have just one feature "Gm18_5133882_G_A", it has to be in a list.

  2. Strand should be either +1 , -1 or None. So if you give a "1" as strand, Biopython will interpret it as None.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top