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__'
Why email me directly if you're also posting the same question here?
Not only did you email me this question directly (which I replied to promptly with the same answer), you posted here on BioStars and you also cross posted on SO - http://stackoverflow.com/questions/22332644/making-annotated-chromosome-using-biopython/22610638
Please stop cross-posting like this & wasting people's time.
Really sorry and will not happen again