Skip to content

uorf4u.drawing

This module provides visualisation of loci annotation.

AnnotationPlotManager

AnnotationPlotManager object holds needed information for annotation visualisation and controls it.

Note:

It's supposed that the AnnotationPlotManager' objects will not be used directly by API users since visualisation can be controlled by 'plot_annotation' method.

Attributes:

  • path (uorf4u.data_processing.Path) –

    Path class' objects that holds list of conserved ORFs.

  • upstream_sequences (list) –

    list of dicts with information about upstream sequences.

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

  • coordinate_system (dict) –

    coordinate system of figure.

  • additional_data (dict) –

    dict with data for visualisation tracks.

Source code in uorf4u/drawing_annotation.py
 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
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
class AnnotationPlotManager:
    """
    AnnotationPlotManager object holds needed information for annotation visualisation and controls it.

    Note:
        It's supposed that the AnnotationPlotManager' objects will not be used directly by API users since
            visualisation can be controlled by 'plot_annotation' method.

    Attributes:
        path (uorf4u.data_processing.Path): Path class' objects that holds list of conserved ORFs.
        upstream_sequences (list): list of dicts with information about upstream sequences.
        parameters (uorf4u.manager.Parameters): Parameters' class object.
        coordinate_system (dict): coordinate system of figure.
        additional_data (dict): dict with data for visualisation tracks.

    """

    def __init__(self, path, upstream_sequences: list, parameters: uorf4u.manager.Parameters):
        """Create a AnnotationPlotManager object.

        Arguments:
            path (uorf4u.data_processing.Path): Path class' objects that holds list of conserved ORFs.
            upstream_sequences (list): list of dicts with information about upstream sequences.
            parameters (uorf4u.manager.Parameters): Parameters' class object.

        """
        self.path = path
        self.upstream_sequences = upstream_sequences
        self.parameters = parameters
        self.coordinate_system = dict()
        self.additional_data = dict()

    def define_x_axis_coordinate_system(self) -> None:
        """Define coordinate system.

        Returns:
            None

        """

        label_height = self.parameters.arguments["label_height_to_orf_height"] * self.parameters.arguments[
            "orf_height"] * cm
        label_font_size = uorf4u.methods.string_height_to_font_size(label_height, "regular", self.parameters.arguments)
        self.additional_data["label_font_size"] = label_font_size
        self.additional_data["ordered_upstream_sequences"] = [self.upstream_sequences[i] for i in
                                                              [orf.useq_index for orf in self.path.path]]
        max_label_width = max([reportlab.pdfbase.pdfmetrics.stringWidth(i.annotations["label"], "regular",
                                                                        label_font_size)
                               for i in self.additional_data["ordered_upstream_sequences"]])
        self.additional_data["number_of_sequences"] = len(self.path)
        self.additional_data["max_upstream_sequence_length"] = max(
            i.annotations["upstream_region_length"] for i in self.additional_data["ordered_upstream_sequences"])
        self.additional_data["max_downstream_sequence_length"] = max(
            i.annotations["downstream_region_length"] for i in self.additional_data["ordered_upstream_sequences"])
        window_size_nt = self.additional_data["max_upstream_sequence_length"] + self.additional_data[
            "max_downstream_sequence_length"]
        if self.parameters.arguments["annotation_width"] == "auto":
            annotation_width = window_size_nt * self.parameters.arguments["mm_per_nt"] * mm
        else:
            annotation_width = self.parameters.arguments["annotation_width"] * cm
        self.coordinate_system["transformation_coef"] = annotation_width / window_size_nt
        self.coordinate_system["x_labels_start"] = self.parameters.arguments["margin"] * cm
        self.coordinate_system["x_labels_stop"] = self.coordinate_system["x_labels_start"] + max_label_width
        self.coordinate_system["x_annotation_start"] = self.coordinate_system["x_labels_stop"] + \
                                                       self.parameters.arguments["label_gap"] * cm
        self.coordinate_system["x_annotation_stop"] = self.coordinate_system["x_annotation_start"] + annotation_width
        self.coordinate_system["figure_width"] = 2 * self.parameters.arguments["margin"] * cm + annotation_width + \
                                                 max_label_width + self.parameters.arguments["label_gap"] * cm
        self.coordinate_system["figure_height"] = self.parameters.arguments["margin"] * cm

        return None

    def create_tracks(self) -> None:
        """Create visualisation tracks.

        Returns:
            None

        """
        self.tracks = []
        """
        title_loader = TitleLoader(self.parameters)
        title_loader.prepare_data(self.coordinate_system, self.additional_data)
        title_track = title_loader.create_track()
        self.tracks.append(title_track)
        self.coordinate_system["figure_height"] += title_track.needed_y_space()
        """
        for index in range(self.additional_data["number_of_sequences"]):
            upstream_sequence = self.additional_data["ordered_upstream_sequences"][index]
            conserved_orf = self.path.path[index]
            sequence_loader = SequencesLoader(self.parameters)
            sequence_loader.prepare_data(upstream_sequence, conserved_orf, self.coordinate_system, self.additional_data)
            track = sequence_loader.create_track()
            self.tracks.append(track)
            self.coordinate_system["figure_height"] += track.needed_y_space()
            self.coordinate_system["figure_height"] += self.parameters.arguments["gap"] * cm
            # if index < self.additional_data["number_of_sequences"] - 1:
        axis_tics_loader = AxisLoader(self.parameters)
        axis_tics_loader.prepare_data(self.coordinate_system, self.additional_data)
        axis_tics_track = axis_tics_loader.create_track()
        self.tracks.append(axis_tics_track)
        self.coordinate_system["figure_height"] += axis_tics_track.needed_y_space()
        self.coordinate_system["figure_height"] += self.parameters.arguments["margin"] * cm

    def plot(self, filename):
        image = Image(filename, self.coordinate_system["figure_width"], self.coordinate_system["figure_height"])
        current_y_top = self.coordinate_system["figure_height"] - self.parameters.arguments["margin"] * cm
        for track in self.tracks:
            track.visualisation_data["y_top"] = current_y_top
            track.draw(image.canvas)
            current_y_top -= (track.needed_space + self.parameters.arguments["gap"] * cm)
        image.save()
        return None

__init__(path, upstream_sequences, parameters)

Create a AnnotationPlotManager object.

Parameters:

  • path (uorf4u.data_processing.Path) –

    Path class' objects that holds list of conserved ORFs.

  • upstream_sequences (list) –

    list of dicts with information about upstream sequences.

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

Source code in uorf4u/drawing_annotation.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def __init__(self, path, upstream_sequences: list, parameters: uorf4u.manager.Parameters):
    """Create a AnnotationPlotManager object.

    Arguments:
        path (uorf4u.data_processing.Path): Path class' objects that holds list of conserved ORFs.
        upstream_sequences (list): list of dicts with information about upstream sequences.
        parameters (uorf4u.manager.Parameters): Parameters' class object.

    """
    self.path = path
    self.upstream_sequences = upstream_sequences
    self.parameters = parameters
    self.coordinate_system = dict()
    self.additional_data = dict()

create_tracks()

Create visualisation tracks.

Returns:

  • None

    None

Source code in uorf4u/drawing_annotation.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
def create_tracks(self) -> None:
    """Create visualisation tracks.

    Returns:
        None

    """
    self.tracks = []
    """
    title_loader = TitleLoader(self.parameters)
    title_loader.prepare_data(self.coordinate_system, self.additional_data)
    title_track = title_loader.create_track()
    self.tracks.append(title_track)
    self.coordinate_system["figure_height"] += title_track.needed_y_space()
    """
    for index in range(self.additional_data["number_of_sequences"]):
        upstream_sequence = self.additional_data["ordered_upstream_sequences"][index]
        conserved_orf = self.path.path[index]
        sequence_loader = SequencesLoader(self.parameters)
        sequence_loader.prepare_data(upstream_sequence, conserved_orf, self.coordinate_system, self.additional_data)
        track = sequence_loader.create_track()
        self.tracks.append(track)
        self.coordinate_system["figure_height"] += track.needed_y_space()
        self.coordinate_system["figure_height"] += self.parameters.arguments["gap"] * cm
        # if index < self.additional_data["number_of_sequences"] - 1:
    axis_tics_loader = AxisLoader(self.parameters)
    axis_tics_loader.prepare_data(self.coordinate_system, self.additional_data)
    axis_tics_track = axis_tics_loader.create_track()
    self.tracks.append(axis_tics_track)
    self.coordinate_system["figure_height"] += axis_tics_track.needed_y_space()
    self.coordinate_system["figure_height"] += self.parameters.arguments["margin"] * cm

define_x_axis_coordinate_system()

Define coordinate system.

Returns:

  • None

    None

Source code in uorf4u/drawing_annotation.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
def define_x_axis_coordinate_system(self) -> None:
    """Define coordinate system.

    Returns:
        None

    """

    label_height = self.parameters.arguments["label_height_to_orf_height"] * self.parameters.arguments[
        "orf_height"] * cm
    label_font_size = uorf4u.methods.string_height_to_font_size(label_height, "regular", self.parameters.arguments)
    self.additional_data["label_font_size"] = label_font_size
    self.additional_data["ordered_upstream_sequences"] = [self.upstream_sequences[i] for i in
                                                          [orf.useq_index for orf in self.path.path]]
    max_label_width = max([reportlab.pdfbase.pdfmetrics.stringWidth(i.annotations["label"], "regular",
                                                                    label_font_size)
                           for i in self.additional_data["ordered_upstream_sequences"]])
    self.additional_data["number_of_sequences"] = len(self.path)
    self.additional_data["max_upstream_sequence_length"] = max(
        i.annotations["upstream_region_length"] for i in self.additional_data["ordered_upstream_sequences"])
    self.additional_data["max_downstream_sequence_length"] = max(
        i.annotations["downstream_region_length"] for i in self.additional_data["ordered_upstream_sequences"])
    window_size_nt = self.additional_data["max_upstream_sequence_length"] + self.additional_data[
        "max_downstream_sequence_length"]
    if self.parameters.arguments["annotation_width"] == "auto":
        annotation_width = window_size_nt * self.parameters.arguments["mm_per_nt"] * mm
    else:
        annotation_width = self.parameters.arguments["annotation_width"] * cm
    self.coordinate_system["transformation_coef"] = annotation_width / window_size_nt
    self.coordinate_system["x_labels_start"] = self.parameters.arguments["margin"] * cm
    self.coordinate_system["x_labels_stop"] = self.coordinate_system["x_labels_start"] + max_label_width
    self.coordinate_system["x_annotation_start"] = self.coordinate_system["x_labels_stop"] + \
                                                   self.parameters.arguments["label_gap"] * cm
    self.coordinate_system["x_annotation_stop"] = self.coordinate_system["x_annotation_start"] + annotation_width
    self.coordinate_system["figure_width"] = 2 * self.parameters.arguments["margin"] * cm + annotation_width + \
                                             max_label_width + self.parameters.arguments["label_gap"] * cm
    self.coordinate_system["figure_height"] = self.parameters.arguments["margin"] * cm

    return None

AxisLoader

Bases: Loader

An AxisLoader object prepares data for an Axis track object.

Attributes:

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

  • prepared_data (dict) –

    dict with data needed for a visualisation track.

