示例#1
0
 def test_anisotropy_planar(self):
     # The anisotropy for planar symmetric objects converges to 1/4.
     # See references 36-40 in doi:10.1063/1.4788616
     planar = np.array([[0., 0, 1], [0, 1, 0], [0, -1, 0], [0, 0, 1],
                        [0, 0, 0], [0, 0.6, 0.6], [0, -0.6, 0.6],
                        [0, 0.6, -0.6], [0, -0.6, -0.6]])
     self.assertAlmostEqual(ftmd.anisotropy(planar), 0.25, places=2)
示例#2
0
 def _get_descriptor(self, descriptor, domain=None):
     """
     :param ensemble: an Ensemble or EnsembleView object
     :param descriptor: A STRING. One of AVAILABLE_DESCRIPTORS
     :param domain: An iterable of cg element names or None (whole cg)
     :returns: A np.array
     """
     if descriptor not in self.AVAILABLE_DESCRIPTORS:
         raise ValueError("Descriptor {} not available.".format(descriptor))
     if descriptor == "rog":
         if domain:
             return np.array([
                 ftmd.radius_of_gyration(
                     cg.get_poss_for_domain(domain, "vres")) for cg in self
             ])
         else:
             return np.array([cg.radius_of_gyration() for cg in self])
     elif descriptor == "anisotropy":
         if domain:
             return np.array([
                 ftmd.anisotropy(cg.get_poss_for_domain(domain, "vres"))
                 for cg in self
             ])
         else:
             return np.array([
                 ftmd.anisotropy(cg.get_ordered_stem_poss()) for cg in self
             ])
     elif descriptor == "asphericity":
         if domain:
             return np.array([
                 ftmd.asphericity(cg.get_poss_for_domain(domain, "vres"))
                 for cg in self
             ])
         else:
             return np.array([
                 ftmd.asphericity(cg.get_ordered_stem_poss()) for cg in self
             ])
示例#3
0
 def _get_descriptor(self, descriptor, domain=None):
     """
     :param ensemble: an Ensemble or EnsembleView object
     :param descriptor: A STRING. One of AVAILABLE_DESCRIPTORS
     :param domain: An iterable of cg element names or None (whole cg)
     :returns: A np.array
     """
     if descriptor not in self.AVAILABLE_DESCRIPTORS:
         raise ValueError("Descriptor {} not available.".format(descriptor))
     if descriptor == "rog":
         if domain:
             return np.array([ftmd.radius_of_gyration(cg.get_poss_for_domain(domain, "vres")) for cg in self])
         else:
             return np.array([cg.radius_of_gyration() for cg in self])
     elif descriptor == "anisotropy":
         if domain:
             return np.array([ftmd.anisotropy(cg.get_poss_for_domain(domain, "vres")) for cg in self])
         else:
             return np.array([ftmd.anisotropy(cg.get_ordered_stem_poss()) for cg in self])
     elif descriptor == "asphericity":
         if domain:
             return np.array([ftmd.asphericity(cg.get_poss_for_domain(domain, "vres")) for cg in self])
         else:
             return np.array([ftmd.asphericity(cg.get_ordered_stem_poss()) for cg in self])
示例#4
0
 def anisotropy(cgs):
     ai = np_nans(len(cgs))
     for i, cg in enumerate(cgs):
         ai[i] = ftmd.anisotropy(cg.get_ordered_stem_poss())
     return ai
