Beispiel #1
0
def iterative_structural_align(aln, align_block=0):
    """Given an alignment of structures, iterate over parameter values
       to obtain the best structural alignment."""
    for seq in aln:
        if seq.code == '_fix_pos':
            raise modeller.ModellerError("This method does not work with fixed "
                                         "alignment positions (_fix_pos)")
        if not hasattr(seq, 'atoms'):
            raise modeller.ModellerError("This method only works for an " + \
                                         "alignment of structures.")
    tmpdir = _TemporaryDirectory()
    fil = tmpdir.get_path("inp.pir")
    aln.write(file=fil)

    opfile = tmpdir.get_path("salign_local_mid.ali")
    opfile2 = tmpdir.get_path("salign_local.ali")

    # -- Iterating over values of gap penalties and matrix offset
    fw1=(1., 0., 0., 0., 1., 0.)
    fw2=(0., 1., 0., 0., 0., 0.)
    fw3=(0., 0., 0., 0., 1., 0.)
    best = _BestAlignment(aln)

    # -- Iterating over gap penalties 1D to get initial alignments
    print("Iterate over 1D penalties to get initial alignments")
    for ogp in _frange(-150, 1, 50):
        for egp in _frange(-50, 1, 50):
            for mo in _frange(-3.0, -0.05, 0.3):
                best.try_seq_align(fil, opfile, fw1, ogp, egp, align_block, mo)

    # -- Iterating over gap penalties 3D to get final alignments
    print("Iterate over 3D penalties to get final alignments")
    for ogp3d in _frange(0, 3, 1):
        for egp3d in range(2, 5, 1):
            best.try_struc_align(opfile, opfile2, fw2, ogp3d, egp3d,
                                 align_block)

    # try alternate initial alignments only if the qmax score is less than 70%
    if best.qscore <= 70:
        print("Trying alternate initial alignments")
        for ogp in _frange(0.0, 2.2, 0.3):
            for egp in _frange(0.1, 2.3, 0.3):
                for mo in _frange(-3.0, -0.05, 0.3):
                    best.try_seq_align(fil, opfile, fw3, ogp, egp, align_block,
                                       mo)

        # -- Iterating over gap penalties 3D to get final alignments
        print("Trying alternate final alignments")
        for ogp3d in _frange(0, 3, 1):
            for egp3d in range(2, 5, 1):
                best.try_struc_align(opfile, opfile2, fw2, ogp3d, egp3d,
                                     align_block)

    print("final max quality = %g" % best.qscore)

    if best.found_struc_align:
        aln.clear()
        aln.append(file=opfile2)
    else:
        raise modeller.ModellerError("Structure alignment failed")
Beispiel #2
0
 def _assess(self, atmsel, schedule_scale=None, **vars):
     self.count += 1
     if self.count == 1:
         return 10., ()
     elif self.count == 2:
         return 20., ()
     elif self.count == 3:
         raise modeller.ModellerError("SOAP error")
Beispiel #3
0
def iterative_structural_align(aln):
    """Given an alignment of structures, iterate over parameter values
       to obtain the best structural alignment."""
    for seq in aln:
        if not hasattr(seq, 'atoms'):
            raise modeller.ModellerError("This method only works for an " + \
                                         "alignment of structures.")
    tmpdir = _TemporaryDirectory()
    fil = tmpdir.get_path("inp.pir")
    aln.write(file=fil)

    opfile = tmpdir.get_path("salign_local_mid.ali")
    opfile2 = tmpdir.get_path("salign_local.ali")

    # -- Iterating over values of gap penalties and matrix offset
    qmax = 0.0
    win_ogp3d = None
    fw1=(1., 0., 0., 0., 1., 0.)
    fw2=(0., 1., 0., 0., 0., 0.)
    fw3=(0., 0., 0., 0., 1., 0.)

    # -- Iterating over gap penalties 1D to get initial alignments
    print "Iterate over 1D penalties to get initial alignments"
    for ogp in _frange(-150, 1, 50):
        for egp in _frange(-50, 1, 50):
            for mo in _frange(-3.0, -0.05, 0.3):
                aln.clear()
                aln.append(file=fil)
                try:
                    qwlty1 = _salign_fw_local_gaps1(aln,fw1,ogp,egp,mo)
                    if qwlty1.qscorepct >= qmax:
                        qmax = qwlty1.qscorepct
                        aln.write(file=opfile, alignment_format='PIR')
                        win_ogp = ogp
                        win_egp = egp
                        win_mo = mo
                    print "Qlty scrs", ogp,"\t",egp,"\t",qwlty1.qscorepct
                except modeller.ModellerError, detail:
                    print "Set of parameters",fw1,ogp,egp,"resulted in the following error\t"+str(detail)
Beispiel #4
0
                    except modeller.ModellerError, detail:
                        print "Set of parameters",fw3,ogp,egp,"resulted in the following error\t"+str(detail)

        # -- Iterating over gap penalties 3D to get final alignments
        print "Trying alternate final alignments"
        qmax3d = 0.
        for ogp3d in _frange(0, 3, 1):
            for egp3d in range(2, 5, 1):

                aln.clear()
                aln.append(file=opfile)
                try:
                    qwlty2 = _salign_fw_gaps3(aln,fw2,ogp3d,egp3d)
                    if qwlty2.qscorepct >= qmax3d:
                        qmax3d = qwlty2.qscorepct
                        aln.write(file=opfile2, alignment_format='PIR')
                        win_ogp3d = ogp3d
                        win_egp3d = egp3d
                    print "Qlty scrs", ogp3d,"\t",egp3d,"\t",qwlty2.qscorepct
                except modeller.ModellerError,detail:
                    print "Set of parameters",fw2,ogp3d,egp3d,"resulted in the following error\t"+str(detail)
        qmax = max(qmax, qmax3d)

    print "final max quality = ", qmax

    if win_ogp3d is None:
        raise modeller.ModellerError("Structure alignment failed")
    else:
        aln.clear()
        aln.append(file=opfile2)