Source code in uorf4u/drawing_annotation.py
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
class AxisLoader(Loader):
    """An AxisLoader object prepares data for an Axis track object.


    Attributes:
        parameters (uorf4u.manager.Parameters): Parameters' class object.
        prepared_data (dict): dict with data needed for a visualisation track.

    """

    def __init__(self, parameters):
        """Create an AxisLoader object.

        Arguments:
            parameters (uorf4u.manager.Parameters): Parameters' class object.

        """
        super().__init__(parameters)

    def prepare_data(self, coordinate_system: dict, additional_data: dict):
        """Prepare data for an Axis visualisation track.

        Attributes:
            coordinate_system (dict): coordinate system of a figure page.
            additional_data (dict): data needed for a track initialisation.

        Returns:
            dict: dictionary with prepared data for visualisation.

        """
        prepared_data = dict()
        prepared_data["coordinate_system"] = coordinate_system
        prepared_data["max_upstream_sequence_length"] = additional_data["max_upstream_sequence_length"]
        prepared_data["max_downstream_sequence_length"] = additional_data["max_downstream_sequence_length"]
        step = int(round(additional_data["max_upstream_sequence_length"] / 2, -2))
        tics = [-additional_data["max_upstream_sequence_length"], 0, additional_data["max_downstream_sequence_length"]]
        x_tic_centred = int(round(-additional_data["max_upstream_sequence_length"] / 2, -2))
        tics.append(x_tic_centred)
        x_tic_left, x_tic_right = x_tic_centred - step, x_tic_centred + step
        while x_tic_right < 0 and x_tic_left > - additional_data["max_upstream_sequence_length"]:
            tics.append(x_tic_left)
            tics.append(x_tic_right)
            x_tic_left -= step
            x_tic_right += step
        tics.sort()
        tics_coordinates = [self.transform_relative_position_to_x_coordinate(i, coordinate_system, additional_data[
            "max_upstream_sequence_length"]) for i in tics]
        prepared_data["tics"] = {k: v for k, v in zip(tics, tics_coordinates)}
        self.prepared_data = prepared_data
        return prepared_data

    def transform_relative_position_to_x_coordinate(self, relative_position: int, coordinate_system: dict,
                                                    max_upstream_sequence_length: int) -> float:
        """Transform nucleotide x coordinate to pdf's.

        Arguments:
            relative_position (int): nucleotide position
            coordinate_system (dict): coordinate system of a figure.
            max_upstream_sequence_length (int): max length of upstream sequences for visualisation.

        Returns:
            float: transformed x coordinate.
        """
        return coordinate_system["x_annotation_start"] + (relative_position + max_upstream_sequence_length) * \
               coordinate_system["transformation_coef"]

    def create_track(self) -> TicsVis:
        """Initialise a Tics track object.

        Returns:
            TicsVis: visualisation track.

        """
        return TicsVis(self.prepared_data, self.parameters)

__init__(parameters)

Create an AxisLoader object.

Parameters:

Source code in uorf4u/drawing_annotation.py
706
707
708
709
710
711
712
713
def __init__(self, parameters):
    """Create an AxisLoader object.

    Arguments:
        parameters (uorf4u.manager.Parameters): Parameters' class object.

    """
    super().__init__(parameters)

create_track()

Initialise a Tics track object.

Returns:

  • TicsVis( TicsVis ) –

    visualisation track.

Source code in uorf4u/drawing_annotation.py
762
763
764
765
766
767
768
769
def create_track(self) -> TicsVis:
    """Initialise a Tics track object.

    Returns:
        TicsVis: visualisation track.

    """
    return TicsVis(self.prepared_data, self.parameters)

prepare_data(coordinate_system, additional_data)

Prepare data for an Axis visualisation track.

Attributes:

  • coordinate_system (dict) –

    coordinate system of a figure page.

  • additional_data (dict) –

    data needed for a track initialisation.

Returns:

  • dict

    dictionary with prepared data for visualisation.

Source code in uorf4u/drawing_annotation.py
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
def prepare_data(self, coordinate_system: dict, additional_data: dict):
    """Prepare data for an Axis visualisation track.

    Attributes:
        coordinate_system (dict): coordinate system of a figure page.
        additional_data (dict): data needed for a track initialisation.

    Returns:
        dict: dictionary with prepared data for visualisation.

    """
    prepared_data = dict()
    prepared_data["coordinate_system"] = coordinate_system
    prepared_data["max_upstream_sequence_length"] = additional_data["max_upstream_sequence_length"]
    prepared_data["max_downstream_sequence_length"] = additional_data["max_downstream_sequence_length"]
    step = int(round(additional_data["max_upstream_sequence_length"] / 2, -2))
    tics = [-additional_data["max_upstream_sequence_length"], 0, additional_data["max_downstream_sequence_length"]]
    x_tic_centred = int(round(-additional_data["max_upstream_sequence_length"] / 2, -2))
    tics.append(x_tic_centred)
    x_tic_left, x_tic_right = x_tic_centred - step, x_tic_centred + step
    while x_tic_right < 0 and x_tic_left > - additional_data["max_upstream_sequence_length"]:
        tics.append(x_tic_left)
        tics.append(x_tic_right)
        x_tic_left -= step
        x_tic_right += step
    tics.sort()
    tics_coordinates = [self.transform_relative_position_to_x_coordinate(i, coordinate_system, additional_data[
        "max_upstream_sequence_length"]) for i in tics]
    prepared_data["tics"] = {k: v for k, v in zip(tics, tics_coordinates)}
    self.prepared_data = prepared_data
    return prepared_data

transform_relative_position_to_x_coordinate(relative_position, coordinate_system, max_upstream_sequence_length)

Transform nucleotide x coordinate to pdf's.

Parameters:

  • relative_position (int) –

    nucleotide position

  • coordinate_system (dict) –

    coordinate system of a figure.

  • max_upstream_sequence_length (int) –

    max length of upstream sequences for visualisation.

Returns:

  • float( float ) –

    transformed x coordinate.

Source code in uorf4u/drawing_annotation.py
747
748
749
750
751
752
753
754
755
756
757
758
759
760
def transform_relative_position_to_x_coordinate(self, relative_position: int, coordinate_system: dict,
                                                max_upstream_sequence_length: int) -> float:
    """Transform nucleotide x coordinate to pdf's.

    Arguments:
        relative_position (int): nucleotide position
        coordinate_system (dict): coordinate system of a figure.
        max_upstream_sequence_length (int): max length of upstream sequences for visualisation.

    Returns:
        float: transformed x coordinate.
    """
    return coordinate_system["x_annotation_start"] + (relative_position + max_upstream_sequence_length) * \
           coordinate_system["transformation_coef"]

Image

An Image object holds pdf.

Attributes:

  • canvas (reportlab.pdfgen.canvas.Canvas) –

    pdf object of the reportlab library.

Source code in uorf4u/drawing_annotation.py
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
class Image:
    """An Image object holds pdf.

    Attributes:
        canvas (reportlab.pdfgen.canvas.Canvas): pdf object of the reportlab library.

    """

    def __init__(self, filename: str, width: float, height: float):
        """Create an Image object.

        Arguments:
            filename (str): path and name of a pdf.
            width (float): width of a pdf.
            height (float): height of a pdf.

        """
        self.canvas = reportlab.pdfgen.canvas.Canvas(filename, pagesize=(width, height))

    def save(self) -> None:
        """Save a pdf file.

        Returns:
            None

        """
        self.canvas.save()
        return None

__init__(filename, width, height)

Create an Image object.

Parameters:

  • filename (str) –

    path and name of a pdf.

  • width (float) –

    width of a pdf.

  • height (float) –

    height of a pdf.

Source code in uorf4u/drawing_annotation.py
780
781
782
783
784
785
786
787
788
789
def __init__(self, filename: str, width: float, height: float):
    """Create an Image object.

    Arguments:
        filename (str): path and name of a pdf.
        width (float): width of a pdf.
        height (float): height of a pdf.

    """
    self.canvas = reportlab.pdfgen.canvas.Canvas(filename, pagesize=(width, height))

save()

Save a pdf file.

Returns:

  • None

    None

Source code in uorf4u/drawing_annotation.py
791
792
793
794
795
796
797
798
799
def save(self) -> None:
    """Save a pdf file.

    Returns:
        None

    """
    self.canvas.save()
    return None

Loader

Parent class for tracks loaders.

Attributes:

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

  • prepared_data (dict) –

    dict with data needed for visualisation tracks.

Source code in uorf4u/drawing_annotation.py
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
class Loader:
    """Parent class for tracks loaders.

    Attributes:
        parameters (uorf4u.manager.Parameters): Parameters' class object.
        prepared_data (dict): dict with data needed for visualisation tracks.

    """

    def __init__(self, parameters: uorf4u.manager.Parameters):
        """Parent's constructor for creating a Loader class object.

        Arguments:
            parameters (uorf4u.manager.Parameters): Parameters' class object.
        """
        self.parameters = parameters
        self.prepared_data = None

    def prepare_data(self) -> None:
        """Empty parent's method for data preparation.

        Returns:
            None

        """
        pass

    def create_track(self) -> None:
        """Empty parent's method for initialisation of a track.

        Returns:
            None

        """
        pass

__init__(parameters)

Parent's constructor for creating a Loader class object.

Parameters:

Source code in uorf4u/drawing_annotation.py
499
500
501
502
503
504
505
506
def __init__(self, parameters: uorf4u.manager.Parameters):
    """Parent's constructor for creating a Loader class object.

    Arguments:
        parameters (uorf4u.manager.Parameters): Parameters' class object.
    """
    self.parameters = parameters
    self.prepared_data = None

create_track()

Empty parent's method for initialisation of a track.

Returns:

  • None

    None

Source code in uorf4u/drawing_annotation.py
517
518
519
520
521
522
523
524
def create_track(self) -> None:
    """Empty parent's method for initialisation of a track.

    Returns:
        None

    """
    pass

prepare_data()

Empty parent's method for data preparation.

Returns:

  • None

    None

Source code in uorf4u/drawing_annotation.py
508
509
510
511
512
513
514
515
def prepare_data(self) -> None:
    """Empty parent's method for data preparation.

    Returns:
        None

    """
    pass

SequenceVis

Bases: Track

SequenceVis track draws sequences and annotation.

Attributes:

  • visualisation_data (dict) –

    a dictionary with data needed for visualisation.

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

  • needed_space (float) –

    needed vertical space for a track.