示例#5
0
def describe_rna(cg, file_num, dist_pais, angle_pairs):
    data = {}
    data["nt_length"] = cg.seq_length
    data["num_cg_elems"] = len(cg.defines)
    for letter in "smifth":
        data["num_" + letter] = len([x for x in cg.defines if x[0] == letter])
    multiloops = cg.find_mlonly_multiloops()
    descriptors = []
    junct3 = 0
    junct4 = 0
    reg = 0
    pk = 0
    op = 0
    for ml in multiloops:
        descriptors = cg.describe_multiloop(ml)
        if "regular_multiloop" in descriptors:
            if len(ml) == 3:
                junct3 += 1
            elif len(ml) == 4:
                junct4 += 1
            reg += 1
        if "pseudoknot" in descriptors:
            pk += 1
        if "open" in descriptors:
            op += 1
    data["3-way-junctions"] = junct3
    data["4-way-junctions"] = junct4

    #print (descriptors)
    data["open_mls"] = op
    # print(data["open_mls"][-1])
    data["pseudoknots"] = pk
    data["regular_mls"] = reg
    data["total_mls"] = len(multiloops)
    try:
        data["longest_ml"] = max(len(x) for x in multiloops)
    except ValueError:
        data["longest_ml"] = 0
    try:
        data["rog_fast"] = cg.radius_of_gyration("fast")
    except (ftmc.RnaMissing3dError, AttributeError):
        data["rog_fast"] = float("nan")
        data["rog_vres"] = float("nan")
        data["anisotropy_fast"] = float("nan")
        data["anisotropy_vres"] = float("nan")
        data["asphericity_fast"] = float("nan")
        data["asphericity_vres"] = float("nan")
    else:
        data["rog_vres"] = cg.radius_of_gyration("vres")
        data["anisotropy_fast"] = ftmd.anisotropy(cg.get_ordered_stem_poss())
        data["anisotropy_vres"] = ftmd.anisotropy(
            cg.get_ordered_virtual_residue_poss())
        data["asphericity_fast"] = ftmd.asphericity(cg.get_ordered_stem_poss())
        data["asphericity_vres"] = ftmd.asphericity(
            cg.get_ordered_virtual_residue_poss())
    for from_nt, to_nt in dist_pairs:
        try:
            dist = ftuv.vec_distance(
                cg.get_virtual_residue(int(from_nt), True),
                cg.get_virtual_residue(int(to_nt), True))
        except Exception as e:
            dist = float("nan")
            log.warning(
                "%d%s File %s: Could not calculate distance between "
                "%d and %d: %s occurred: %s", file_num, {
                    1: "st",
                    2: "nd",
                    3: "rd"
                }.get(file_num % 10 * (file_num % 100 not in [11, 12, 13]),
                      "th"), cg.name, from_nt, to_nt,
                type(e).__name__, e)
        data["distance_{}_{}".format(from_nt, to_nt)] = dist
    for elem1, elem2 in angle_pairs:
        try:
            angle = ftuv.vec_angle(cg.coords.get_direction(elem1),
                                   cg.coords.get_direction(elem2))
        except Exception as e:
            angle = float("nan")
            log.warning(
                "%d%s File %s: Could not calculate angle between "
                "%s and %s: %s occurred: %s", file_num, {
                    1: "st",
                    2: "nd",
                    3: "rd"
                }.get(file_num % 10 * (file_num % 100 not in [11, 12, 13]),
                      "th"), cg.name, elem1, elem2,
                type(e).__name__, e)
        data["angle_{}_{}".format(elem1, elem2)] = angle
    data["missing_residues_5prime"] = (len(cg.seq.with_missing[:1]) - 1)
    data["missing_residues_3prime"] = (
        len(cg.seq.with_missing[cg.seq_length:]) - 1)
    data["missing_residues_middle"] = (
        len(cg.seq.with_missing[1:cg.seq_length]) -
        len(cg.seq[1:cg.seq_length]))
    data["missing_residues_total"] = (len(cg.seq.with_missing[:]) -
                                      len(cg.seq[:]))
    fp = len(cg.seq.with_missing[:1]) - 1
    tp = 0
    old_bp = None
    bp = None
    for bp in cg.backbone_breaks_after:
        fp += len(cg.seq.with_missing[bp:bp + 1].split('&')[1]) - 1
        tp += len(cg.seq.with_missing[bp:bp + 1].split('&')[0]) - 1
    tp += len(cg.seq.with_missing[cg.seq_length:]) - 1
    data["missing_residues_5prime_chain"] = (fp)
    data["missing_residues_3prime_chain"] = (tp)
    data["missing_residues_middle_chain"] = (data["missing_residues_total"] -
                                             fp - tp)
    incomplete_elem_types = Counter(x[0] for x in cg.incomplete_elements)
    data["s_with_missing"] = incomplete_elem_types["s"]
    data["i_with_missing"] = incomplete_elem_types["i"]
    data["m_with_missing"] = incomplete_elem_types["m"]
    data["h_with_missing"] = incomplete_elem_types["h"]
    mp = ""
    if incomplete_elem_types["s"]:
        for elem in cg.incomplete_elements:
            if elem[0] != "s":
                continue
            for i in range(cg.defines[elem][0], cg.defines[elem][1]):
                left_s = cg.seq.with_missing[i:i + 1]
                if len(left_s) > 2:
                    right_s = cg.seq.with_missing[cg.pairing_partner(i + 1):cg.
                                                  pairing_partner(i)]
                    if len(right_s) > 2:
                        mp += "{}&{};".format(left_s, right_s)
    data["missing_basepairs"] = mp
    return data
