Example #1
0
def seq_display(request, align_slug):
    """
    Serves query display page
    :param request: HTTP request
    :param align_id: alignment pk
    :return:HttpResponse or HttpResponseNotAllowed object
    """
    if request.method == 'GET':
        # split sequences in chunks of 80 characters
        align_id = Alignment.objects.get(slug=align_slug).pk
        alignment = consensus_add(Alignment.objects.get_alignment(align_id))
        alphabets = {
            "Gapped(ExtendedIUPACProtein(), '-')": 'Protein',
            "Gapped(ExtendedIUPACDNA(), '-')": 'DNA',
        }
        alphabet = alphabets[str(alignment[0].seq.alphabet)]

        query_seqs = split_lines(alignment, line_length=80, split_type='sequence')

        return render(
            request,
            'base/query_display.html',
            {'query_seqs': query_seqs, 'seq_type': alphabet, 'align_id': align_slug}
        )

    else:
        return HttpResponseNotAllowed(['GET'])
Example #2
0
 def test_split_lines_sequence_splits_lines_of_80_chars(self):
     """
     Tests that split_lines function splits sequences in lines of 80 characters by default
     """
     alignment = self.alignment
     split_sequence = split_lines(alignment, split_type="sequence")
     for seq in split_sequence:
         self.assertEqual([80 for i in range(len(seq["seq"]) - 1)], [len(s) for s in seq["seq"][:-1]])
         self.assertTrue(len(seq["seq"][-1]) <= 80)
Example #3
0
 def test_split_lines_alignment_splits_blocks_of_80_chars(self):
     """
     Tests that split_lines function splits blocks of alignment sequences in lines of 80 characters by default
     """
     alignment = self.alignment
     split_alignment = split_lines(alignment, split_type="alignment")
     for seq in split_alignment[:-1]:
         self.assertEqual([80 for i in range(len(seq))], [len(s) for s in seq])
     for seq in split_alignment[-1]:
         self.assertTrue(len(seq) <= 80)
Example #4
0
def align_display(request, align_slug):
    """
    serves alignment display page
    :param request: HTTP request
    :param align_id: alignment pk
    :return: HttpResponse object
    """
    if request.method == 'GET':
        align_id = Alignment.objects.get(slug=align_slug).pk
        alignment_fetch = Alignment.objects.get_alignment(align_id)

        alignment = consensus_add(alignment_fetch)

        alignment = annotate(alignment)

        # get longest id for id display width
        id_lengths = [len(a.id) for a in alignment]
        id_lengths.sort(reverse=True)
        id_width = id_lengths[0] + 2

        # split sequences in lines of 80 characters
        seq_lines = split_lines(alignment, line_length=80, split_type='alignment')

        # split lines in blocks of 10 characters
        block_length = 10

        seqs_blocks = [
            [
                [
                    ls.id, [
                        zip(
                            ls.letter_annotations['eq'][j:j + block_length],
                            list(ls[j:j + block_length])
                        ) for j in range(0, len(ls), block_length)
                    ]
                ] for ls in ln] for ln in seq_lines
        ]

        align = {
            'align_seqs': seqs_blocks,
        }

        r = render(
            request, 'base/align_display.html',
            {'align': align, 'id_width': id_width * .6, 'total_width': (id_width + 80) * .5}
        )
        return r