Source code in uorf4u/drawing_annotation.py
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
class SequenceVis(Track):
    """SequenceVis track draws sequences and annotation.

    Attributes:
        visualisation_data (dict): a dictionary with data needed for visualisation.
        parameters (uorf4u.manager.Parameters): Parameters' class object.
        needed_space (float): needed vertical space for a track.

    """

    def __init__(self, visualisation_data: dict, parameters: uorf4u.manager.Parameters):
        """Create a SequenceVis object.

        Arguments:
            visualisation_data (dict): a dictionary with data needed for visualisation.
            parameters (uorf4u.manager.Parameters): Parameters' class object.

        """
        super().__init__(visualisation_data, parameters)
        self.needed_space = None

    def needed_y_space(self) -> float:
        """Calculate needed vertical space for a SequenceVis track.

        Returns:
            float: needed vertical space.

        """
        self.needed_space = self.parameters.arguments["orf_height"] * cm
        return self.needed_space

    def draw(self, canvas: reportlab.pdfgen.canvas.Canvas) -> None:
        """Draw a Sequence track.

        Arguments:
            canvas (reportlab.pdfgen.canvas.Canvas): a pdf object.

        Returns:
            None

        """
        orf_height = self.parameters.arguments["orf_height"] * cm
        y_c = self.visualisation_data["y_top"] - 0.5 * orf_height
        x_offset = 0.5 * self.parameters.arguments["upstream_seq_line_width"]
        canvas.setStrokeColorRGB(*uorf4u.methods.get_color("upstream_seq_line_color", self.parameters.arguments))
        canvas.setLineCap(0)
        canvas.setLineWidth(self.parameters.arguments["upstream_seq_line_width"])
        canvas.line(self.visualisation_data["upstream_sequence_line_start_x"], y_c,
                    self.visualisation_data["upstream_sequence_line_stop_x"] - x_offset, y_c)
        # Cleaning the space:
        canvas.setFillColorRGB
        canvas.setStrokeColorRGB(1, 1, 1, 1)

        for orf_dict in self.visualisation_data["orfs_coordinates_dict"].values():

            canvas.setLineWidth(self.parameters.arguments["upstream_seq_line_width"]*1.5)
            canvas.line(orf_dict["x_start"], y_c, orf_dict["x_stop"], y_c)
            #canvas.rect(orf_dict["x_start"], y_c - orf_height / 2, orf_dict["x_stop"] - orf_dict["x_start"], orf_height,
            #            stroke=0, fill=1)
        if self.parameters.arguments["check_assembly_annotation"] and \
                "fasta" not in self.parameters.cmd_arguments.keys():
            for protein_id, cds_dict in self.visualisation_data["CDSs_coordinates_dict"].items():
                canvas.line(cds_dict["x_start"], y_c, cds_dict["x_stop"], y_c)
        canvas.setLineWidth(self.parameters.arguments["upstream_seq_line_width"])

        # Labels
        canvas.setFillColorRGB(*uorf4u.methods.get_color("label_color", self.parameters.arguments))
        canvas.setFont("regular", self.visualisation_data["label_font_size"])
        y_l = y_c - 0.5 * (self.parameters.arguments["label_height_to_orf_height"] * orf_height)
        canvas.drawRightString(self.visualisation_data["coordinate_system"]["x_labels_stop"], y_l,
                               self.visualisation_data["useq_label"])

        # main_CDS
        canvas.setLineWidth(self.parameters.arguments["orf_line_width"])
        canvas.setStrokeColorRGB(*uorf4u.methods.get_color("cds_seq_stroke_color", self.parameters.arguments))
        canvas.setFillColorRGB(*uorf4u.methods.get_color("cds_seq_fill_color", self.parameters.arguments))
        p = canvas.beginPath()
        p.moveTo(self.visualisation_data["main_CDS_stop_x"], y_c - orf_height / 2)
        p.lineTo(self.visualisation_data["main_CDS_start_x"], y_c - orf_height / 2)
        p.lineTo(self.visualisation_data["main_CDS_start_x"], y_c + orf_height / 2)
        p.lineTo(self.visualisation_data["main_CDS_stop_x"], y_c + orf_height / 2)
        canvas.drawPath(p, stroke=1, fill=1)
        # Other ORFs:
        for orf in self.visualisation_data["annotated_orfs"]:
            orf_dict = self.visualisation_data["orfs_coordinates_dict"][orf]
            if orf != self.visualisation_data["conserved_orf"]:
                fill_color = None
                stroke_color = uorf4u.methods.get_color("other_uorfs_stroke_color", self.parameters.arguments)

            else:
                fill_color = uorf4u.methods.get_color("conserved_uorfs_fill_color", self.parameters.arguments)
                stroke_color = uorf4u.methods.get_color("conserved_uorfs_stroke_color", self.parameters.arguments)
            self.orf_object(canvas, orf_dict["x_start"], orf_dict["x_stop"], y_c, orf_dict["strand"], orf_height,
                            orf_dict["left_out"], orf_dict["right_out"], fill_color, stroke_color)

        # Annotated in RefSeq CDSs
        if self.parameters.arguments["check_assembly_annotation"] and \
                "fasta" not in self.parameters.cmd_arguments.keys():
            fill_color = None
            stroke_color = uorf4u.methods.get_color("annotated_orf_stroke_color", self.parameters.arguments)
            for protein_id, cds_dict in self.visualisation_data["CDSs_coordinates_dict"].items():
                self.orf_object(canvas, cds_dict["x_start"], cds_dict["x_stop"], y_c, cds_dict["strand"], orf_height,
                                cds_dict["left_out"], cds_dict["right_out"], fill_color, stroke_color)
        return None

    def orf_object(self, canvas: reportlab.pdfgen.canvas.Canvas, x_start: float, x_stop: float, y_c: float, strand: str,
                   height: float, left_out: bool, right_out: bool, fill_color: str, stroke_color: str) -> None:
        """Method for drawing an ORF's polygon.

        Arguments:
            canvas (reportlab.pdfgen.canvas.Canvas): a pdf object.
            x_start (float): ORF's start coordinate (already transformed to pdf's)
            x_stop (float): ORF's stop coordinate (already transformed to pdf's)
            y_c: (float): centred y coordinate of a current track.
            strand (str): strand of an ORF.
            height (float): height of a polygon.
            left_out (bool): whether an ORF is out of range on the left.
            right_out (bool): whether an ORF is out of range on the right.
            fill_color (str): fill color of a polygon.
            stroke_color (str): stroke color of a polygon.

        Returns:
            None
        """
        fill, stroke = 0, 0
        if stroke_color:
            canvas.setStrokeColorRGB(*stroke_color)
            stroke = 1
        if fill_color:
            canvas.setFillColorRGB(*fill_color)
            fill = 1
        arrow_length = min(height, (x_stop - x_start))
        p = canvas.beginPath()
        if strand == "+" and not left_out and not right_out:
            p.moveTo(x_start, y_c)
            p.lineTo(x_start, y_c + height / 2)
            p.lineTo(x_stop - arrow_length, y_c + height / 2)
            p.lineTo(x_stop, y_c)
            p.lineTo(x_stop - arrow_length, y_c - height / 2)
            p.lineTo(x_start, y_c - height / 2)
            p.lineTo(x_start, y_c)
        elif strand == "+" and left_out and not right_out:
            p.moveTo(x_start, y_c + height / 2)
            p.lineTo(x_stop - arrow_length, y_c + height / 2)
            p.lineTo(x_stop, y_c)
            p.lineTo(x_stop - arrow_length, y_c - height / 2)
            p.lineTo(x_start, y_c - height / 2)
        elif strand == "+" and right_out and not left_out:
            p.moveTo(x_stop, y_c + height / 2)
            p.lineTo(x_start, y_c + height / 2)
            p.lineTo(x_start, y_c - height / 2)
            p.lineTo(x_stop, y_c - height / 2)
        elif strand == "-" and not left_out and not right_out:
            p.moveTo(x_stop, y_c)
            p.lineTo(x_stop, y_c + height / 2)
            p.lineTo(x_start + arrow_length, y_c + height / 2)
            p.lineTo(x_start, y_c)
            p.lineTo(x_start + arrow_length, y_c - height / 2)
            p.lineTo(x_stop, y_c - height / 2)
            p.lineTo(x_stop, y_c)
        elif strand == "-" and right_out and not left_out:
            p.moveTo(x_stop, y_c + height / 2)
            p.lineTo(x_start + arrow_length, y_c + height / 2)
            p.lineTo(x_start, y_c)
            p.lineTo(x_start + arrow_length, y_c - height / 2)
            p.lineTo(x_stop, y_c - height / 2)
        elif strand == "-" and left_out and not right_out:
            p.moveTo(x_start, y_c + height / 2)
            p.lineTo(x_stop, y_c + height / 2)
            p.lineTo(x_stop, y_c - height / 2)
            p.lineTo(x_start, y_c - height / 2)
        canvas.drawPath(p, stroke=stroke, fill=fill)

__init__(visualisation_data, parameters)

Create a SequenceVis object.

Parameters:

  • visualisation_data (dict) –

    a dictionary with data needed for visualisation.

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

Source code in uorf4u/drawing_annotation.py
247
248
249
250
251
252
253
254
255
256
def __init__(self, visualisation_data: dict, parameters: uorf4u.manager.Parameters):
    """Create a SequenceVis object.

    Arguments:
        visualisation_data (dict): a dictionary with data needed for visualisation.
        parameters (uorf4u.manager.Parameters): Parameters' class object.

    """
    super().__init__(visualisation_data, parameters)
    self.needed_space = None

draw(canvas)

Draw a Sequence track.

Parameters:

  • canvas (reportlab.pdfgen.canvas.Canvas) –

    a pdf object.

Returns:

  • None

    None

Source code in uorf4u/drawing_annotation.py
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
def draw(self, canvas: reportlab.pdfgen.canvas.Canvas) -> None:
    """Draw a Sequence track.

    Arguments:
        canvas (reportlab.pdfgen.canvas.Canvas): a pdf object.

    Returns:
        None

    """
    orf_height = self.parameters.arguments["orf_height"] * cm
    y_c = self.visualisation_data["y_top"] - 0.5 * orf_height
    x_offset = 0.5 * self.parameters.arguments["upstream_seq_line_width"]
    canvas.setStrokeColorRGB(*uorf4u.methods.get_color("upstream_seq_line_color", self.parameters.arguments))
    canvas.setLineCap(0)
    canvas.setLineWidth(self.parameters.arguments["upstream_seq_line_width"])
    canvas.line(self.visualisation_data["upstream_sequence_line_start_x"], y_c,
                self.visualisation_data["upstream_sequence_line_stop_x"] - x_offset, y_c)
    # Cleaning the space:
    canvas.setFillColorRGB
    canvas.setStrokeColorRGB(1, 1, 1, 1)

    for orf_dict in self.visualisation_data["orfs_coordinates_dict"].values():

        canvas.setLineWidth(self.parameters.arguments["upstream_seq_line_width"]*1.5)
        canvas.line(orf_dict["x_start"], y_c, orf_dict["x_stop"], y_c)
        #canvas.rect(orf_dict["x_start"], y_c - orf_height / 2, orf_dict["x_stop"] - orf_dict["x_start"], orf_height,
        #            stroke=0, fill=1)
    if self.parameters.arguments["check_assembly_annotation"] and \
            "fasta" not in self.parameters.cmd_arguments.keys():
        for protein_id, cds_dict in self.visualisation_data["CDSs_coordinates_dict"].items():
            canvas.line(cds_dict["x_start"], y_c, cds_dict["x_stop"], y_c)
    canvas.setLineWidth(self.parameters.arguments["upstream_seq_line_width"])

    # Labels
    canvas.setFillColorRGB(*uorf4u.methods.get_color("label_color", self.parameters.arguments))
    canvas.setFont("regular", self.visualisation_data["label_font_size"])
    y_l = y_c - 0.5 * (self.parameters.arguments["label_height_to_orf_height"] * orf_height)
    canvas.drawRightString(self.visualisation_data["coordinate_system"]["x_labels_stop"], y_l,
                           self.visualisation_data["useq_label"])

    # main_CDS
    canvas.setLineWidth(self.parameters.arguments["orf_line_width"])
    canvas.setStrokeColorRGB(*uorf4u.methods.get_color("cds_seq_stroke_color", self.parameters.arguments))
    canvas.setFillColorRGB(*uorf4u.methods.get_color("cds_seq_fill_color", self.parameters.arguments))
    p = canvas.beginPath()
    p.moveTo(self.visualisation_data["main_CDS_stop_x"], y_c - orf_height / 2)
    p.lineTo(self.visualisation_data["main_CDS_start_x"], y_c - orf_height / 2)
    p.lineTo(self.visualisation_data["main_CDS_start_x"], y_c + orf_height / 2)
    p.lineTo(self.visualisation_data["main_CDS_stop_x"], y_c + orf_height / 2)
    canvas.drawPath(p, stroke=1, fill=1)
    # Other ORFs:
    for orf in self.visualisation_data["annotated_orfs"]:
        orf_dict = self.visualisation_data["orfs_coordinates_dict"][orf]
        if orf != self.visualisation_data["conserved_orf"]:
            fill_color = None
            stroke_color = uorf4u.methods.get_color("other_uorfs_stroke_color", self.parameters.arguments)

        else:
            fill_color = uorf4u.methods.get_color("conserved_uorfs_fill_color", self.parameters.arguments)
            stroke_color = uorf4u.methods.get_color("conserved_uorfs_stroke_color", self.parameters.arguments)
        self.orf_object(canvas, orf_dict["x_start"], orf_dict["x_stop"], y_c, orf_dict["strand"], orf_height,
                        orf_dict["left_out"], orf_dict["right_out"], fill_color, stroke_color)

    # Annotated in RefSeq CDSs
    if self.parameters.arguments["check_assembly_annotation"] and \
            "fasta" not in self.parameters.cmd_arguments.keys():
        fill_color = None
        stroke_color = uorf4u.methods.get_color("annotated_orf_stroke_color", self.parameters.arguments)
        for protein_id, cds_dict in self.visualisation_data["CDSs_coordinates_dict"].items():
            self.orf_object(canvas, cds_dict["x_start"], cds_dict["x_stop"], y_c, cds_dict["strand"], orf_height,
                            cds_dict["left_out"], cds_dict["right_out"], fill_color, stroke_color)
    return None

needed_y_space()

Calculate needed vertical space for a SequenceVis track.

Returns:

  • float( float ) –

    needed vertical space.

Source code in uorf4u/drawing_annotation.py
258
259
260
261
262
263
264
265
266
def needed_y_space(self) -> float:
    """Calculate needed vertical space for a SequenceVis track.

    Returns:
        float: needed vertical space.

    """
    self.needed_space = self.parameters.arguments["orf_height"] * cm
    return self.needed_space

orf_object(canvas, x_start, x_stop, y_c, strand, height, left_out, right_out, fill_color, stroke_color)

