Unverified Commit c85db3fd authored by E Rasche's avatar E Rasche
Browse files

Some more command refactoring

parent 73337725
Loading
Loading
Loading
Loading
+15 −22
Original line number Diff line number Diff line
@@ -253,18 +253,17 @@ class Bam(Binary):
            raise Exception(message)

        # Get the version of samtools via --version-only, if available
        p = subprocess.Popen(['samtools', '--version-only'],
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        output, error = p.communicate()

        try:
            output = subprocess.check_output(['samtools', '--version-only'])
            # --version-only is available
            # Format is <version x.y.z>+htslib-<a.b.c>
        if p.returncode == 0:
            version = output.split('+')[0]
            return version
        except subprocess.CalledProcessError:
            # --version-only not available
            pass

        output = subprocess.Popen(['samtools'], stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()[1]
        output = subprocess.check_output(['samtools'])
        lines = output.split('\n')
        for line in lines:
            if line.lower().startswith('version'):
@@ -294,10 +293,8 @@ class Bam(Binary):

    def _is_coordinate_sorted(self, file_name):
        """See if the input BAM file is sorted from the header information."""
        params = ["samtools", "view", "-H", file_name]
        output = subprocess.Popen(params, stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()[0]
        # find returns -1 if string is not found
        return output.find("SO:coordinate") != -1 or output.find("SO:sorted") != -1
        output = subprocess.check_output(["samtools", "view", "-H", file_name])
        return 'SO:coordinate' in output or 'SO:sorted' in output

    def dataset_content_needs_grooming(self, file_name):
        """See if file_name is a sorted BAM file"""
@@ -322,8 +319,7 @@ class Bam(Binary):
                return False
            index_name = tempfile.NamedTemporaryFile(prefix="bam_index").name
            stderr_name = tempfile.NamedTemporaryFile(prefix="bam_index_stderr").name
            command = 'samtools index %s %s' % (file_name, index_name)
            proc = subprocess.Popen(args=command, shell=True, stderr=open(stderr_name, 'wb'))
            proc = subprocess.Popen(['samtools', 'index', file_name, index_name], stderr=open(stderr_name, 'wb'))
            proc.wait()
            stderr = open(stderr_name).read().strip()
            if stderr:
@@ -366,8 +362,8 @@ class Bam(Binary):
        tmp_sorted_dataset_file_name_prefix = os.path.join(tmp_dir, 'sorted')
        stderr_name = tempfile.NamedTemporaryFile(dir=tmp_dir, prefix="bam_sort_stderr").name
        samtools_created_sorted_file_name = "%s.bam" % tmp_sorted_dataset_file_name_prefix  # samtools accepts a prefix, not a filename, it always adds .bam to the prefix
        command = "samtools sort %s %s" % (file_name, tmp_sorted_dataset_file_name_prefix)
        proc = subprocess.Popen(args=command, shell=True, cwd=tmp_dir, stderr=open(stderr_name, 'wb'))
        proc = subprocess.Popen(['samtools', 'sort', file_name, tmp_sorted_dataset_file_name_prefix],
                                cwd=tmp_dir, stderr=open(stderr_name, 'wb'))
        exit_code = proc.wait()
        # Did sort succeed?
        stderr = open(stderr_name).read().strip()
@@ -1309,11 +1305,8 @@ class ExcelXls(Binary):
    edam_format = "format_3468"

    def sniff(self, filename):
        mime_type = subprocess.check_output("file --mime-type '{}'".format(filename), shell=True).rstrip()
        if mime_type.find("application/vnd.ms-excel") != -1:
            return True
        else:
            return False
        mime_type = subprocess.check_output(['file', '--mime-type', filename]).strip()
        return "application/vnd.ms-excel" in mime_type

    def get_mime(self):
        """Returns the mime type of the datatype"""
+5 −10
Original line number Diff line number Diff line
@@ -116,17 +116,12 @@ def get_affected_packages(args):
    """
    recipes_dir = args.recipes_dir
    hours = args.diff_hours
    cmd = """cd '%s' && git log --diff-filter=ACMRTUXB --name-only --pretty="" --since="%s hours ago" | grep -E '^recipes/.*/meta.yaml' | sort | uniq""" % (recipes_dir, hours)
    pkg_list = check_output(cmd, shell=True)
    ret = list()
    for pkg in pkg_list.strip().split('\n'):
    cmd = ['git', 'log', '--diff-filter=ACMRTUXB', '--name-only', '--pretty=""', '--since="%s hours ago"' % hours]
    changed_files = subprocess.check_output(cmd, cwd=recipes_dir).strip().split('\n')
    pkg_list = set([x for x in changed_files if x.startswith('recipes/') and x.endswith('meta.yaml')])
    for pkg in pkg_list:
        if pkg and os.path.exists(os.path.join(recipes_dir, pkg)):
            ret.append((get_pkg_name(args, pkg), get_tests(args, pkg)))
    return ret


def check_output(cmd, shell=True):
    return subprocess.check_output(cmd, shell=shell)
            yield (get_pkg_name(args, pkg), get_tests(args, pkg))


def conda_versions(pkg_name, file_name):
+1 −2
Original line number Diff line number Diff line
@@ -55,8 +55,7 @@ def _new_versions(quay, conda):

def run_channel(args, build_last_n_versions=1):
    """Build list of involucro commands (as shell snippet) to run."""
    pkgs = get_affected_packages(args)
    for pkg_name, pkg_tests in pkgs:
    for pkg_name, pkg_tests in get_affected_packages(args):
        repo_data = _fetch_repo_data(args)
        c = conda_versions(pkg_name, repo_data)
        # only package the most recent N versions