It is possible to tell me a safe way to upgrade biopython without having some conflict between the tow versions ! Thanks in advance
Hello every body. Several people who did bioinformatic need a tool to draw some gene features on chromosomes, I found I nice way to do that using Biopython (Even if I never use it before). This is a nice link with exemples http://biopython.org/DIST/docs/tutorial/Tutorial.html#htoc236 (see section 17.2.2 Annotated Chromosomes). I tried to do an exemple using the following code :
from reportlab.lib.units import cm
from Bio import SeqIO
from Bio.Graphics import BasicChromosome
entries = [("Chr I", "CHR_I/NC_003070.gbk"),
("Chr II", "CHR_II/NC_003071.gbk"),
("Chr III", "CHR_III/NC_003074.gbk"),
("Chr IV", "CHR_IV/NC_003075.gbk"),
("Chr V", "CHR_V/NC_003076.gbk")]
max_len = 30432563 #Could compute this
telomere_length = 1000000 #For illustration
chr_diagram = BasicChromosome.Organism()
chr_diagram.page_size = (29.7*cm, 21*cm) #A4 landscape
for index, (name, filename) in enumerate(entries):
record = SeqIO.read(filename,"genbank")
length = len(record)
features = [f for f in record.features if f.type=="tRNA"]
#Record an Artemis style integer color in the feature's qualifiers,
#1 = Black, 2 = Red, 3 = Green, 4 = blue, 5 =cyan, 6 = purple
for f in features: f.qualifiers["color"] = [index+2]
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)
#Add a body - again using bp as the scale length here.
body = BasicChromosome.AnnotatedChromosomeSegment(length, features)
body.scale = length
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("tRNA_chrom.pdf", "Arabidopsis thaliana")
The problem is that I have an error message
body = BasicChromosome.AnnotatedChromosomeSegment(length, features)
AttributeError: 'module' object has no attribute 'AnnotatedChromosomeSegment'
Any help will be appreciated Thanks
1 answer
The documentation refers to the latest version 1.61 Your version of BioPython does not contain the necessary functionality. You will need to upgrade.
This all depends on the operating system that you have. You just need to follow the standard installation instructions. The new version of Biopython should directly replace the old one.
Thanks Albert ! it works now ! So this how I upgrade Biopython in linux system :
$: easy_install -f http://biopython.org/DIST/ biopython
if easy_install is not installed you have to do it by yourself :
$: sudo apt-get install python-setuptools python-dev build-essential
Thanks again great !
$ easy_install pip
$ pip install -U biopython
Log in to answer this question.
My first guess would be that your version of BioPython is older than when this feature has been added. What does this print?
Thanks for your reply ! this is the result of Bio version 1.58
It sounds like python cant find the
AnnotatedChromosomeSegmentmodule inside ofBasicChromosome.Assuming you managed to get
biopythonandreportlabinstalled correctly, I would bet that this is an issue with simply writing the import statement incorrectly. Sometimes things act wonky depending on how the internals of the package is set up (NOT gonna go into all that if we don't have to!).But before anything else, can you confirm that you are using the same version of biopython that the tutorial is referencing? What is the output when you type the following into an interactive python session:
After that we might be able to help better.