示例#6
0
 def test_anisotropy_star(self):
     star = np.array([[0., 0, 1], [0, 1, 0], [1, 0, 0], [-1, 0, 0],
                      [0, -1, 0], [0, 0, 1], [0, 0, 0]])
     self.assertLessEqual(ftmd.anisotropy(star), 0.2)
示例#7
0
 def test_anisotropy_linear(self):
     linear = np.array([[1., 1., 1.], [0., 0., 0.], [-1., -1., -1.],
                        [-2, -2, -2]])
     self.assertAlmostEqual(ftmd.anisotropy(linear), 1)
示例#8
0
 def update(self, sm, step):
     rog = ftur.anisotropy(sm.bg.get_ordered_stem_poss())
     self.history[0].append(rog)
     return "{:6.2f}".format(rog)
示例#9
0
 def test_anisotropy_no_coords(self):
     a = np.array([])
     self.assertTrue(np.isnan(ftmd.anisotropy(a)))
示例#10
0
def describe_rna(cg, file_num, dist_pais, angle_pairs):
    data = {}
    data["nt_length"] = cg.seq_length
    data["num_cg_elems"] = len(cg.defines)
    for letter in "smifth":
        data["num_" + letter] = len([x for x in cg.defines if x[0] == letter])
    multiloops = cg.find_mlonly_multiloops()
    descriptors = []
    junct3 = 0
    junct4 = 0
    reg = 0
    pk = 0
    op = 0
    for ml in multiloops:
        descriptors = cg.describe_multiloop(ml)
        if "regular_multiloop" in descriptors:
            if len(ml) == 3:
                junct3 += 1
            elif len(ml) == 4:
                junct4 += 1
            reg += 1
        if "pseudoknot" in descriptors:
            pk += 1
        if "open" in descriptors:
            op += 1
    data["3-way-junctions"] = junct3
    data["4-way-junctions"] = junct4

    #print (descriptors)
    data["open_mls"] = op
    #print(data["open_mls"][-1])
    data["pseudoknots"] = pk
    data["regular_mls"] = reg
    data["total_mls"] = len(multiloops)
    try:
        data["longest_ml"] = max(len(x) for x in multiloops)
    except ValueError:
        data["longest_ml"] = 0
    try:
        data["rog_fast"] = cg.radius_of_gyration("fast")
    except (ftmc.RnaMissing3dError, AttributeError):
        data["rog_fast"] = float("nan")
        data["rog_vres"] = float("nan")
        data["anisotropy_fast"] = float("nan")
        data["anisotropy_vres"] = float("nan")
        data["asphericity_fast"] = float("nan")
        data["asphericity_vres"] = float("nan")
    else:
        data["rog_vres"] = cg.radius_of_gyration("vres")
        data["anisotropy_fast"] = ftmd.anisotropy(cg.get_ordered_stem_poss())
        data["anisotropy_vres"] = ftmd.anisotropy(
            cg.get_ordered_virtual_residue_poss())
        data["asphericity_fast"] = ftmd.asphericity(cg.get_ordered_stem_poss())
        data["asphericity_vres"] = ftmd.asphericity(
            cg.get_ordered_virtual_residue_poss())
    for from_nt, to_nt in dist_pairs:
        try:
            dist = ftuv.vec_distance(
                cg.get_virtual_residue(int(from_nt), True),
                cg.get_virtual_residue(int(to_nt), True))
        except Exception as e:
            dist = float("nan")
            log.warning(
                "%d%s File %s: Could not calculate distance between "
                "%d and %d: %s occurred: %s", file_num, {
                    1: "st",
                    2: "nd",
                    3: "rd"
                }.get(file_num % 10 * (file_num % 100 not in [11, 12, 13]),
                      "th"), cg.name, from_nt, to_nt,
                type(e).__name__, e)
        data["distance_{}_{}".format(from_nt, to_nt)] = dist
    for elem1, elem2 in angle_pairs:
        try:
            angle = ftuv.vec_angle(cg.coords.get_direction(elem1),
                                   cg.coords.get_direction(elem2))
        except Exception as e:
            angle = float("nan")
            log.warning(
                "%d%s File %s: Could not calculate angle between "
                "%s and %s: %s occurred: %s", file_num, {
                    1: "st",
                    2: "nd",
                    3: "rd"
                }.get(file_num % 10 * (file_num % 100 not in [11, 12, 13]),
                      "th"), cg.name, elem1, elem2,
                type(e).__name__, e)
        data["angle_{}_{}".format(elem1, elem2)] = angle
    return data
