def get_r_doc(image_dir):
    raw_r_doc = utils.docker_exec(
        image_dir,
        "sh -c \"echo 'ip <- as.data.frame(installed.packages()[,c(1,3:4)]) \n rownames(ip) <- NULL \n ip <- ip[is.na(ip\$Priority),1:2,drop=FALSE] \n print(ip, row.names=FALSE)' > temp.r; Rscript temp.r; rm temp.r\""
    )
    packages = raw_r_doc.strip().split("\n")

    r_version_output = utils.docker_exec(image_dir, "R --version | head -1")
    try:
        r_version = re.search("(\d+\.)(\d+\.)(\*|\d+)",
                              r_version_output).group(0)
    except AttributeError as e:
        raise ValueError(
            "the R has produced output with an improperly formatted version. Something has likely gone wrong with this script, ensure that the output has a version properly parsed by the regex in the function write_r_doc.\n\tOutput: "
            + r_version_output)

    package_json = [{"r": r_version}]
    for package in packages[1:]:
        processed_tuple = re.sub(' +', ' ', package.strip()).split(' ')

        assert len(processed_tuple
                   ) == 2, "Asserting format for {} is correct".format(package)

        json = {processed_tuple[0]: processed_tuple[1]}
        package_json.append(json)

    return package_json
def get_python_doc(params):
  image_dir = params.image_dir
  python_version_output = utils.docker_exec(image_dir, "python3 --version")
  raw_python_doc = utils.docker_exec(image_dir, "pip list --format=json")

  try:
    python_version = re.search("(\d+\.)(\d+\.)(\*|\d+)", python_version_output).group(0)
  except AttributeError as e:
    raise ValueError("the python command has produced output with an improperly formatted version. Something has likely gone wrong with this script, ensure that the output has a version properly parsed by the regex in the function write_python_doc. \n\tOutput: " + python_version_output)

  json_python_doc = json.loads(raw_python_doc)
  json_python_doc = list(map(lambda package: { package["name"]: package["version"] }, json_python_doc))
  json_python_doc.append({"python": python_version})

  return json_python_doc
def get_gatk_doc(image_dir):
    cmd = "ls /etc/ | grep gatk | tr '-' ' ' | awk '{print $2}'"
    gatk_version = utils.docker_exec(image_dir, cmd)

    return [{"gatk": gatk_version}]