Beispiel #1
0
def symlink(
    source_path,
    target_path,
):
    rel_symlink(
        str(source_path),
        str(target_path),
    )
Beispiel #2
0
    def __call__(self, dataset, output_path, regex):
        try:

            source_ligand_path = self.get_ligand_path(
                dataset,
                regex,
            )

            # print(source_ligand_path)

            rel_symlink(
                str(source_ligand_path),
                str(output_path / source_ligand_path.name),
            )

        except Exception as e:
            print(e)
Beispiel #3
0
    def __call__(self, mcd):

        # ==============================>
        # Clean previous PanDDA
        # ==============================>
        try:
            shutil.rmtree(self.out_dir, ignore_errors=True)
        except Exception as e:
            print(e)

        # ==============================>
        # Make output dir
        # ==============================>
        os.mkdir(str(self.out_dir))

        # ==============================>
        # Get path objects
        # ==============================>
        dataset_template = {"event_map.ccp4": None, "ligand": {"dummy": None}}

        processed_datasets = {
            dtag: dataset_template
            for dtag, d in mcd.datasets.items()
        }

        analyses = {"pandda_analyse_events.csv": None}

        pandda = {
            "processed_datasets": processed_datasets,
            "analyses": analyses
        }

        # ==============================>
        # Initialise pandda output
        # ==============================>
        self.tree = Tree(str(self.out_dir), pandda)

        # ==============================>
        # Initialise dataset output
        # ==============================>
        errors = []
        for dtag, dataset in mcd.datasets.items():

            # ==============================>
            # Get path
            # ==============================>
            dataset_path = p.Path(self.tree(("processed_datasets", dtag))[0])

            # ==============================>
            # Create links to input files
            # ==============================>
            # Links for the dataset input files
            # TODO: seems inelegant
            link_pdb = str(dataset_path / "pandda_input.pdb")
            link_mtz = str(dataset_path / "pandda_input.mtz")

            # Link the input files to the output folder
            if not os.path.exists(link_pdb):
                rel_symlink(orig=dataset.model.filename, link=link_pdb)
            if not os.path.exists(link_mtz):
                rel_symlink(orig=dataset.data.filename, link=link_mtz)
            # ==============================>
            # Search for ligand files and copy them to the output ligands folder
            # ==============================>
            lig_files = glob.glob(
                os.path.join(os.path.dirname(dataset.model.filename),
                             self.lig_style))
            for lig_file in lig_files:
                # Find all files with the same basename but allowing for different extensions. Then link to output folder.
                lig_base = os.path.splitext(lig_file)[0] + '.*'
                lig_matches = glob.glob(lig_base)
                for lig in lig_matches:
                    out_path = os.path.join(str(dataset_path / 'ligand'),
                                            os.path.basename(lig))
                    if os.path.exists(lig) and (not os.path.exists(out_path)):
                        try:
                            shutil.copy(lig, out_path)
                        except:
                            pass
            # # ==============================>
            # # Lastly: Update the pointer to the new path (relative to the pandda directory)
            # # ==============================>
            # dataset.model.filename = os.path.relpath(link_pdb, start=self.out_dir)
            # dataset.data.filename = os.path.relpath(link_mtz, start=self.out_dir)

        return self.tree