Ejemplo n.º 1
0
 def test_functions(self):
     """ Test the helper functions in csv_related """
     fn = self.get_input_file_name("csv.txt")
     rows = csv_related.read_csv(fn)
     self.assertEqual(len(rows), 6)
     rows = csv_related.read_csv_keyword(fn, "id")
     self.assertEqual(len(rows), 3)
Ejemplo n.º 2
0
 def test_functions(self):
     """ Test the helper functions in csv_related """
     fn = self.get_input_file_name("csv.txt")
     rows = csv_related.read_csv(fn)
     self.assertEqual(len(rows), 6)
     rows = csv_related.read_csv_keyword(fn, "id")
     self.assertEqual(len(rows), 3)
Ejemplo n.º 3
0
def read_hex_transforms(fn_transforms):
    """
        Parses a file of hex transforms. It returns the transformations as
        alg.Transformation3D objects
        @param fn_transforms
    """
    rows = csv_related.read_csv(fn_transforms, delimiter=" ")
    return [parse_hex_transform(row) for row in rows]
Ejemplo n.º 4
0
 def read_merge_tree(self, fn):
     """
         Read and create a merge tree from a file.
         The format of the file is the format written by write merge_tree()
         It does not matter the order of the indices in the file, as
         they are sorted by this function.
         The only condition is that the index for the vertex that is the
         root of the tree MUST be the largest. This is guaranteed when
         creating a merge tree with create_merge_tree()
         @param fn File containing the merge tree
     """
     log.info("Reading merge tree from %s", fn)
     ps = self.rb_states_table.get_particles()
     log.debug("particles")
     for p in ps:
         log.debug("%s", p.get_name())
     rows = csv_related.read_csv(fn, delimiter = field_delim)
     for i in range(len(rows)):
         row = rows[i]
         rows[i] = [int(row[0]), int(row[1]), int(row[2]), row[3]]
     # Sort rows by vertice index
     rows.sort()
     subsets = []
     # build subsets from the rows text
     for row in rows:
         names = row[3].split(unit_delim)
         log.debug("row %s names %s", row, names)
         # get particles in the subset
         particles = []
         for name in names:
             l = filter(lambda p: p.get_name() == name, ps)
             if (len(l) > 1):
                 ValueError("More than one particle with same name" % names)
             particles.extend(l)
         s = domino.Subset(particles)
         subset_names = [p.get_name() for p in particles]
         log.debug("Merge tree Subset %s. Particles %s ",s, subset_names)
         subsets.append(s)
     # The vertex with the largest index is the root.
     # trick: get the merge tree object from a tree with only one node ...
     jt = domino.SubsetGraph()
     jt.add_vertex(subsets[0])
     mt = domino.get_merge_tree(jt)
     # ... and add the rest of the vertices
     for i in range(1,len(subsets)):
         mt.add_vertex(subsets[i]) # the name of the vertex is a subset
     # set edges
     for row in rows:
         vid = row[0]
         child_left = row[1]
         child_right = row[2]
         if child_left != -1:
             mt.add_edge(vid, child_left)
         if child_right != -1:
             mt.add_edge(vid, child_right)
     self.merge_tree = mt
     log.info("%s",self.merge_tree.show_graphviz() )
Ejemplo n.º 5
0
Archivo: io.py Proyecto: sirusb/imp
def read_reference_frames(fn, n=10):
    """
        Read the reference frames contained in a solutions file from sampling
        n is the maximum number of ref frames to read.
        NOTE: Currently the function returns only the reference frames and
        discards the score, the first element of a row
    """
    rows = csv_related.read_csv(fn, delimiter="/")
    x = min(n, len(rows))
    all_refs = []
    for i, row in enumerate(rows[0:x]):
        refs = [TextToReferenceFrame(t).get_reference_frame() for t in row[1:]]
        all_refs.append(refs)
    return all_refs
Ejemplo n.º 6
0
def read_reference_frames(fn, n=10):
    """
        Read the reference frames contained in a solutions file from sampling
        n is the maximum number of ref frames to read.
        NOTE: Currently the function returns only the reference frames and
        discards the score, the first element of a row
    """
    rows = csv_related.read_csv(fn, delimiter = "/")
    x = min(n,len(rows))
    all_refs = []
    for i,row in enumerate(rows[0:x]):
        refs = [ TextToReferenceFrame(t).get_reference_frame() for t in row[1:]]
        all_refs.append(refs)
    return all_refs
Ejemplo n.º 7
0
def filter_docking_results(h_receptor, h_ligand,
                        list_xlinks, fn_transforms,
                        fn_filtered, max_number=False):
    """
        Check if the set of transforms proposed by docking with HEX is
        compatible with the distances between aminoacids from crosslinking

        @param h_receptor atom.Hierarchy for the receptor
        @param h_ligand atom.Hierarchy for the ligand
        @param list_xlinks - list of tuples with the format
                                (residue receptor, residue ligand, distance)
        @param fn_transforms File of transforms as given by HEX
        @param fn_filtered Output file that will contain only the
                                transformations satisfying the cross-linking
                                restraints
    """
    log.info("Filtering results of docking in %s with xlinks %s", fn_transforms,
                                                                list_xlinks)
    coords_rec = []
    coords_lig = []
    threshold_distances = []
    for i, j, distance in list_xlinks:
        coords_rec.append(
            representation.get_residue_coordinates(h_receptor, res=i))
        coords_lig.append(
            representation.get_residue_coordinates(h_ligand, res=j))
        threshold_distances.append(distance);

    rows = csv_related.read_csv(fn_transforms, delimiter=" ",
                                                        max_number=max_number)
    good = []
    for r in rows:
        T = parse_hex_transform(r)
        transformed = [T.get_transformed(c) for c in coords_lig ]
        if get_xlinks_are_good(coords_rec, transformed, threshold_distances):
            good.append(r)

    # If there are not good transforms because all were filtered, the best
    # bet is to keep all of them.
    f_output = open(fn_filtered, "w")
    w = csv.writer(f_output, delimiter=" ")
    if len(good) ==0:
        log.warning("No docking solution satisfies all the x-linking " \
                                            "restraints. Keeping all of them")
        w.writerows(rows)
    else:
        w.writerows(good)
    f_output.close()