コード例 #1
0
ファイル: node.py プロジェクト: CarlesV/paleomix
 def _setup(self, _config, _temp):
     """Is called prior to '_run()' by 'run()'. Any code used to copy/link files,
     or other steps needed to ready the node for running may be carried out in this
     function. Checks that required input files exist, and raises an NodeError if
     this is not the case."""
     if fileutils.missing_executables(self.executables):
         raise NodeError("Executable(s) does not exist for node: %s" % (self,))
     self._check_for_missing_files(self.input_files, "input")
     self._check_for_missing_files(self.auxiliary_files, "auxiliary")
コード例 #2
0
ファイル: nodegraph.py プロジェクト: UMNPonyClub/paleomix
    def _check_required_executables(cls, nodes):
        exec_filenames = set()
        for node in nodes:
            exec_filenames.update(node.executables)

        missing_exec = missing_executables(exec_filenames)
        if missing_exec:
            raise NodeGraphError("Required executables are missing:\n\t%s"
                                 % ("\n\t".join(sorted(missing_exec))))
コード例 #3
0
    def _check_required_executables(cls, nodes):
        exec_filenames = set()
        for node in nodes:
            exec_filenames.update(node.executables)

        missing_exec = missing_executables(exec_filenames)
        if missing_exec:
            raise NodeGraphError("Required executables are missing:\n\t%s" %
                                 ("\n\t".join(sorted(missing_exec))))
コード例 #4
0
ファイル: node.py プロジェクト: health1987/paleomix
 def _setup(self, _config, _temp):
     """Is called prior to '_run()' by 'run()'. Any code used to copy/link files,
     or other steps needed to ready the node for running may be carried out in this
     function. Checks that required input files exist, and raises an NodeError if
     this is not the case."""
     if fileutils.missing_executables(self.executables):
         raise NodeError("Executable(s) does not exist for node: %s" %
                         (self, ))
     self._check_for_missing_files(self.input_files, "input")
     self._check_for_missing_files(self.auxiliary_files, "auxiliary")
コード例 #5
0
    def _check_required_executables(cls, nodes):
        exec_filenames, exec_requirements = set(), set()
        for node in nodes:
            exec_filenames.update(node.executables)
            exec_requirements.update(node.requirements)

        missing_exec = missing_executables(exec_filenames)
        if missing_exec:
            raise NodeGraphError("Required executables are missing:\n\t%s" \
                                % ("\n\t".join(sorted(missing_exec))))

        try:
            for requirement in exec_requirements:
                requirement()
        except versions.VersionRequirementError, error:
            raise NodeGraphError("Version requirements check failed for %s:\n\t%s" \
                                 % (requirement.name, error))
コード例 #6
0
ファイル: fileutils_test.py プロジェクト: schae234/pypeline
def test_missing_executables__mixed():
    assert_equal(missing_executables(["lsxxxx", "ls"]), ["lsxxxx"])
コード例 #7
0
ファイル: fileutils_test.py プロジェクト: schae234/pypeline
def test_missing_executables__non_executable():
    assert_equal(missing_executables(["lsxxxx"]), ["lsxxxx"])
コード例 #8
0
ファイル: fileutils_test.py プロジェクト: schae234/pypeline
def test_missing_executables__executable():
    assert_equal(missing_executables(["ls"]), [])
コード例 #9
0
ファイル: fileutils_test.py プロジェクト: schae234/pypeline
def test_missing_executables__mixed():
    assert_equal(missing_executables(["lsxxxx", "ls"]), ["lsxxxx"])
コード例 #10
0
ファイル: fileutils_test.py プロジェクト: schae234/pypeline
def test_missing_executables__non_executable():
    assert_equal(missing_executables(["lsxxxx"]), ["lsxxxx"])
コード例 #11
0
ファイル: fileutils_test.py プロジェクト: schae234/pypeline
def test_missing_executables__executable():
    assert_equal(missing_executables(["ls"]), [])
コード例 #12
0
ファイル: create_pileup.py プロジェクト: CarlesV/paleomix
def main(argv):
    parser = argparse.ArgumentParser(prog="paleomix create_pileup")
    parser.add_argument("output", help="BGZipped pileup file.")
    parser.add_argument("mpileup_args", nargs=argparse.REMAINDER)
    args = parser.parse_args(argv)

    missing = missing_executables(("samtools", "tabix", "bgzip"))
    if missing:
        sys.stderr.write("ERROR: Required executables are missing:\n")
        sys.stderr.write("    - %s\n" % "\n\t- ".join(missing))
        return 1

    with open(args.output, "w") as handle:
        bgzip = subprocess.Popen("bgzip",
                                 stdin  = subprocess.PIPE,
                                 stdout = handle)

        # While samtools mpileup has an option for specifying a list of
        # positions (-l), this requires traversing the entire file, and may
        # not calculate the BAQ. Given the low number of expected sites,
        # individual calls for each position are significantly faster.
        sys.stderr.write("Reading VCF from STDIN ...\n")
        positions = _collect_positions(sys.stdin)
        npositions = len(positions)
        sys.stderr.write(" - Read %i candidate positions ...\n"
                         % (npositions,))

        positions_file = args.output + ".positions"
        with open(positions_file, "w") as handle:
            for (contig, position) in positions:
                handle.write("%s\t%s\n" % (contig, position))
        sys.stderr.write(" - Wrote positions to '%s' ...\n"
                         % (positions_file,))

        sys.stderr.write("Collecting pileups:\n")
        call = ["samtools", "mpileup", "-R", "-l", positions_file]
        call.extend(args.mpileup_args)
        proc = subprocess.Popen(call,
                                stdout=subprocess.PIPE,
                                close_fds=True)

        line = "NA\tNA\t"
        index = npositions = 1
        for (index, line) in enumerate(proc.stdout, start=1):
            if (index - 1) % 100 == 0:
                contig, position, _ = line.split("\t", 2)
                print_status(index, contig, position, npositions)
            bgzip.stdin.write(line)

        contig, position, _ = line.split("\t", 2)
        print_status(index, contig, position, npositions, end="\n")

        if proc.wait():
            sys.stderr.write("ERROR: Error running samtools, return-code=%i:\n"
                             % proc.wait())
            sys.stderr.write("\t- Command: %s\n" % " ".join(call))
            return 1

        bgzip.stdin.close()
        if bgzip.wait():
            sys.stderr.write("ERROR: Error running bgzip, return-code %i\n"
                             % bgzip.wait())

    sys.stderr.write(" - Cleaning up ...")
    os.remove(positions_file)

    subprocess.check_call(["tabix", "-b", "2", "-e", "2", args.output])
    return 0