Example #1
0
    def process(self):
        """
        Run the conversion script if the output needs updating.
        """
        # Note: _needs_update() does the logging.
        if not self._needs_update():
            return

        if not os.path.exists(self.script):
            raise ValueError(
                "Processing script {0.script} does not exist".format(self))

        if not (stat.S_IXUSR & os.stat(self.script)[stat.ST_MODE]):
            raise ValueError(
                Fore.RED +
                "Processing script {0.script} not executable".format(self) +
                Fore.RESET)

        utils.makedirs(os.path.dirname(self.processed))

        cmds = [
            self.script,
            self.original,
            self.processed
        ]
        retval = subprocess.check_call(cmds)
        if self._needs_update():
            raise ValueError(
                Fore.RED + 'The following command did not update '
                '{1}:\n\n{0}\n'.format(' \\\n'.join(cmds), self.processed) +
                Fore.RESET
            )
Example #2
0
    def process(self):
        """
        Run the conversion script if the output needs updating.
        """
        # Note: _needs_update() does the logging.
        if not self._needs_update():
            return

        if not os.path.exists(self.script):
            raise ValueError(
                "Processing script {0.script} does not exist".format(self))

        if not (stat.S_IXUSR & os.stat(self.script)[stat.ST_MODE]):
            raise ValueError(
                Fore.RED +
                "Processing script {0.script} not executable".format(self) +
                Fore.RESET)

        utils.makedirs(os.path.dirname(self.processed))

        cmds = [self.script, self.original, self.processed]
        retval = subprocess.check_call(cmds)
        if self._needs_update():
            raise ValueError(
                Fore.RED + 'The following command did not update '
                '{1}:\n\n{0}\n'.format(' \\\n'.join(cmds), self.processed) +
                Fore.RESET)
Example #3
0
    def liftover(self, from_assembly, to_assembly, newfile):
        """
        Lifts over the processed file to a new file, but only if needed.

        Uses a hidden sentinel file to indicate whether it's been lifted over.

        Parameters
        ----------

        from_assembly : str
            Existing data are in this assembly's coordinates

        to_assembly : str
            Lift over existing data to this assembly's coordinates

        newfile : str
            Target filename of the lifted-over data
        """

        if not from_assembly == self.genome:
            log(
                "{0} not from assembly {1}. Skipping liftover from {1} to {2} "
                "and simply copying the file as-is to {3}"
                .format(self.label, from_assembly, to_assembly, newfile)
            )
            shutil.copy(self.processed, newfile)

        if not self._needs_liftover(from_assembly, to_assembly, newfile):
            log("{0} is already lifted over and up-to-date. Skipping."
                .format(newfile))
            return

        tmp = tempfile.NamedTemporaryFile(delete=False).name
        log("Lift over {0} to {1}".format(self.processed, tmp))
        liftover.liftover(
            from_assembly, to_assembly, self.processed, tmp, self.type_)
        utils.makedirs(os.path.dirname(newfile))
        log("Moving {0} to {1}".format(tmp, newfile))
        shutil.move(tmp, newfile)

        if self.type_.lower() == 'bam':
            shutil.move(tmp + '.bai', newfile + '.bai')


        # CrossMap.py seems to `chmod go-rw` on lifted-over file. So we copy
        # permissions from the original one.
        shutil.copymode(self.processed, newfile)

        # Write the sentinel file to indicate genome we lifted over to.
        sentinel = self._liftover_sentinel(from_assembly, to_assembly, newfile)
        with open(sentinel, 'w') as fout:
            pass
Example #4
0
    def liftover(self, from_assembly, to_assembly, newfile):
        """
        Lifts over the processed file to a new file, but only if needed.

        Uses a hidden sentinel file to indicate whether it's been lifted over.

        Parameters
        ----------

        from_assembly : str
            Existing data are in this assembly's coordinates

        to_assembly : str
            Lift over existing data to this assembly's coordinates

        newfile : str
            Target filename of the lifted-over data
        """

        if not from_assembly == self.genome:
            log("{0} not from assembly {1}. Skipping liftover from {1} to {2} "
                "and simply copying the file as-is to {3}".format(
                    self.label, from_assembly, to_assembly, newfile))
            shutil.copy(self.processed, newfile)

        if not self._needs_liftover(from_assembly, to_assembly, newfile):
            log("{0} is already lifted over and up-to-date. Skipping.".format(
                newfile))
            return

        tmp = tempfile.NamedTemporaryFile(delete=False).name
        log("Lift over {0} to {1}".format(self.processed, tmp))
        liftover.liftover(from_assembly, to_assembly, self.processed, tmp,
                          self.type_)
        utils.makedirs(os.path.dirname(newfile))
        log("Moving {0} to {1}".format(tmp, newfile))
        shutil.move(tmp, newfile)

        # CrossMap.py seems to `chmod go-rw` on lifted-over file. So we copy
        # permissions from the original one.
        shutil.copymode(self.processed, newfile)

        # Write the sentinel file to indicate genome we lifted over to.
        sentinel = self._liftover_sentinel(from_assembly, to_assembly, newfile)
        with open(sentinel, 'w') as fout:
            pass