Method for drawing an ORF's polygon.

Parameters:

  • canvas (reportlab.pdfgen.canvas.Canvas) –

    a pdf object.

  • x_start (float) –

    ORF's start coordinate (already transformed to pdf's)

  • x_stop (float) –

    ORF's stop coordinate (already transformed to pdf's)

  • y_c (float) –

    (float): centred y coordinate of a current track.

  • strand (str) –

    strand of an ORF.

  • height (float) –

    height of a polygon.

  • left_out (bool) –

    whether an ORF is out of range on the left.

  • right_out (bool) –

    whether an ORF is out of range on the right.

  • fill_color (str) –

    fill color of a polygon.

  • stroke_color (str) –

    stroke color of a polygon.

Returns:

  • None

    None

Source code in uorf4u/drawing_annotation.py
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
def orf_object(self, canvas: reportlab.pdfgen.canvas.Canvas, x_start: float, x_stop: float, y_c: float, strand: str,
               height: float, left_out: bool, right_out: bool, fill_color: str, stroke_color: str) -> None:
    """Method for drawing an ORF's polygon.

    Arguments:
        canvas (reportlab.pdfgen.canvas.Canvas): a pdf object.
        x_start (float): ORF's start coordinate (already transformed to pdf's)
        x_stop (float): ORF's stop coordinate (already transformed to pdf's)
        y_c: (float): centred y coordinate of a current track.
        strand (str): strand of an ORF.
        height (float): height of a polygon.
        left_out (bool): whether an ORF is out of range on the left.
        right_out (bool): whether an ORF is out of range on the right.
        fill_color (str): fill color of a polygon.
        stroke_color (str): stroke color of a polygon.

    Returns:
        None
    """
    fill, stroke = 0, 0
    if stroke_color:
        canvas.setStrokeColorRGB(*stroke_color)
        stroke = 1
    if fill_color:
        canvas.setFillColorRGB(*fill_color)
        fill = 1
    arrow_length = min(height, (x_stop - x_start))
    p = canvas.beginPath()
    if strand == "+" and not left_out and not right_out:
        p.moveTo(x_start, y_c)
        p.lineTo(x_start, y_c + height / 2)
        p.lineTo(x_stop - arrow_length, y_c + height / 2)
        p.lineTo(x_stop, y_c)
        p.lineTo(x_stop - arrow_length, y_c - height / 2)
        p.lineTo(x_start, y_c - height / 2)
        p.lineTo(x_start, y_c)
    elif strand == "+" and left_out and not right_out:
        p.moveTo(x_start, y_c + height / 2)
        p.lineTo(x_stop - arrow_length, y_c + height / 2)
        p.lineTo(x_stop, y_c)
        p.lineTo(x_stop - arrow_length, y_c - height / 2)
        p.lineTo(x_start, y_c - height / 2)
    elif strand == "+" and right_out and not left_out:
        p.moveTo(x_stop, y_c + height / 2)
        p.lineTo(x_start, y_c + height / 2)
        p.lineTo(x_start, y_c - height / 2)
        p.lineTo(x_stop, y_c - height / 2)
    elif strand == "-" and not left_out and not right_out:
        p.moveTo(x_stop, y_c)
        p.lineTo(x_stop, y_c + height / 2)
        p.lineTo(x_start + arrow_length, y_c + height / 2)
        p.lineTo(x_start, y_c)
        p.lineTo(x_start + arrow_length, y_c - height / 2)
        p.lineTo(x_stop, y_c - height / 2)
        p.lineTo(x_stop, y_c)
    elif strand == "-" and right_out and not left_out:
        p.moveTo(x_stop, y_c + height / 2)
        p.lineTo(x_start + arrow_length, y_c + height / 2)
        p.lineTo(x_start, y_c)
        p.lineTo(x_start + arrow_length, y_c - height / 2)
        p.lineTo(x_stop, y_c - height / 2)
    elif strand == "-" and left_out and not right_out:
        p.moveTo(x_start, y_c + height / 2)
        p.lineTo(x_stop, y_c + height / 2)
        p.lineTo(x_stop, y_c - height / 2)
        p.lineTo(x_start, y_c - height / 2)
    canvas.drawPath(p, stroke=stroke, fill=fill)

SequencesLoader

Bases: Loader

A SequencesLoader object prepares data for a Sequence track object.

Attributes:

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

  • prepared_data (dict) –

    dict with data needed for a visualisation track.

Source code in uorf4u/drawing_annotation.py
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
class SequencesLoader(Loader):
    """A SequencesLoader object prepares data for a Sequence track object.


    Attributes:
        parameters (uorf4u.manager.Parameters): Parameters' class object.
        prepared_data (dict): dict with data needed for a visualisation track.

    """

    def __init__(self, parameters):
        """Create a SequenceLoader object.

        Arguments:
            parameters (uorf4u.manager.Parameters): Parameters' class object.

        """
        super().__init__(parameters)

    def prepare_data(self, upstream_sequence: Bio.SeqRecord.SeqRecord, conserved_orf, coordinate_system: dict,
                     additional_data: dict) -> dict:
        """Prepare data for a Title visualisation track.

        Attributes:
            upstream_sequence (dict): upstream sequence' data.
            conserved_orf (uorf4u.data_processing.ORF): conserved ORF on the upstream sequence.
            coordinate_system (dict): coordinate system of a figure page.
            additional_data (dict): data needed for a track initialisation.

        Returns:
            dict: dictionary with prepared data for visualisation.

        """
        prepared_data = dict()
        max_upstream_sequence_length = additional_data["max_upstream_sequence_length"]
        prepared_data["coordinate_system"] = coordinate_system
        prepared_data["label_font_size"] = additional_data["label_font_size"]
        prepared_data["label_right_border"] = coordinate_system["x_labels_stop"]
        prepared_data["upstream_sequence_line_start_x"] = coordinate_system["x_annotation_start"] + \
                                                          ((max_upstream_sequence_length -
                                                            upstream_sequence.annotations["upstream_region_length"]) * \
                                                           coordinate_system["transformation_coef"])
        prepared_data["upstream_sequence_line_stop_x"] = coordinate_system["x_annotation_start"] + \
                                                         (max_upstream_sequence_length *
                                                          coordinate_system["transformation_coef"])
        prepared_data["main_CDS_start_x"] = coordinate_system["x_annotation_start"] + \
                                            (max_upstream_sequence_length *
                                             coordinate_system["transformation_coef"])
        prepared_data["main_CDS_stop_x"] = coordinate_system["x_annotation_start"] + \
                                           ((max_upstream_sequence_length +
                                             upstream_sequence.annotations["downstream_region_length"]) *
                                            coordinate_system["transformation_coef"])

        prepared_data["orfs_coordinates_dict"] = {k: v for k, v in
                                                  zip(upstream_sequence.annotations["ORFs"],
                                                      [self.calculate_orf_position(i.start, i.stop, "+",
                                                                                   upstream_sequence,
                                                                                   max_upstream_sequence_length,
                                                                                   coordinate_system) for i in
                                                       upstream_sequence.annotations["ORFs"]])}
        prepared_data["useq_label"] = upstream_sequence.annotations["label"]
        prepared_data["annotated_orfs"] = [orf for orf in upstream_sequence.annotations["ORFs"] if orf != conserved_orf]
        prepared_data["annotated_orfs"].append(conserved_orf)
        prepared_data["conserved_orf"] = conserved_orf
        if self.parameters.arguments["check_assembly_annotation"] and upstream_sequence.annotations["RefSeq"]:
            prepared_data["CDSs"] = [i for i in upstream_sequence.annotations["locus_annotation"].CDSs if
                                     i["relative_start"] != upstream_sequence.annotations["upstream_region_length"]]
            prepared_data["CDSs_coordinates_dict"] = {k: v for k, v in
                                                      zip([i["protein_id"] for i in
                                                           prepared_data["CDSs"]],
                                                          [self.calculate_orf_position(i["relative_start"],
                                                                                       i["relative_stop"],
                                                                                       i["relative_strand"],
                                                                                       upstream_sequence,
                                                                                       max_upstream_sequence_length,
                                                                                       coordinate_system) for i in
                                                           prepared_data["CDSs"]])}
        else:
            prepared_data["CDSs"] = None
        self.prepared_data = prepared_data

        return prepared_data

    def calculate_orf_position(self, start: int, stop: int, strand: str, useq: Bio.SeqRecord.SeqRecord,
                               max_upstream_sequence_length: int, coordinate_system: dict) -> dict:
        """Transform an ORF's nucleotide coordinates to pdf's coordinates.

        Arguments:
            start (int): start coordinate in nt.
            stop (int): stop coordinate in nt.
            strand (str): strand of an ORF.
            useq (dict): current upstream sequence.
            max_upstream_sequence_length (int): max length of upstream sequences for visualisation.
            coordinate_system (dict): coordinate system of a figure.

        Returns:
            dict: transformed orf's coordinates.
        """
        orf_coordinates = dict()
        orf_coordinates["x_start"] = coordinate_system["x_annotation_start"] + (
                max(0, start) + (max_upstream_sequence_length - useq.annotations["upstream_region_length"])) * \
                                     coordinate_system["transformation_coef"]
        orf_coordinates["x_stop"] = coordinate_system["x_annotation_start"] + (
                min(stop, useq.annotations["length"]) + (
                max_upstream_sequence_length - useq.annotations["upstream_region_length"])) * \
                                    coordinate_system["transformation_coef"]
        orf_coordinates["strand"] = strand
        orf_coordinates["left_out"] = start < 0
        orf_coordinates["right_out"] = stop > useq.annotations["length"]
        return orf_coordinates

    def create_track(self) -> SequenceVis:
        """Initialise a Sequence track object.

        Returns:
            SequenceVis: visualisation track.

        """
        return SequenceVis(self.prepared_data, self.parameters)

__init__(parameters)

Create a SequenceLoader object.

Parameters:

Source code in uorf4u/drawing_annotation.py
585
586
587
588
589
590
591
592
def __init__(self, parameters):
    """Create a SequenceLoader object.

    Arguments:
        parameters (uorf4u.manager.Parameters): Parameters' class object.

    """
    super().__init__(parameters)

calculate_orf_position(start, stop, strand, useq, max_upstream_sequence_length, coordinate_system)

Transform an ORF's nucleotide coordinates to pdf's coordinates.

Parameters:

  • start (int) –

    start coordinate in nt.

  • stop (int) –

    stop coordinate in nt.

  • strand (str) –

    strand of an ORF.

  • useq (dict) –

    current upstream sequence.

  • max_upstream_sequence_length (int) –

    max length of upstream sequences for visualisation.

  • coordinate_system (dict) –

    coordinate system of a figure.

Returns:

  • dict( dict ) –

    transformed orf's coordinates.

Source code in uorf4u/drawing_annotation.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
def calculate_orf_position(self, start: int, stop: int, strand: str, useq: Bio.SeqRecord.SeqRecord,
                           max_upstream_sequence_length: int, coordinate_system: dict) -> dict:
    """Transform an ORF's nucleotide coordinates to pdf's coordinates.

    Arguments:
        start (int): start coordinate in nt.
        stop (int): stop coordinate in nt.
        strand (str): strand of an ORF.
        useq (dict): current upstream sequence.
        max_upstream_sequence_length (int): max length of upstream sequences for visualisation.
        coordinate_system (dict): coordinate system of a figure.

    Returns:
        dict: transformed orf's coordinates.
    """
    orf_coordinates = dict()
    orf_coordinates["x_start"] = coordinate_system["x_annotation_start"] + (
            max(0, start) + (max_upstream_sequence_length - useq.annotations["upstream_region_length"])) * \
                                 coordinate_system["transformation_coef"]
    orf_coordinates["x_stop"] = coordinate_system["x_annotation_start"] + (
            min(stop, useq.annotations["length"]) + (
            max_upstream_sequence_length - useq.annotations["upstream_region_length"])) * \
                                coordinate_system["transformation_coef"]
    orf_coordinates["strand"] = strand
    orf_coordinates["left_out"] = start < 0
    orf_coordinates["right_out"] = stop > useq.annotations["length"]
    return orf_coordinates

create_track()

Initialise a Sequence track object.

