-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMT.py
53 lines (42 loc) · 1.71 KB
/
MT.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from reportlab.lib.units import cm
from Bio import SeqIO
from Bio.Graphics import BasicChromosome
entries = [
("Chr I", "Homosapiens.gb"),
("Chr II", "Musmusculus.gb"),
("Chr III", "Xenopus.gb"),
("Chr IV", "Zebrafish.gb"),
("Chr V", "Ovisaries.gb"),
]
max_len = 30432563 # Could compute this from the entries dict
telomere_length = 1000000 # For illustration
chr_diagram = BasicChromosome.Organism()
chr_diagram.page_size = (100 * cm, 95* 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", "Allmt")