Exemple #1
0
def test_selected_targets_format(mock_open):

    targets = {'a': 'coffee',
               'b': 'tea'}

    alignments = {}
    for chain_id in targets:
        alignments[chain_id] = TargetTemplateAlignment('', '')
        alignments[chain_id].target_id = targets[chain_id]

    path = tempfile.mktemp()

    class FakeTarFile:
        def __enter__(self, *args, **kwargs):
            return self

        def __exit__(self, *args, **kwargs):
            pass

        def extractfile(self, *args, **kwargs):
            return open(path, 'r')

    mock_open.return_value = FakeTarFile()

    try:
        modeler._write_selected_targets(alignments, path)
        parsed = model_storage.extract_selected_targets('no.tar.gz')
    finally:
        if os.path.isfile(path):
            os.remove(path)

    eq_(parsed, targets)
Exemple #2
0
def test_alignment_ok_for_range():
    r = SequenceRange(1, 22, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
    a = TargetTemplateAlignment(
        "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
        "-----AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA--")

    ok_(domain_aligner._alignment_ok_for_range(r, a))

    r = SequenceRange(1, 22, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
    a = TargetTemplateAlignment(
        "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
        "-------GGGG------------------------------------")

    ok_(not domain_aligner._alignment_ok_for_range(r, a))
Exemple #3
0
    def _merge_alignments(self, alignment1, alignment2):
        span1 = alignment1.get_relative_span()
        span2 = alignment2.get_relative_span()

        # make sure span1 is the N-sided:
        if span2 < span1:
            span1, span2 = swap(span1, span2)
            alignment1, alignment2 = swap(alignment1, alignment2)

        # Determine alignment positions of span1 and span2:
        i1 = 0
        naa = 0
        while naa < span1.end:
            if is_amino_acid_char(alignment1.template_alignment[i1]):
                naa += 1
            i1 += 1

        i2 = 0
        naa = 0
        while naa < span2.start:
            if is_amino_acid_char(alignment2.template_alignment[i2]):
                naa += 1
            i2 += 1

        return TargetTemplateAlignment(alignment1.target_alignment[: i1] + alignment2.target_alignment[i2: ],
                                       alignment1.template_alignment[: i1] + alignment2.template_alignment[i2: ])
Exemple #4
0
def test_count_aligned_residues():
    alignment = BlastAlignment('pdb|1crn|A', 'AVAVAVAVAV', '',
                               1, 10, 'AVAVAVAVAV',
                               1, 10, 'A-A-A-A-A-')
    eq_(alignment.count_aligned_residues(), 5)

    alignment = TargetTemplateAlignment('AVAVAVAVAV',
                                        'A-A-A-A-A-')
    eq_(alignment.count_aligned_residues(), 5)
Exemple #5
0
def test_get_percentage_identity():
    alignment = BlastAlignment('pdb|1crn|A', 'AVAVAVAVAV', '',
                               1, 10, 'AVAVAVAVAV',
                               1, 10, 'ATATATATAT')
    eq_(alignment.get_percentage_identity(), 50.0)

    alignment = TargetTemplateAlignment('AVAVAVAVAV',
                                        'ATATATATAT')
    eq_(alignment.get_percentage_identity(), 50.0)
Exemple #6
0
def test_get_percentage_coverage():
    alignment = BlastAlignment('pdb|1crn|A', 'AVAVAVAVAV', '',
                               1, 10, 'AVAVAVAVAV',
                               1, 10, 'A-A-A-A-A-')
    eq_(alignment.get_percentage_coverage(), 50.0)

    alignment = TargetTemplateAlignment('AVAVAVAVAV',
                                        'A-A-A-A-A-')
    eq_(alignment.get_percentage_coverage(), 50.0)
Exemple #7
0
def test_remove_enclosing():
    d = {
        SequenceRange(1, 22, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"):
        TargetTemplateAlignment(
            "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"),
        SequenceRange(3, 18, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"):
        TargetTemplateAlignment(
            "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"),
        SequenceRange(3, 20, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"):
        TargetTemplateAlignment(
            "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV")
    }
    e = SequenceRange(2, 19, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")

    r = domain_aligner._remove_enclosing(e, d)
    eq_(len(r), 2)
Exemple #8
0
    def align(self,
              template_sequence,
              template_secstr,
              target_sequence,
              gap_open=-13.0,
              gap_extend=-0.4,
              modifier=3.0):

        _log.debug("kmad align\n{}\n{}\n{}".format(template_sequence,
                                                   template_secstr,
                                                   target_sequence))

        # Prevent kmad from adding insertions in bulges, replace those.
        template_secstr = self._remove_bulges(template_secstr, 'H', 3)
        template_secstr = self._remove_bulges(template_secstr, 'E', 3)

        if len(template_sequence) <= 0:
            raise ValueError("empty template sequence")
        if len(template_sequence) != len(template_secstr):
            raise ValueError(
                "template sequence ({}) has different length than secondary structure ({})"
                .format(len(template_sequence), len(template_secstr)))

        kmad_template_sequence = self._to_kmad_sequence(
            template_sequence, template_secstr)
        kmad_target_sequence = self._to_kmad_sequence(target_sequence)

        input_path = tempfile.mktemp()
        output_path = tempfile.mktemp()

        write_fasta(input_path, {
            'target': kmad_target_sequence,
            'template': kmad_template_sequence
        })
        try:
            self._run_kmad(input_path, output_path, gap_open, gap_extend,
                           modifier)

            output_path += '_al'

            aligned = parse_fasta(output_path)

            _log.debug("kmad aligned\n{}\n{}".format(aligned['target'],
                                                     aligned['template']))
        finally:
            for path in [input_path, output_path]:
                if os.path.isfile(path):
                    os.remove(path)

        alignment = TargetTemplateAlignment(aligned['target'],
                                            aligned['template'])
        return alignment
Exemple #9
0
def test_find_shared_hits_ranges():
    d = {
        SequenceRange(1, 22, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"):
        TargetTemplateAlignment(
            "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"),
        SequenceRange(3, 18, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"):
        TargetTemplateAlignment(
            "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"),
        SequenceRange(3, 19, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"):
        TargetTemplateAlignment(
            "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV")
    }
    template_id = TemplateID('1xxx', 'A')
    for v in d.values():
        v.template_id = template_id

    r = domain_aligner._find_shared_hits_ranges(d)

    eq_(len(r), 1)
    eq_(len(list(r.values())[0]), 3)
Exemple #10
0
def test_get_template_sequence_in_target_range():

    alignment = TargetTemplateAlignment(
        "PHTSHSWLCDGRLLCLHDPSNKNNWKIFRECWKQGQPVLVSGVHKKLK" +
        "SELWKPEAFSQEFGDQDVDLVNCRNCAIISDVKVRDFWDGFEIICKRL" +
        "RSEDGQPMVLKLKDWPPGEDFRDMMPTRFEDLMENLPLPEYTKRDGRL" +
        "NLASRLPSYFVRPDLGPKMYNAYGLITAEDRRVGTTNLHLDVSDAVNV" +
        "MVYVGIPIGEG-AHDEEVLKTIDEGDADEVTKQRIHDGKEKPGALWHI" +
        "YAAKDAEKIRELLRKVGEEQGQENPPDHDPIHDQSWYLDQTLRKRLYE" +
        "EYGVQGWAIVQFLGDAVFIPAGAPHQVHNLYSCIKVAEDFVSPEHVKH" + "CFRLTQEF",
        "-MIPHSWICEKHILWLKDYKNSSNWKLFKECWKQGQPAVVSGVHKKMN" +
        "ISLWKAESISLDFGDHQADLLNCKD-SIISNANVKEFWDGFEEVSKR-" +
        "-----ETVVLKLKDWPSGEDFKTMMPARYEDLLKSLPLPEYCNPEGKF" +
        "NLASHLPGFFVR---GPRLCSAYGVVAAKDHDIGTTNLHIEVSDVVNI" +
        "LVYVGIAKGNGILSKAGILKKFEEEDLDDILRKRLKDSSEIPGALWHI" +
        "YAGKDVDKIREFLQKISKEQG------HDPIRDQSWYVNKKLRQRLLE" +
        "EYGVRTCTLIQFLGDAIVLPAGALHQVQNFHSCIQVTEDFVSPEHLVE" + "SFHLTQEL")

    range_ = SequenceRange(48, 96, alignment.target_alignment.replace('-', ''))

    template_seq = domain_aligner._get_template_sequence_in_target_range(
        alignment, range_)
    eq_(template_seq, "ISLWKAESISLDFGDHQADLLNCKD-SIISNANVKEFWDGFEEVSKR-")
Exemple #11
0
def test_get_relative_span():
    alignment = TargetTemplateAlignment('---VA-AVAV-',
                                        '--AAAAA-A-A')
    r = alignment.get_relative_span()
    eq_(r.start, 1)
    eq_(r.end, 6)
Exemple #12
0
def test_get_covered_template_residues_indices():
    alignment = TargetTemplateAlignment('---VA-AVAV',
                                        'A-AAAAA-A-')

    indices = alignment.get_covered_template_residues_indices()
    eq_(indices, [2, 3, 5, 6])
Exemple #13
0
    def _make_poly_A_alignment(self, context, chain_id):

        template_seq = context.get_sequence(chain_id)

        return TargetTemplateAlignment('A' * len(template_seq), template_seq)