This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Making Annotated Chromosome Using Biopython

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__'
biopython

Why email me directly if you're also posting the same question here?

Really sorry and will not happen again

2 answers

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


features should be a list of features, like this:

#location of the chromosome
features = [(5, 10, "1", "Gm18_5133882_G_A", "blue")]

It should be noted that the third element in the tuple should be the interger 1, instead of the string "1", because a strand in Biopython should be either integer 1, -1 or None, and a string "1" will be interpreted by Bio.Graphics as None, which is not the intended behavior in this case.

is there a way to add several features? I tried to do it like this: Features = [(5, 10, +1, "Label1", "blue"), (56, 90, +1, "Label2", "blue"), (100, 1200, +1, "Label3", "blue")]

But it's not working. Many thanks!

This would be better as a new question giving more information about the script you're working on. It might be something simple like mixing features (lower case) and Features (title case).

I also have this question, now I need to visualised some gene at chromosome just like Florian Jupe.et.al 2012 did. But I do not know hou to add so many of fetures.(I only have the gene location、gene name 、chromosome location 、but not the gene bank data ) and I also want to know that you are the Peter who help Jupe draw the annotated chromosome?

Log in to answer this question.