Returns:

Source code in uorf4u/drawing_annotation.py
686
687
688
689
690
691
692
693
def create_track(self) -> SequenceVis:
    """Initialise a Sequence track object.

    Returns:
        SequenceVis: visualisation track.

    """
    return SequenceVis(self.prepared_data, self.parameters)

prepare_data(upstream_sequence, conserved_orf, coordinate_system, additional_data)

Prepare data for a Title visualisation track.

Attributes:

  • upstream_sequence (dict) –

    upstream sequence' data.

  • conserved_orf (uorf4u.data_processing.ORF) –

    conserved ORF on the upstream sequence.

  • coordinate_system (dict) –

    coordinate system of a figure page.

  • additional_data (dict) –

    data needed for a track initialisation.

Returns:

  • dict( dict ) –

    dictionary with prepared data for visualisation.

Source code in uorf4u/drawing_annotation.py
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
def prepare_data(self, upstream_sequence: Bio.SeqRecord.SeqRecord, conserved_orf, coordinate_system: dict,
                 additional_data: dict) -> dict:
    """Prepare data for a Title visualisation track.

    Attributes:
        upstream_sequence (dict): upstream sequence' data.
        conserved_orf (uorf4u.data_processing.ORF): conserved ORF on the upstream sequence.
        coordinate_system (dict): coordinate system of a figure page.
        additional_data (dict): data needed for a track initialisation.

    Returns:
        dict: dictionary with prepared data for visualisation.

    """
    prepared_data = dict()
    max_upstream_sequence_length = additional_data["max_upstream_sequence_length"]
    prepared_data["coordinate_system"] = coordinate_system
    prepared_data["label_font_size"] = additional_data["label_font_size"]
    prepared_data["label_right_border"] = coordinate_system["x_labels_stop"]
    prepared_data["upstream_sequence_line_start_x"] = coordinate_system["x_annotation_start"] + \
                                                      ((max_upstream_sequence_length -
                                                        upstream_sequence.annotations["upstream_region_length"]) * \
                                                       coordinate_system["transformation_coef"])
    prepared_data["upstream_sequence_line_stop_x"] = coordinate_system["x_annotation_start"] + \
                                                     (max_upstream_sequence_length *
                                                      coordinate_system["transformation_coef"])
    prepared_data["main_CDS_start_x"] = coordinate_system["x_annotation_start"] + \
                                        (max_upstream_sequence_length *
                                         coordinate_system["transformation_coef"])
    prepared_data["main_CDS_stop_x"] = coordinate_system["x_annotation_start"] + \
                                       ((max_upstream_sequence_length +
                                         upstream_sequence.annotations["downstream_region_length"]) *
                                        coordinate_system["transformation_coef"])

    prepared_data["orfs_coordinates_dict"] = {k: v for k, v in
                                              zip(upstream_sequence.annotations["ORFs"],
                                                  [self.calculate_orf_position(i.start, i.stop, "+",
                                                                               upstream_sequence,
                                                                               max_upstream_sequence_length,
                                                                               coordinate_system) for i in
                                                   upstream_sequence.annotations["ORFs"]])}
    prepared_data["useq_label"] = upstream_sequence.annotations["label"]
    prepared_data["annotated_orfs"] = [orf for orf in upstream_sequence.annotations["ORFs"] if orf != conserved_orf]
    prepared_data["annotated_orfs"].append(conserved_orf)
    prepared_data["conserved_orf"] = conserved_orf
    if self.parameters.arguments["check_assembly_annotation"] and upstream_sequence.annotations["RefSeq"]:
        prepared_data["CDSs"] = [i for i in upstream_sequence.annotations["locus_annotation"].CDSs if
                                 i["relative_start"] != upstream_sequence.annotations["upstream_region_length"]]
        prepared_data["CDSs_coordinates_dict"] = {k: v for k, v in
                                                  zip([i["protein_id"] for i in
                                                       prepared_data["CDSs"]],
                                                      [self.calculate_orf_position(i["relative_start"],
                                                                                   i["relative_stop"],
                                                                                   i["relative_strand"],
                                                                                   upstream_sequence,
                                                                                   max_upstream_sequence_length,
                                                                                   coordinate_system) for i in
                                                       prepared_data["CDSs"]])}
    else:
        prepared_data["CDSs"] = None
    self.prepared_data = prepared_data

    return prepared_data

TicsVis

Bases: Track

TicsVis track draws axis tics.

Attributes:

  • visualisation_data (dict) –

    a dictionary with data needed for visualisation.

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

  • needed_space (float) –

    needed vertical space for a track.

Source code in uorf4u/drawing_annotation.py
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
class TicsVis(Track):
    """TicsVis track draws axis tics.

    Attributes:
        visualisation_data (dict): a dictionary with data needed for visualisation.
        parameters (uorf4u.manager.Parameters): Parameters' class object.
        needed_space (float): needed vertical space for a track.

    """

    def __init__(self, visualisation_data: dict, parameters: uorf4u.manager.Parameters):
        """Create a TicsVis object.

        Arguments:
            visualisation_data (dict): a dictionary with data needed for visualisation.
            parameters (uorf4u.manager.Parameters): Parameters' class object.

        """
        super().__init__(visualisation_data, parameters)
        self.needed_space = None

    def needed_y_space(self) -> float:
        """Calculate needed vertical space for a SequenceVis track.

        Returns:
            float: needed vertical space.

        """
        font_type = "regular"
        reportlab.pdfbase.pdfmetrics.registerFont(
            reportlab.pdfbase.ttfonts.TTFont(font_type, self.parameters.arguments[f"font_{font_type}"]))
        face = reportlab.pdfbase.pdfmetrics.getFont("regular").face
        if self.parameters.arguments["axis_tics_font_size"] == "auto":
            text_height = self.parameters.arguments["label_height_to_orf_height"] * self.parameters.arguments[
                "orf_height"] * cm
            font_size = uorf4u.methods.string_height_to_font_size(text_height, "regular", self.parameters.arguments)
            self.parameters.arguments["axis_tics_font_size"] = font_size
        else:
            text_height = (self.parameters.arguments["axis_tics_font_size"] * (face.ascent - face.descent)) / (
                    1000 * 1.38)
        self.visualisation_data["tics_height"] = 0.7 * text_height
        self.visualisation_data["text_space"] = 1.2 * text_height
        self.needed_space = self.visualisation_data["tics_height"] + self.visualisation_data["text_space"]
        return self.needed_space

    def draw(self, canvas: reportlab.pdfgen.canvas.Canvas) -> None:
        """Draw an AxisTics track.

        Arguments:
            canvas (reportlab.pdfgen.canvas.Canvas): a pdf object.

        Returns:
            None

        """
        y_top = self.visualisation_data["y_top"]
        canvas.setLineCap(2)
        canvas.setLineWidth(self.parameters.arguments["axis_tics_line_width"])
        canvas.setStrokeColorRGB(*uorf4u.methods.get_color("label_color", self.parameters.arguments))
        canvas.setFillColorRGB(*uorf4u.methods.get_color("label_color", self.parameters.arguments))
        canvas.setFont("regular", self.parameters.arguments["axis_tics_font_size"])
        canvas.line(self.visualisation_data["coordinate_system"]["x_annotation_start"], y_top,
                    self.visualisation_data["coordinate_system"]["x_annotation_stop"], y_top)
        for tic_label, tic_position in self.visualisation_data["tics"].items():
            canvas.line(tic_position, y_top, tic_position, y_top - self.visualisation_data["tics_height"])
            if tic_label == -self.visualisation_data["max_upstream_sequence_length"]:
                canvas.drawString(tic_position,
                                  y_top - (self.visualisation_data["tics_height"] + self.visualisation_data[
                                      "text_space"]), str(tic_label))
            elif tic_label == self.visualisation_data["max_downstream_sequence_length"]:
                canvas.drawRightString(tic_position,
                                       y_top - (self.visualisation_data["tics_height"] + self.visualisation_data[
                                           "text_space"]), str(tic_label))
            else:
                canvas.drawCentredString(tic_position,
                                         y_top - (self.visualisation_data["tics_height"] + self.visualisation_data[
                                             "text_space"]), str(tic_label))

__init__(visualisation_data, parameters)

Create a TicsVis object.

Parameters:

  • visualisation_data (dict) –

    a dictionary with data needed for visualisation.

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

Source code in uorf4u/drawing_annotation.py
421
422
423
424
425
426
427
428
429
430
def __init__(self, visualisation_data: dict, parameters: uorf4u.manager.Parameters):
    """Create a TicsVis object.

    Arguments:
        visualisation_data (dict): a dictionary with data needed for visualisation.
        parameters (uorf4u.manager.Parameters): Parameters' class object.

    """
    super().__init__(visualisation_data, parameters)
    self.needed_space = None

draw(canvas)

Draw an AxisTics track.

Parameters:

  • canvas (reportlab.pdfgen.canvas.Canvas) –

    a pdf object.

Returns:

  • None

    None

Source code in uorf4u/drawing_annotation.py
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
def draw(self, canvas: reportlab.pdfgen.canvas.Canvas) -> None:
    """Draw an AxisTics track.

    Arguments:
        canvas (reportlab.pdfgen.canvas.Canvas): a pdf object.

    Returns:
        None

    """
    y_top = self.visualisation_data["y_top"]
    canvas.setLineCap(2)
    canvas.setLineWidth(self.parameters.arguments["axis_tics_line_width"])
    canvas.setStrokeColorRGB(*uorf4u.methods.get_color("label_color", self.parameters.arguments))
    canvas.setFillColorRGB(*uorf4u.methods.get_color("label_color", self.parameters.arguments))
    canvas.setFont("regular", self.parameters.arguments["axis_tics_font_size"])
    canvas.line(self.visualisation_data["coordinate_system"]["x_annotation_start"], y_top,
                self.visualisation_data["coordinate_system"]["x_annotation_stop"], y_top)
    for tic_label, tic_position in self.visualisation_data["tics"].items():
        canvas.line(tic_position, y_top, tic_position, y_top - self.visualisation_data["tics_height"])
        if tic_label == -self.visualisation_data["max_upstream_sequence_length"]:
            canvas.drawString(tic_position,
                              y_top - (self.visualisation_data["tics_height"] + self.visualisation_data[
                                  "text_space"]), str(tic_label))
        elif tic_label == self.visualisation_data["max_downstream_sequence_length"]:
            canvas.drawRightString(tic_position,
                                   y_top - (self.visualisation_data["tics_height"] + self.visualisation_data[
                                       "text_space"]), str(tic_label))
        else:
            canvas.drawCentredString(tic_position,
                                     y_top - (self.visualisation_data["tics_height"] + self.visualisation_data[
                                         "text_space"]), str(tic_label))

needed_y_space()

Calculate needed vertical space for a SequenceVis track.

Returns:

  • float( float ) –

    needed vertical space.

Source code in uorf4u/drawing_annotation.py
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
def needed_y_space(self) -> float:
    """Calculate needed vertical space for a SequenceVis track.

    Returns:
        float: needed vertical space.

    """
    font_type = "regular"
    reportlab.pdfbase.pdfmetrics.registerFont(
        reportlab.pdfbase.ttfonts.TTFont(font_type, self.parameters.arguments[f"font_{font_type}"]))
    face = reportlab.pdfbase.pdfmetrics.getFont("regular").face
    if self.parameters.arguments["axis_tics_font_size"] == "auto":
        text_height = self.parameters.arguments["label_height_to_orf_height"] * self.parameters.arguments[
            "orf_height"] * cm
        font_size = uorf4u.methods.string_height_to_font_size(text_height, "regular", self.parameters.arguments)
        self.parameters.arguments["axis_tics_font_size"] = font_size
    else:
        text_height = (self.parameters.arguments["axis_tics_font_size"] * (face.ascent - face.descent)) / (
                1000 * 1.38)
    self.visualisation_data["tics_height"] = 0.7 * text_height
    self.visualisation_data["text_space"] = 1.2 * text_height
    self.needed_space = self.visualisation_data["tics_height"] + self.visualisation_data["text_space"]
    return self.needed_space

TitleLoader

Bases: Loader

A TitleLoader object prepares data for a Title track object.

Note:

Title track currently is not available.