示例#11
0
 def test_anisotropy_no_coords(self):
     a = np.array([])
     self.assertTrue(np.isnan(ftmd.anisotropy(a)))
示例#12
0
 def test_anisotropy_planar(self):
     # The anisotropy for planar symmetric objects converges to 1/4.
     # See references 36-40 in doi:10.1063/1.4788616
     planar = np.array([[0., 0, 1], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, 0],
                        [0, 0.6, 0.6], [0, -0.6, 0.6], [0, 0.6, -0.6], [0, -0.6, -0.6]])
     self.assertAlmostEqual(ftmd.anisotropy(planar), 0.25, places=2)
示例#13
0
 def test_anisotropy_star(self):
     star = np.array([[0., 0, 1], [0, 1, 0], [1, 0, 0],
                      [-1, 0, 0], [0, -1, 0], [0, 0, 1], [0, 0, 0]])
     self.assertLessEqual(ftmd.anisotropy(star), 0.2)
示例#14
0
 def test_anisotropy_linear(self):
     linear = np.array([[1., 1., 1.], [0., 0., 0.],
                        [-1., -1., -1.], [-2, -2, -2]])
     self.assertAlmostEqual(ftmd.anisotropy(linear), 1)
示例#15
0
def describe_rna(cg, file_num, dist_pais, angle_pairs):
    data = {}
    data["nt_length"] = cg.seq_length
    data["num_cg_elems"] = len(cg.defines)
    for letter in "smifth":
        data["num_" + letter] = len([x for x in cg.defines if x[0] == letter])
    multiloops = cg.find_mlonly_multiloops()
    descriptors = []
    junct3 = 0
    junct4 = 0
    reg = 0
    pk = 0
    op = 0
    for ml in multiloops:
        descriptors = cg.describe_multiloop(ml)
        if "regular_multiloop" in descriptors:
            if len(ml) == 3:
                junct3 += 1
            elif len(ml) == 4:
                junct4 += 1
            reg += 1
        if "pseudoknot" in descriptors:
            pk += 1
        if "open" in descriptors:
            op += 1
    data["3-way-junctions"] = junct3
    data["4-way-junctions"] = junct4

    #print (descriptors)
    data["open_mls"] = op
    # print(data["open_mls"][-1])
    data["pseudoknots"] = pk
    data["regular_mls"] = reg
    data["total_mls"] = len(multiloops)
    try:
        data["longest_ml"] = max(len(x) for x in multiloops)
    except ValueError:
        data["longest_ml"] = 0
    try:
        data["rog_fast"] = cg.radius_of_gyration("fast")
    except (ftmc.RnaMissing3dError, AttributeError):
        data["rog_fast"] = float("nan")
        data["rog_vres"] = float("nan")
        data["anisotropy_fast"] = float("nan")
        data["anisotropy_vres"] = float("nan")
        data["asphericity_fast"] = float("nan")
        data["asphericity_vres"] = float("nan")
    else:
        data["rog_vres"] = cg.radius_of_gyration("vres")
        data["anisotropy_fast"] = ftmd.anisotropy(cg.get_ordered_stem_poss())
        data["anisotropy_vres"] = ftmd.anisotropy(
            cg.get_ordered_virtual_residue_poss())
        data["asphericity_fast"] = ftmd.asphericity(cg.get_ordered_stem_poss())
        data["asphericity_vres"] = ftmd.asphericity(
            cg.get_ordered_virtual_residue_poss())
    for from_nt, to_nt in dist_pairs:
        try:
            dist = ftuv.vec_distance(cg.get_virtual_residue(int(from_nt), True),
                                     cg.get_virtual_residue(int(to_nt), True))
        except Exception as e:
            dist = float("nan")
            log.warning("%d%s File %s: Could not calculate distance between "
                        "%d and %d: %s occurred: %s", file_num,
                        {1: "st", 2: "nd", 3: "rd"}.get(
                            file_num % 10 * (file_num % 100 not in [11, 12, 13]), "th"),
                        cg.name, from_nt, to_nt, type(e).__name__, e)
        data["distance_{}_{}".format(from_nt, to_nt)] = dist
    for elem1, elem2 in angle_pairs:
        try:
            angle = ftuv.vec_angle(cg.coords.get_direction(elem1),
                                   cg.coords.get_direction(elem2))
        except Exception as e:
            angle = float("nan")
            log.warning("%d%s File %s: Could not calculate angle between "
                        "%s and %s: %s occurred: %s", file_num,
                        {1: "st", 2: "nd", 3: "rd"}.get(
                            file_num % 10 * (file_num % 100 not in [11, 12, 13]), "th"),
                        cg.name, elem1, elem2, type(e).__name__, e)
        data["angle_{}_{}".format(elem1, elem2)] = angle
    data["missing_residues_5prime"] = (len(cg.seq.with_missing[:1]) - 1)
    data["missing_residues_3prime"] = (
        len(cg.seq.with_missing[cg.seq_length:]) - 1)
    data["missing_residues_middle"] = (
        len(cg.seq.with_missing[1:cg.seq_length]) - len(cg.seq[1:cg.seq_length]))
    data["missing_residues_total"] = (
        len(cg.seq.with_missing[:]) - len(cg.seq[:]))
    fp = len(cg.seq.with_missing[:1]) - 1
    tp = 0
    old_bp = None
    bp = None
    for bp in cg.backbone_breaks_after:
        fp += len(cg.seq.with_missing[bp:bp + 1].split('&')[1]) - 1
        tp += len(cg.seq.with_missing[bp:bp + 1].split('&')[0]) - 1
    tp += len(cg.seq.with_missing[cg.seq_length:]) - 1
    data["missing_residues_5prime_chain"] = (fp)
    data["missing_residues_3prime_chain"] = (tp)
    data["missing_residues_middle_chain"] = (
        data["missing_residues_total"] - fp - tp)
    incomplete_elem_types = Counter(x[0] for x in cg.incomplete_elements)
    data["s_with_missing"] = incomplete_elem_types["s"]
    data["i_with_missing"] = incomplete_elem_types["i"]
    data["m_with_missing"] = incomplete_elem_types["m"]
    data["h_with_missing"] = incomplete_elem_types["h"]
    mp = ""
    if incomplete_elem_types["s"]:
        for elem in cg.incomplete_elements:
            if elem[0] != "s":
                continue
            for i in range(cg.defines[elem][0], cg.defines[elem][1]):
                left_s = cg.seq.with_missing[i:i + 1]
                if len(left_s) > 2:
                    right_s = cg.seq.with_missing[cg.pairing_partner(
                        i + 1):cg.pairing_partner(i)]
                    if len(right_s) > 2:
                        mp += "{}&{};".format(left_s, right_s)
    data["missing_basepairs"] = mp
    return data
示例#16
0
 def anisotropy(cgs):
     ai = np_nans(len(cgs))
     for i, cg in enumerate(cgs):
         ai[i] = ftmd.anisotropy(cg.get_ordered_stem_poss())
     return ai