Skip to content

Commit 6330387

Browse files
authored
DNA Segment Map - fix bug 13375 and enhancement 13382 (#600)
Fix dump when DNA Association data contains tab characters. Add config option to include/exclude Citation Notes for parsing DNA data. Association Notes are always parsed. Currently Citations attached to an Association are parsed too. This makes them optional. Add config for character scale in Legend to allow more entries. Default fontsize is 12. This option lets user specify the fontsize for the Legend. This does not impact the chart size.
1 parent da3f0cd commit 6330387

File tree

1 file changed

+40
-29
lines changed

1 file changed

+40
-29
lines changed

DNA/dnasegmentmap.py

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
CONFIG.register('map.paternal-background', (0.833, 0.845, 0.92, 1.0))
6363
CONFIG.register('map.legend-single-chromosome-y-offset', 25)
6464
CONFIG.register('map.show-centromere',0)
65+
CONFIG.register('map.legend-char-height',12)
66+
CONFIG.register('map.include-citation-notes',1)
6567

6668
CONFIG.init()
6769

@@ -116,6 +118,7 @@ def main(self):
116118
segmap.gender = active.gender
117119
segmap.active = active
118120
segmap.relationship = self.relationship
121+
include_citation_notes = segmap._config.get('map.include-citation-notes')
119122

120123
for assoc in active.get_person_ref_list():
121124
if assoc.get_relation() == 'DNA':
@@ -142,13 +145,14 @@ def main(self):
142145
assoc_handle = assoc.ref
143146
self.write_chromo(line, side, rgb_color, assoc, note, segmap)
144147
# Get Notes attached to Citation which is attached to the Association
145-
for citation_handle in assoc.get_citation_list():
146-
citation = self.dbstate.db.get_citation_from_handle(citation_handle)
147-
for handle in citation.get_note_list():
148-
note = self.dbstate.db.get_note_from_handle(handle)
149-
for line in note.get().split('\n'):
150-
assoc_handle = assoc.ref
151-
self.write_chromo(line, side, rgb_color, assoc, note, segmap)
148+
if include_citation_notes :
149+
for citation_handle in assoc.get_citation_list():
150+
citation = self.dbstate.db.get_citation_from_handle(citation_handle)
151+
for handle in citation.get_note_list():
152+
note = self.dbstate.db.get_note_from_handle(handle)
153+
for line in note.get().split('\n'):
154+
assoc_handle = assoc.ref
155+
self.write_chromo(line, side, rgb_color, assoc, note, segmap)
152156
if len(segmap.segments) > 0:
153157
segmap.show()
154158
self.vbox.pack_start(segmap, True, True, 0)
@@ -158,12 +162,17 @@ def write_chromo(self, line, side, rgb_color, assoc, note, segmap):
158162
if "\t" in line:
159163
# Tabs are the field separators. Now determine THOUSEP and RADIXCHAR. Use Field 2 (Stop Pos) to see if there are THOUSEP there. Use Field 3 (SNPs) to see if there is a radixchar
160164
field = line.split('\t')
161-
if "," in field[2]:
162-
line = line.replace(",", "")
163-
elif "." in field[2]:
164-
line = line.replace(".", "")
165-
if "," in field[3]:
166-
line = line.replace(",", ".")
165+
if len(field) > 3:
166+
if "," in field[2]:
167+
line = line.replace(",", "")
168+
elif "." in field[2]:
169+
line = line.replace(".", "")
170+
if "," in field[3]:
171+
line = line.replace(",", ".")
172+
else:
173+
associate = segmap.dbstate.db.get_person_from_handle(assoc.ref)
174+
id_str = _(_nd.display(associate) )
175+
print("Skipping: ",id_str,line)
167176
line = line.replace("\t", ",")
168177
# If Tab is not the field separator, then comma is. And point is the radixchar.
169178
field = line.split(',')
@@ -239,6 +248,7 @@ def __init__(self):
239248
self.paternal_background = self._config.get('map.paternal-background')
240249
self.legend_single_chromosome = self._config.get('map.legend-single-chromosome-y-offset')
241250
self.show_centromere = self._config.get('map.show-centromere')
251+
self.legend_char_height = self._config.get('map.legend-char-height')
242252
self._config.save()
243253
self.chromosomesThirtySeven = (
244254
('1', 249250621),
@@ -477,7 +487,7 @@ def do_draw(self, cr):
477487
label_width = width
478488
offset_x = -(len(label)-2)* 6
479489
cr.move_to(offset_x, i * 2 * (chr_height + spacing) + offset+7)
480-
self.__chrrects.append((offset_x, i * 2 * (chr_height + spacing) + offset+7, 12, chr_height))
490+
self.__chrrects.append((offset_x, i * 2 * (chr_height + spacing) + offset+7, chr_height, chr_height))
481491
PangoCairo.show_layout(cr, layout)
482492

483493
self.set_axis(_('Chr'))
@@ -625,6 +635,7 @@ def do_draw(self, cr):
625635
cr.set_source_rgba(*fg_color)
626636
PangoCairo.show_layout(cr, layout)
627637
legend_offset_y += chr_height + 2 * spacing
638+
legend_chr_height = self.legend_char_height
628639
chromo_count = -1
629640
row_num = 0
630641
maximum = self.maximum
@@ -706,21 +717,21 @@ def do_draw(self, cr):
706717
cr.set_source_rgba(*fg_color)
707718
cr.stroke()
708719
# Legend
709-
cr.rectangle(legend_offset_x - chr_height - 2 * spacing,
720+
cr.rectangle(legend_offset_x - legend_chr_height - 2 * spacing,
710721
legend_offset_y + self.legend_swatch_offset_y,
711-
chr_height,
712-
chr_height)
722+
legend_chr_height,
723+
legend_chr_height)
713724
cr.set_source_rgba(rgb_color[0], rgb_color[1], rgb_color[2], 1)
714725
cr.fill_preserve()
715726
cr.stroke()
716727
layout = self.create_pango_layout(last_name)
717728
cr.move_to(legend_offset_x, legend_offset_y)
718-
self.__legendrects.append((legend_offset_x, legend_offset_y,len(assoc_name) * 6, chr_height))
729+
self.__legendrects.append((legend_offset_x, legend_offset_y,len(assoc_name) * 6, legend_chr_height))
719730
self.__associates.append(associate)
720731
self.__assoc_handle.append(handle)
721732
self.__legend_str.append(last_name)
722733
cr.set_source_rgba(*fg_color)
723-
legend_offset_y += chr_height + 2 * spacing
734+
legend_offset_y += legend_chr_height + 2 * spacing
724735
PangoCairo.show_layout(cr, layout)
725736
# Segment Info
726737
chr_offset = row_num * 2 * (chr_height + spacing) + offset
@@ -748,22 +759,22 @@ def do_draw(self, cr):
748759
if last_name != assoc_name:
749760
last_name = assoc_name
750761

751-
cr.rectangle(legend_offset_x - chr_height - 2 * spacing,
762+
cr.rectangle(legend_offset_x - legend_chr_height - 2 * spacing,
752763
legend_offset_y,
753-
chr_height,
754-
chr_height)
764+
legend_chr_height,
765+
legend_chr_height)
755766
cr.set_source_rgba(rgb_color[0], rgb_color[1], rgb_color[2], 1/chr_mult)
756767
cr.fill_preserve()
757768
cr.stroke()
758769

759770
layout = self.create_pango_layout(last_name)
760771
cr.move_to(legend_offset_x, legend_offset_y)
761-
self.__legendrects.append((legend_offset_x, legend_offset_y,len(assoc_name) * 6, chr_height))
772+
self.__legendrects.append((legend_offset_x, legend_offset_y,len(assoc_name) * 6, legend_chr_height))
762773
self.__associates.append(associate)
763774
self.__assoc_handle.append(handle)
764775
self.__legend_str.append(last_name)
765776
cr.set_source_rgba(*fg_color)
766-
legend_offset_y += chr_height + 2 * spacing
777+
legend_offset_y += legend_chr_height + 2 * spacing
767778
PangoCairo.show_layout(cr, layout)
768779
else: # Drawing all chromosome segments
769780
for chromo, start, stop, side, cms, snp, assoc_name, rgb_color, associate, handle, note in self.segments:
@@ -796,22 +807,22 @@ def do_draw(self, cr):
796807
# Legend entry
797808
if last_name != assoc_name:
798809
last_name = assoc_name
799-
cr.rectangle(legend_offset_x - chr_height - 2 * spacing,
810+
cr.rectangle(legend_offset_x - legend_chr_height - 2 * spacing,
800811
legend_offset_y + self.legend_swatch_offset_y,
801-
chr_height,
802-
chr_height)
812+
legend_chr_height,
813+
legend_chr_height)
803814
cr.set_source_rgba(rgb_color[0], rgb_color[1], rgb_color[2], 1/chr_mult)
804815
cr.fill_preserve()
805816
cr.stroke()
806817

807818
layout = self.create_pango_layout(last_name)
808819
cr.move_to(legend_offset_x, legend_offset_y)
809-
self.__legendrects.append((legend_offset_x, legend_offset_y,len(assoc_name) * 6, chr_height))
820+
self.__legendrects.append((legend_offset_x, legend_offset_y,len(assoc_name) * 6, legend_chr_height))
810821
self.__associates.append(associate)
811822
self.__assoc_handle.append(handle)
812823
self.__legend_str.append(last_name)
813824
cr.set_source_rgba(*fg_color)
814-
legend_offset_y += chr_height + 2 * spacing
825+
legend_offset_y += legend_chr_height + 2 * spacing
815826
PangoCairo.show_layout(cr, layout)
816827

817828
self.set_size_request(-1, bottom + height + 5)

0 commit comments

Comments
 (0)