Attributes:

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

  • prepared_data (dict) –

    dict with data needed for a visualisation track.

Source code in uorf4u/drawing_annotation.py
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
class TitleLoader(Loader):
    """A TitleLoader object prepares data for a Title track object.

    Note:
        Title track currently is not available.

    Attributes:
        parameters (uorf4u.manager.Parameters): Parameters' class object.
        prepared_data (dict): dict with data needed for a visualisation track.

    """

    def __init__(self, parameters):
        """Create a TitleLoader object.

        Arguments:
            parameters (uorf4u.manager.Parameters): Parameters' class object.

        """
        super().__init__(parameters)

    def prepare_data(self, coordinate_system: dict, additional_data: dict) -> dict:
        """Prepare data for Title visualisation track.

        Attributes:
            coordinate_system (dict): coordinate system of a figure page.
            additional_data (dict): data needed for a track initialisation.

        Returns:
            dict: dictionary with prepared data for visualisation.

        """
        prepared_data = dict()
        prepared_data["title"] = "Title Testing"
        prepared_data["coordinate_system"] = coordinate_system
        self.prepared_data = prepared_data
        return prepared_data

    def create_track(self) -> TitleVis:
        """Initialise a Title track object.

        Returns:
            TitleVis: visualisation track.

        """
        return TitleVis(self.prepared_data, self.parameters)

__init__(parameters)

Create a TitleLoader object.

Parameters:

Source code in uorf4u/drawing_annotation.py
539
540
541
542
543
544
545
546
def __init__(self, parameters):
    """Create a TitleLoader object.

    Arguments:
        parameters (uorf4u.manager.Parameters): Parameters' class object.

    """
    super().__init__(parameters)

create_track()

Initialise a Title track object.

Returns:

  • TitleVis( TitleVis ) –

    visualisation track.

Source code in uorf4u/drawing_annotation.py
565
566
567
568
569
570
571
572
def create_track(self) -> TitleVis:
    """Initialise a Title track object.

    Returns:
        TitleVis: visualisation track.

    """
    return TitleVis(self.prepared_data, self.parameters)

prepare_data(coordinate_system, additional_data)

Prepare data for Title visualisation track.

Attributes:

  • coordinate_system (dict) –

    coordinate system of a figure page.

  • additional_data (dict) –

    data needed for a track initialisation.

Returns:

  • dict( dict ) –

    dictionary with prepared data for visualisation.

Source code in uorf4u/drawing_annotation.py
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
def prepare_data(self, coordinate_system: dict, additional_data: dict) -> dict:
    """Prepare data for Title visualisation track.

    Attributes:
        coordinate_system (dict): coordinate system of a figure page.
        additional_data (dict): data needed for a track initialisation.

    Returns:
        dict: dictionary with prepared data for visualisation.

    """
    prepared_data = dict()
    prepared_data["title"] = "Title Testing"
    prepared_data["coordinate_system"] = coordinate_system
    self.prepared_data = prepared_data
    return prepared_data

TitleVis

Bases: Track

Title visualisation track object draws figure's title.

Note:

This track currently is not supported.

Attributes:

  • visualisation_data (dict) –

    a dictionary with data needed for visualisation.

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

Source code in uorf4u/drawing_annotation.py
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
class TitleVis(Track):
    """Title visualisation track object draws figure's title.

    Note:
        This track currently is not supported.

    Attributes:
        visualisation_data (dict): a dictionary with data needed for visualisation.
        parameters (uorf4u.manager.Parameters): Parameters' class object.

    """

    def __init__(self, visualisation_data: dict, parameters: uorf4u.manager.Parameters):
        """Create TitleVis object.

        Arguments:
            visualisation_data (dict): a dictionary with data needed for visualisation.
            parameters (uorf4u.manager.Parameters): Parameters' class object.

        """
        self.visualisation_data = visualisation_data
        self.parameters = parameters

    def needed_y_space(self) -> float:
        """Calculate needed vertical space for a Title track.

        Returns:
            float: needed vertical space.

        """
        font_type = self.parameters.arguments["title_font_type"]
        reportlab.pdfbase.pdfmetrics.registerFont(
            reportlab.pdfbase.ttfonts.TTFont(font_type, self.parameters.arguments[f"font_{font_type}"]))
        face = reportlab.pdfbase.pdfmetrics.getFont(font_type).face
        if self.parameters.arguments["title_font_size"] == "auto":
            text_height = self.parameters.arguments["orf_height"] * cm
            font_size = uorf4u.methods.string_height_to_font_size(text_height, font_type, self.parameters.arguments)
            self.parameters.arguments["title_font_size"] = font_size
        else:
            text_height = (self.parameters.arguments["title_font_size"] * (face.ascent - face.descent)) / (
                    1000 * 1.38)
        self.visualisation_data["text_height"] = text_height
        self.needed_space = text_height * 1.2
        return self.needed_space

    def draw(self, canvas: reportlab.pdfgen.canvas.Canvas) -> None:
        """Draw a Title track.

        Arguments:
            canvas (reportlab.pdfgen.canvas.Canvas): a pdf object.

        Returns:
            None

        """
        x_left_border = self.visualisation_data["coordinate_system"]["x_labels_start"]
        # x_left_border = self.visualisation_data["coordinate_system"]["x_annotation_start"]
        canvas.setFillColorRGB(*uorf4u.methods.get_color("label_color", self.parameters.arguments))
        canvas.setFont(self.parameters.arguments["title_font_type"], self.parameters.arguments["title_font_size"])
        canvas.drawString(x_left_border, self.visualisation_data["y_top"] - self.visualisation_data["text_height"],
                          self.visualisation_data["title"])

__init__(visualisation_data, parameters)

Create TitleVis object.

Parameters:

  • visualisation_data (dict) –

    a dictionary with data needed for visualisation.

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

Source code in uorf4u/drawing_annotation.py
186
187
188
189
190
191
192
193
194
195
def __init__(self, visualisation_data: dict, parameters: uorf4u.manager.Parameters):
    """Create TitleVis object.

    Arguments:
        visualisation_data (dict): a dictionary with data needed for visualisation.
        parameters (uorf4u.manager.Parameters): Parameters' class object.

    """
    self.visualisation_data = visualisation_data
    self.parameters = parameters

draw(canvas)

Draw a Title track.

Parameters:

  • canvas (reportlab.pdfgen.canvas.Canvas) –

    a pdf object.

Returns:

  • None

    None

Source code in uorf4u/drawing_annotation.py
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
def draw(self, canvas: reportlab.pdfgen.canvas.Canvas) -> None:
    """Draw a Title track.

    Arguments:
        canvas (reportlab.pdfgen.canvas.Canvas): a pdf object.

    Returns:
        None

    """
    x_left_border = self.visualisation_data["coordinate_system"]["x_labels_start"]
    # x_left_border = self.visualisation_data["coordinate_system"]["x_annotation_start"]
    canvas.setFillColorRGB(*uorf4u.methods.get_color("label_color", self.parameters.arguments))
    canvas.setFont(self.parameters.arguments["title_font_type"], self.parameters.arguments["title_font_size"])
    canvas.drawString(x_left_border, self.visualisation_data["y_top"] - self.visualisation_data["text_height"],
                      self.visualisation_data["title"])

needed_y_space()

Calculate needed vertical space for a Title track.

Returns:

  • float( float ) –

    needed vertical space.

Source code in uorf4u/drawing_annotation.py
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
def needed_y_space(self) -> float:
    """Calculate needed vertical space for a Title track.

    Returns:
        float: needed vertical space.

    """
    font_type = self.parameters.arguments["title_font_type"]
    reportlab.pdfbase.pdfmetrics.registerFont(
        reportlab.pdfbase.ttfonts.TTFont(font_type, self.parameters.arguments[f"font_{font_type}"]))
    face = reportlab.pdfbase.pdfmetrics.getFont(font_type).face
    if self.parameters.arguments["title_font_size"] == "auto":
        text_height = self.parameters.arguments["orf_height"] * cm
        font_size = uorf4u.methods.string_height_to_font_size(text_height, font_type, self.parameters.arguments)
        self.parameters.arguments["title_font_size"] = font_size
    else:
        text_height = (self.parameters.arguments["title_font_size"] * (face.ascent - face.descent)) / (
                1000 * 1.38)
    self.visualisation_data["text_height"] = text_height
    self.needed_space = text_height * 1.2
    return self.needed_space

Track

Parent clas for visualisation Tracks.

Attributes:

  • visualisation_data (dict) –

    a dictionary with data needed for visualisation.

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

Source code in uorf4u/drawing_annotation.py
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
class Track:
    """Parent clas for visualisation Tracks.

    Attributes:
        visualisation_data (dict): a dictionary with data needed for visualisation.
        parameters (uorf4u.manager.Parameters): Parameters' class object.

    """

    def __init__(self, visualisation_data: dict, parameters: uorf4u.manager.Parameters):
        """Parent's constructor for creating a Track object.

        Arguments:
            visualisation_data (dict): a dictionary with data needed for visualisation.
            parameters (uorf4u.manager.Parameters): Parameters' class object.

        """
        self.visualisation_data = visualisation_data
        self.parameters = parameters

    def needed_y_space(self) -> None:
        """Empy parent's method for calculation needed vertical space for a track.

        Returns:
            None

        """
        pass

    def draw(self, canvas: reportlab.pdfgen.canvas.Canvas) -> None:
        """Empy parent's method for track visualisation.

        Arguments:
            canvas (reportlab.pdfgen.canvas.Canvas): a pdf object.

        Returns:
            None
        """
        pass

__init__(visualisation_data, parameters)

Parent's constructor for creating a Track object.

Parameters:

  • visualisation_data (dict) –

    a dictionary with data needed for visualisation.

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

Source code in uorf4u/drawing_annotation.py
142
143
144
145
146
147
148
149
150
151
def __init__(self, visualisation_data: dict, parameters: uorf4u.manager.Parameters):
    """Parent's constructor for creating a Track object.

    Arguments:
        visualisation_data (dict): a dictionary with data needed for visualisation.
        parameters (uorf4u.manager.Parameters): Parameters' class object.

    """
    self.visualisation_data = visualisation_data
    self.parameters = parameters

draw(canvas)

Empy parent's method for track visualisation.

Parameters:

  • canvas (reportlab.pdfgen.canvas.Canvas) –

    a pdf object.

Returns:

  • None

    None

Source code in uorf4u/drawing_annotation.py
162
163
164
165
166
167
168
169
170
171
def draw(self, canvas: reportlab.pdfgen.canvas.Canvas) -> None:
    """Empy parent's method for track visualisation.

    Arguments:
        canvas (reportlab.pdfgen.canvas.Canvas): a pdf object.

    Returns:
        None
    """
    pass

needed_y_space()

Empy parent's method for calculation needed vertical space for a track.

Returns:

  • None

    None

Source code in uorf4u/drawing_annotation.py
153
154
155
156
157
158
159
160
def needed_y_space(self) -> None:
    """Empy parent's method for calculation needed vertical space for a track.

    Returns:
        None

    """
    pass

This module provides visualisation of loci annotation.

Image

An Image object holds pdf.

Attributes:

  • canvas (reportlab.pdfgen.canvas.Canvas) –

    pdf object of the reportlab library.

Source code in uorf4u/drawing_msa.py
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
class Image:
    """An Image object holds pdf.

    Attributes:
        canvas (reportlab.pdfgen.canvas.Canvas): pdf object of the reportlab library.

    """

    def __init__(self, filename: str, width: float, height: float):
        """Create an Image object.

        Arguments:
            filename (str): path and name of a pdf.
            width (float): width of a pdf.
            height (float): height of a pdf.

        """
        self.canvas = reportlab.pdfgen.canvas.Canvas(filename, pagesize=(width, height))

    def save(self) -> None:
        """Save a pdf file.

        Returns:
            None

        """
        self.canvas.save()
        return None

__init__(filename, width, height)

Create an Image object.

Parameters:

  • filename (str) –

    path and name of a pdf.

  • width (float) –

    width of a pdf.

  • height (float) –

    height of a pdf.

Source code in uorf4u/drawing_msa.py
335
336
337
338
339
340
341
342
343
344
def __init__(self, filename: str, width: float, height: float):
    """Create an Image object.

    Arguments:
        filename (str): path and name of a pdf.
        width (float): width of a pdf.
        height (float): height of a pdf.

    """
    self.canvas = reportlab.pdfgen.canvas.Canvas(filename, pagesize=(width, height))

save()

Save a pdf file.

Returns:

  • None

    None

Source code in uorf4u/drawing_msa.py
346
347
348
349
350
351
352
353
354
def save(self) -> None:
    """Save a pdf file.

    Returns:
        None

    """
    self.canvas.save()
    return None

Loader

Parent class for tracks loaders.

Attributes:

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

  • prepared_data (dict) –

    dict with data needed for visualisation tracks.

Source code in uorf4u/drawing_msa.py
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
class Loader:
    """Parent class for tracks loaders.

    Attributes:
        parameters (uorf4u.manager.Parameters): Parameters' class object.
        prepared_data (dict): dict with data needed for visualisation tracks.

    """

    def __init__(self, parameters: uorf4u.manager.Parameters):
        """Parent's constructor for creating a Loader class object.

        Arguments:
            parameters (uorf4u.manager.Parameters): Parameters' class object.
        """
        self.parameters = parameters
        self.prepared_data = None

    def prepare_data(self) -> None:
        """Empty parent's method for data preparation.

        Returns:
            None

        """
        pass

    def create_track(self) -> None:
        """Empty parent's method for initialisation of a track.

        Returns:
            None

        """
        pass

__init__(parameters)

Parent's constructor for creating a Loader class object.

Parameters:

Source code in uorf4u/drawing_msa.py
245
246
247
248
249
250
251
252
def __init__(self, parameters: uorf4u.manager.Parameters):
    """Parent's constructor for creating a Loader class object.

    Arguments:
        parameters (uorf4u.manager.Parameters): Parameters' class object.
    """
    self.parameters = parameters
    self.prepared_data = None

create_track()

Empty parent's method for initialisation of a track.

Returns:

  • None

    None

Source code in uorf4u/drawing_msa.py
263
264
265
266
267
268
269
270
def create_track(self) -> None:
    """Empty parent's method for initialisation of a track.

    Returns:
        None

    """
    pass

prepare_data()

Empty parent's method for data preparation.

Returns:

  • None

    None

Source code in uorf4u/drawing_msa.py
254
255
256
257
258
259
260
261
def prepare_data(self) -> None:
    """Empty parent's method for data preparation.

    Returns:
        None

    """
    pass

MSAPlotManager

AnnotationPlotManager object holds needed information for annotation visualisation and controls it.

Note:

It's supposed that the AnnotationPlotManager' objects will not be used directly by API users since visualisation can be controlled by 'plot_annotation' method.

Attributes:

  • msa (FILL IN) –

    Path class' multiple sequence alignment.

  • upstream_sequences (list) –

    list of dicts with information about upstream sequences.

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

  • coordinate_system (dict) –

    coordinate system of figure.

  • additional_data (dict) –

    dict with data for visualisation tracks.

Source code in uorf4u/drawing_msa.py
 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
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
class MSAPlotManager:
    """
    AnnotationPlotManager object holds needed information for annotation visualisation and controls it.

    Note:
        It's supposed that the AnnotationPlotManager' objects will not be used directly by API users since
            visualisation can be controlled by 'plot_annotation' method.

    Attributes:
        msa (FILL IN): Path class' multiple sequence alignment.
        upstream_sequences (list): list of dicts with information about upstream sequences.
        parameters (uorf4u.manager.Parameters): Parameters' class object.
        coordinate_system (dict): coordinate system of figure.
        additional_data (dict): dict with data for visualisation tracks.

    """

    def __init__(self, msa, parameters: uorf4u.manager.Parameters, type: str):
        """Create a AnnotationPlotManager object.

        Arguments:
            path (uorf4u.data_processing.Path): Path class' objects that holds list of conserved ORFs.
            upstream_sequences (list): list of dicts with information about upstream sequences.
            parameters (uorf4u.manager.Parameters): Parameters' class object.
            type (str): type of sequences (sd, nt, aa)

        """
        self.msa = msa
        self.parameters = parameters
        self.coordinate_system = dict()
        self.additional_data = dict()
        self.type = type

    def define_x_axis_coordinate_system(self) -> None:
        """Define coordinate system.

        Returns:
            None

        """

        label_height = self.parameters.arguments["label_size"] * self.parameters.arguments["tile_size"] * cm
        label_font_size = uorf4u.methods.string_height_to_font_size(label_height, "regular", self.parameters.arguments)
        self.additional_data["label_font_size"] = label_font_size
        msa_length = self.msa.get_alignment_length()
        max_label_width = max([reportlab.pdfbase.pdfmetrics.stringWidth(i.description, "regular",
                                                                        label_font_size) for i in self.msa])

        char_height = self.parameters.arguments["char_size"] * self.parameters.arguments["tile_size"] * cm
        char_font_size = uorf4u.methods.string_height_to_font_size(char_height, "mono", self.parameters.arguments)
        self.additional_data["char_font_size"] = char_font_size

        self.additional_data["number_of_sequences"] = len(self.msa)
        self.coordinate_system["x_labels_start"] = self.parameters.arguments["margin"] * cm
        self.coordinate_system["x_labels_stop"] = self.coordinate_system["x_labels_start"] + max_label_width
        self.coordinate_system["x_msa_start"] = self.coordinate_system["x_labels_stop"] + \
                                                self.parameters.arguments["label_gap"] * cm
        msa_width = self.parameters.arguments["tile_size"] * msa_length * cm
        self.coordinate_system["x_msa_stop"] = self.coordinate_system["x_msa_start"] + msa_width
        self.coordinate_system["figure_width"] = 2 * self.parameters.arguments["margin"] * cm + msa_width + \
                                                 max_label_width + self.parameters.arguments["label_gap"] * cm
        self.coordinate_system["figure_height"] = self.parameters.arguments["margin"] * cm
        self.additional_data["palette"] = self.parameters.arguments[f"colors_{self.type}"]
        self.additional_data["palette"] = {k: uorf4u.methods.color_name_to_hex(v, self.parameters.arguments) for k, v in
                                           self.additional_data["palette"].items()}

        return None

    def create_tracks(self) -> None:
        """Create visualisation tracks.

        Returns:
            None

        """
        self.tracks = []
        """
        title_loader = TitleLoader(self.parameters)
        title_loader.prepare_data(self.coordinate_system, self.additional_data)
        title_track = title_loader.create_track()
        self.tracks.append(title_track)
        self.coordinate_system["figure_height"] += title_track.needed_y_space()
        """
        for record in self.msa:
            sequence_loader = SequencesLoader(self.parameters)
            sequence_loader.prepare_data(record, self.coordinate_system, self.additional_data)
            track = sequence_loader.create_track()
            self.tracks.append(track)
            self.coordinate_system["figure_height"] += track.needed_y_space()
            # self.coordinate_system["figure_height"] += self.parameters.arguments["gap"] * cm
            # if index < self.additional_data["number_of_sequences"] - 1:
        self.coordinate_system["figure_height"] += self.parameters.arguments["margin"] * cm

    def plot(self, filename):
        image = Image(filename, self.coordinate_system["figure_width"], self.coordinate_system["figure_height"])
        current_y_top = self.coordinate_system["figure_height"] - self.parameters.arguments["margin"] * cm
        for track in self.tracks:
            track.visualisation_data["y_top"] = current_y_top
            track.draw(image.canvas)
            current_y_top -= (track.needed_space)
        image.save()
        return None

__init__(msa, parameters, type)

Create a AnnotationPlotManager object.

Parameters:

  • path (uorf4u.data_processing.Path) –

    Path class' objects that holds list of conserved ORFs.

  • upstream_sequences (list) –

    list of dicts with information about upstream sequences.

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

  • type (str) –

    type of sequences (sd, nt, aa)

Source code in uorf4u/drawing_msa.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def __init__(self, msa, parameters: uorf4u.manager.Parameters, type: str):
    """Create a AnnotationPlotManager object.

    Arguments:
        path (uorf4u.data_processing.Path): Path class' objects that holds list of conserved ORFs.
        upstream_sequences (list): list of dicts with information about upstream sequences.
        parameters (uorf4u.manager.Parameters): Parameters' class object.
        type (str): type of sequences (sd, nt, aa)

    """
    self.msa = msa
    self.parameters = parameters
    self.coordinate_system = dict()
    self.additional_data = dict()
    self.type = type

create_tracks()

Create visualisation tracks.

Returns:

  • None

    None

Source code in uorf4u/drawing_msa.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
def create_tracks(self) -> None:
    """Create visualisation tracks.

    Returns:
        None

    """
    self.tracks = []
    """
    title_loader = TitleLoader(self.parameters)
    title_loader.prepare_data(self.coordinate_system, self.additional_data)
    title_track = title_loader.create_track()
    self.tracks.append(title_track)
    self.coordinate_system["figure_height"] += title_track.needed_y_space()
    """
    for record in self.msa:
        sequence_loader = SequencesLoader(self.parameters)
        sequence_loader.prepare_data(record, self.coordinate_system, self.additional_data)
        track = sequence_loader.create_track()
        self.tracks.append(track)
        self.coordinate_system["figure_height"] += track.needed_y_space()
        # self.coordinate_system["figure_height"] += self.parameters.arguments["gap"] * cm
        # if index < self.additional_data["number_of_sequences"] - 1:
    self.coordinate_system["figure_height"] += self.parameters.arguments["margin"] * cm

define_x_axis_coordinate_system()

Define coordinate system.

Returns:

  • None

    None

Source code in uorf4u/drawing_msa.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def define_x_axis_coordinate_system(self) -> None:
    """Define coordinate system.

    Returns:
        None

    """

    label_height = self.parameters.arguments["label_size"] * self.parameters.arguments["tile_size"] * cm
    label_font_size = uorf4u.methods.string_height_to_font_size(label_height, "regular", self.parameters.arguments)
    self.additional_data["label_font_size"] = label_font_size
    msa_length = self.msa.get_alignment_length()
    max_label_width = max([reportlab.pdfbase.pdfmetrics.stringWidth(i.description, "regular",
                                                                    label_font_size) for i in self.msa])

    char_height = self.parameters.arguments["char_size"] * self.parameters.arguments["tile_size"] * cm
    char_font_size = uorf4u.methods.string_height_to_font_size(char_height, "mono", self.parameters.arguments)
    self.additional_data["char_font_size"] = char_font_size

    self.additional_data["number_of_sequences"] = len(self.msa)
    self.coordinate_system["x_labels_start"] = self.parameters.arguments["margin"] * cm
    self.coordinate_system["x_labels_stop"] = self.coordinate_system["x_labels_start"] + max_label_width
    self.coordinate_system["x_msa_start"] = self.coordinate_system["x_labels_stop"] + \
                                            self.parameters.arguments["label_gap"] * cm
    msa_width = self.parameters.arguments["tile_size"] * msa_length * cm
    self.coordinate_system["x_msa_stop"] = self.coordinate_system["x_msa_start"] + msa_width
    self.coordinate_system["figure_width"] = 2 * self.parameters.arguments["margin"] * cm + msa_width + \
                                             max_label_width + self.parameters.arguments["label_gap"] * cm
    self.coordinate_system["figure_height"] = self.parameters.arguments["margin"] * cm
    self.additional_data["palette"] = self.parameters.arguments[f"colors_{self.type}"]
    self.additional_data["palette"] = {k: uorf4u.methods.color_name_to_hex(v, self.parameters.arguments) for k, v in
                                       self.additional_data["palette"].items()}

    return None

SequenceVis

Bases: Track

SequenceVis track draws sequences and annotation.

Attributes:

  • visualisation_data (dict) –

    a dictionary with data needed for visualisation.

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

  • needed_space (float) –

    needed vertical space for a track.

Source code in uorf4u/drawing_msa.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
class SequenceVis(Track):
    """SequenceVis track draws sequences and annotation.

    Attributes:
        visualisation_data (dict): a dictionary with data needed for visualisation.
        parameters (uorf4u.manager.Parameters): Parameters' class object.
        needed_space (float): needed vertical space for a track.

    """

    def __init__(self, visualisation_data: dict, parameters: uorf4u.manager.Parameters):
        """Create a SequenceVis object.

        Arguments:
            visualisation_data (dict): a dictionary with data needed for visualisation.
            parameters (uorf4u.manager.Parameters): Parameters' class object.

        """
        super().__init__(visualisation_data, parameters)
        self.needed_space = None

    def needed_y_space(self) -> float:
        """Calculate needed vertical space for a SequenceVis track.

        Returns:
            float: needed vertical space.

        """
        self.needed_space = self.parameters.arguments["tile_size"] * cm
        return self.needed_space

    def draw(self, canvas: reportlab.pdfgen.canvas.Canvas) -> None:
        """Draw a Sequence track.

        Arguments:
            canvas (reportlab.pdfgen.canvas.Canvas): a pdf object.

        Returns:
            None

        """
        tile_size = self.parameters.arguments["tile_size"] * cm
        y_c = self.visualisation_data["y_top"] - (tile_size * 0.5)
        y_l = self.visualisation_data["y_top"] - tile_size

        y_gap_label = tile_size * (1 - self.parameters.arguments["label_size"]) * 0.5
        y_gap_char = tile_size * (1 - self.parameters.arguments["char_size"]) * 0.5
        # Labels
        canvas.setFillColorRGB(*uorf4u.methods.get_color("label_color", self.parameters.arguments))
        canvas.setFont("regular", self.visualisation_data["label_font_size"])
        canvas.drawRightString(self.visualisation_data["coordinate_system"]["x_labels_stop"], y_l + y_gap_label,
                               self.visualisation_data["label"])

        canvas.setLineWidth(0.05 * tile_size)
        canvas.setStrokeColorRGB(1, 1, 1)
        canvas.setFont("mono", self.visualisation_data["char_font_size"])
        x = self.visualisation_data['msa_left_border']
        for symbol in self.visualisation_data["sequence"]:
            x_c = x + tile_size * 0.5
            symbol = symbol.upper()
            try:
                color = self.visualisation_data["palette"][symbol]
            except:
                color = "#FFFFFF"
            canvas.setFillColorRGB(*uorf4u.methods.hex_to_rgb(color), self.parameters.arguments["tile_alpha"])
            canvas.rect(x, y_l, tile_size, tile_size, fill=1)
            canvas.setFillColorRGB(0, 0, 0, 0.8)  # to change
            canvas.drawCentredString(x_c, y_l + y_gap_char, symbol)
            x += tile_size

        return None

__init__(visualisation_data, parameters)

Create a SequenceVis object.

Parameters:

  • visualisation_data (dict) –

    a dictionary with data needed for visualisation.

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

Source code in uorf4u/drawing_msa.py
173
174
175
176
177
178
179
180
181
182
def __init__(self, visualisation_data: dict, parameters: uorf4u.manager.Parameters):
    """Create a SequenceVis object.

    Arguments:
        visualisation_data (dict): a dictionary with data needed for visualisation.
        parameters (uorf4u.manager.Parameters): Parameters' class object.

    """
    super().__init__(visualisation_data, parameters)
    self.needed_space = None

draw(canvas)

Draw a Sequence track.

Parameters:

  • canvas (reportlab.pdfgen.canvas.Canvas) –

    a pdf object.

Returns:

  • None

    None

Source code in uorf4u/drawing_msa.py
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
def draw(self, canvas: reportlab.pdfgen.canvas.Canvas) -> None:
    """Draw a Sequence track.

    Arguments:
        canvas (reportlab.pdfgen.canvas.Canvas): a pdf object.

    Returns:
        None

    """
    tile_size = self.parameters.arguments["tile_size"] * cm
    y_c = self.visualisation_data["y_top"] - (tile_size * 0.5)
    y_l = self.visualisation_data["y_top"] - tile_size

    y_gap_label = tile_size * (1 - self.parameters.arguments["label_size"]) * 0.5
    y_gap_char = tile_size * (1 - self.parameters.arguments["char_size"]) * 0.5
    # Labels
    canvas.setFillColorRGB(*uorf4u.methods.get_color("label_color", self.parameters.arguments))
    canvas.setFont("regular", self.visualisation_data["label_font_size"])
    canvas.drawRightString(self.visualisation_data["coordinate_system"]["x_labels_stop"], y_l + y_gap_label,
                           self.visualisation_data["label"])

    canvas.setLineWidth(0.05 * tile_size)
    canvas.setStrokeColorRGB(1, 1, 1)
    canvas.setFont("mono", self.visualisation_data["char_font_size"])
    x = self.visualisation_data['msa_left_border']
    for symbol in self.visualisation_data["sequence"]:
        x_c = x + tile_size * 0.5
        symbol = symbol.upper()
        try:
            color = self.visualisation_data["palette"][symbol]
        except:
            color = "#FFFFFF"
        canvas.setFillColorRGB(*uorf4u.methods.hex_to_rgb(color), self.parameters.arguments["tile_alpha"])
        canvas.rect(x, y_l, tile_size, tile_size, fill=1)
        canvas.setFillColorRGB(0, 0, 0, 0.8)  # to change
        canvas.drawCentredString(x_c, y_l + y_gap_char, symbol)
        x += tile_size

    return None

needed_y_space()

Calculate needed vertical space for a SequenceVis track.

Returns:

  • float( float ) –

    needed vertical space.

Source code in uorf4u/drawing_msa.py
184
185
186
187
188
189
190
191
192
def needed_y_space(self) -> float:
    """Calculate needed vertical space for a SequenceVis track.

    Returns:
        float: needed vertical space.

    """
    self.needed_space = self.parameters.arguments["tile_size"] * cm
    return self.needed_space

SequencesLoader

Bases: Loader

A SequencesLoader object prepares data for a Sequence track object.

Attributes:

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

  • prepared_data (dict) –

    dict with data needed for a visualisation track.

Source code in uorf4u/drawing_msa.py
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
class SequencesLoader(Loader):
    """A SequencesLoader object prepares data for a Sequence track object.


    Attributes:
        parameters (uorf4u.manager.Parameters): Parameters' class object.
        prepared_data (dict): dict with data needed for a visualisation track.

    """

    def __init__(self, parameters):
        """Create a SequenceLoader object.

        Arguments:
            parameters (uorf4u.manager.Parameters): Parameters' class object.

        """
        super().__init__(parameters)

    def prepare_data(self, record, coordinate_system: dict, additional_data: dict) -> dict:
        """Prepare data for a Title visualisation track.

        Attributes:
            record (FILL in): record of blablabla
            coordinate_system (dict): coordinate system of a figure page.
            additional_data (dict): data needed for a track initialisation.

        Returns:
            dict: dictionary with prepared data for visualisation.

        """
        prepared_data = dict()
        prepared_data["coordinate_system"] = coordinate_system
        prepared_data["label_font_size"] = additional_data["label_font_size"]
        prepared_data["char_font_size"] = additional_data["char_font_size"]
        prepared_data["label_right_border"] = coordinate_system["x_labels_stop"]
        prepared_data["msa_left_border"] = coordinate_system["x_msa_start"]
        prepared_data["sequence"] = record.seq
        prepared_data["label"] = record.description
        prepared_data["palette"] = additional_data["palette"]
        self.prepared_data = prepared_data

        return prepared_data

    def create_track(self) -> SequenceVis:
        """Initialise a Sequence track object.

        Returns:
            SequenceVis: visualisation track.

        """
        return SequenceVis(self.prepared_data, self.parameters)

__init__(parameters)

Create a SequenceLoader object.

Parameters:

Source code in uorf4u/drawing_msa.py
283
284
285
286
287
288
289
290
def __init__(self, parameters):
    """Create a SequenceLoader object.

    Arguments:
        parameters (uorf4u.manager.Parameters): Parameters' class object.

    """
    super().__init__(parameters)

create_track()

Initialise a Sequence track object.

Returns:

Source code in uorf4u/drawing_msa.py
317
318
319
320
321
322
323
324
def create_track(self) -> SequenceVis:
    """Initialise a Sequence track object.

    Returns:
        SequenceVis: visualisation track.

    """
    return SequenceVis(self.prepared_data, self.parameters)

prepare_data(record, coordinate_system, additional_data)

Prepare data for a Title visualisation track.

Attributes:

  • record (FILL in) –

    record of blablabla

  • coordinate_system (dict) –

    coordinate system of a figure page.

  • additional_data (dict) –

    data needed for a track initialisation.

Returns:

  • dict( dict ) –

    dictionary with prepared data for visualisation.

Source code in uorf4u/drawing_msa.py
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
def prepare_data(self, record, coordinate_system: dict, additional_data: dict) -> dict:
    """Prepare data for a Title visualisation track.

    Attributes:
        record (FILL in): record of blablabla
        coordinate_system (dict): coordinate system of a figure page.
        additional_data (dict): data needed for a track initialisation.

    Returns:
        dict: dictionary with prepared data for visualisation.

    """
    prepared_data = dict()
    prepared_data["coordinate_system"] = coordinate_system
    prepared_data["label_font_size"] = additional_data["label_font_size"]
    prepared_data["char_font_size"] = additional_data["char_font_size"]
    prepared_data["label_right_border"] = coordinate_system["x_labels_stop"]
    prepared_data["msa_left_border"] = coordinate_system["x_msa_start"]
    prepared_data["sequence"] = record.seq
    prepared_data["label"] = record.description
    prepared_data["palette"] = additional_data["palette"]
    self.prepared_data = prepared_data

    return prepared_data

Track

Parent clas for visualisation Tracks.

Attributes:

  • visualisation_data (dict) –

    a dictionary with data needed for visualisation.

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

Source code in uorf4u/drawing_msa.py
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
class Track:
    """Parent clas for visualisation Tracks.

    Attributes:
        visualisation_data (dict): a dictionary with data needed for visualisation.
        parameters (uorf4u.manager.Parameters): Parameters' class object.

    """

    def __init__(self, visualisation_data: dict, parameters: uorf4u.manager.Parameters):
        """Parent's constructor for creating a Track object.

        Arguments:
            visualisation_data (dict): a dictionary with data needed for visualisation.
            parameters (uorf4u.manager.Parameters): Parameters' class object.

        """
        self.visualisation_data = visualisation_data
        self.parameters = parameters

    def needed_y_space(self) -> None:
        """Empy parent's method for calculation needed vertical space for a track.

        Returns:
            None

        """
        pass

    def draw(self, canvas: reportlab.pdfgen.canvas.Canvas) -> None:
        """Empy parent's method for track visualisation.

        Arguments:
            canvas (reportlab.pdfgen.canvas.Canvas): a pdf object.

        Returns:
            None
        """
        pass

__init__(visualisation_data, parameters)

Parent's constructor for creating a Track object.

Parameters:

  • visualisation_data (dict) –

    a dictionary with data needed for visualisation.

  • parameters (uorf4u.manager.Parameters) –

    Parameters' class object.

Source code in uorf4u/drawing_msa.py
131
132
133
134
135
136
137
138
139
140
def __init__(self, visualisation_data: dict, parameters: uorf4u.manager.Parameters):
    """Parent's constructor for creating a Track object.

    Arguments:
        visualisation_data (dict): a dictionary with data needed for visualisation.
        parameters (uorf4u.manager.Parameters): Parameters' class object.

    """
    self.visualisation_data = visualisation_data
    self.parameters = parameters

draw(canvas)

Empy parent's method for track visualisation.

Parameters:

  • canvas (reportlab.pdfgen.canvas.Canvas) –

    a pdf object.

Returns:

  • None

    None

Source code in uorf4u/drawing_msa.py
151
152
153
154
155
156
157
158
159
160
def draw(self, canvas: reportlab.pdfgen.canvas.Canvas) -> None:
    """Empy parent's method for track visualisation.

    Arguments:
        canvas (reportlab.pdfgen.canvas.Canvas): a pdf object.

    Returns:
        None
    """
    pass

needed_y_space()

Empy parent's method for calculation needed vertical space for a track.

Returns:

  • None

    None

Source code in uorf4u/drawing_msa.py
142
143
144
145
146
147
148
149
def needed_y_space(self) -> None:
    """Empy parent's method for calculation needed vertical space for a track.

    Returns:
        None

    """
    pass