Esempio n. 1
0
def test_upload(runner):
    source = os.path.join(testWD,"data","test_reads_R1.fastq.gz")

    cmd = f"-b {bucket} -c {credentials_path} upload {source} -o {f1target} -m /tmp/{metadata_name} --silent"
    log.debug(cmd)
    res = runner.invoke(root, cmd.split())
    assert res.exit_code == 0
Esempio n. 2
0
def verify_fq_suffix(fn):
    """Makes sure the provided file looks like a fastq"""

    #Check suffix
    if not fn.endswith(("fastq.gz","fq.gz","fastq","fq")):
        raise Exception(f"File {fn} is not a fastq")
    log.debug(f'Verified that {fn} is a zipped fastq')
    #Check for unresolved symlink
    if os.path.islink(fn):
        if not os.path.exists(os.readlink(fn)):
            raise Exception(f"File {fn} is an unresolved symlink")
Esempio n. 3
0
def read_credentials(credentials_path):
    """Set endpoint, aws id and aws key using a json-file"""
    with open(credentials_path, 'r') as inp:
        c = json.load(inp)

    ep = c['endpoint']
    aid = c['aws_access_key_id']
    key = c['aws_secret_access_key']
    log.debug("Credentials file successfully utilized")

    if not all([c['endpoint'], c['aws_access_key_id'], c['aws_secret_access_key']]):
        raise MissingCredentialsError('One or more values missing from provided json.')

    return [ep,aid,key]
Esempio n. 4
0
def test_upload_no_destination(runner):
    source = os.path.join(testWD,"data","test_reads_R1.fastq.gz")
    code_cnt = 0

    dest = os.path.basename(source)

    cmd = f"-b {bucket} -c {credentials_path} upload {source} -m /tmp/{metadata_name} --silent"
    log.debug(cmd)
    res = runner.invoke(root, cmd.split())
    code_cnt = code_cnt + res.exit_code
    cmd1 = f"-b {bucket} -c {credentials_path} delete {dest} -f"
    res1 = runner.invoke(root, cmd1.split())
    cmd2 = f"-b {bucket} -c {credentials_path} delete {metadata_name} -f"
    res2 = runner.invoke(root, cmd2.split())
    code_cnt = code_cnt + res1.exit_code
    code_cnt = code_cnt + res2.exit_code
    assert code_cnt == 0
Esempio n. 5
0
def generate_tagmap(fn, tag, output_path="{}/meta-{}.json".format(os.getcwd(), TIMESTAMP)):
    """Creates a json file with filenames and tags"""
    # Check if meta exists, else make it
    if not os.path.exists(output_path):
        data = {fn: {'tag': tag}}
        with open(output_path, 'w') as out:
            json.dump(data, out, indent=4)
    else:
        # Read the current meta
        with open(output_path, 'r') as inp:
            current_data = json.load(inp)

        # New data
        new_data = {fn: {'tag': tag}}
        updated_data = {**current_data, **new_data}

        # Write updated
        with open(output_path, 'w') as out:
            json.dump(updated_data, out, indent=4)

    log.debug(f'Generated metadata file {output_path}')
Esempio n. 6
0
def verify_fq_content(fn):
    """Makes sure fastq file contains fastq data"""
    nuc = set("ATCGN\n")
    lineno = 0
    f1 = gzip.open(fn, "r")
    for line in f1:
        line = line.decode('UTF-8')
        lineno = lineno + 1 
        if lineno == 1:
            corr = re.match("^@",line)
        elif lineno == 2:
            corr = set(line) <= nuc
        elif lineno == 3:
            corr = re.match("^\+",line)
        elif lineno == 4:
            lineno = 0

        if not corr:
            raise Exception(f"File{fn} does not look like a fastq at line {lineno}: {line}")
    f1.close()
    
    if lineno % 4 != 0:
        raise Exception(f"File {fn} is missing data")
    log.debug(f'Verified that {fn} resembles a fastq')
Esempio n. 7
0
def test_download(runner):
    dest =  os.path.join('tmp','tst.fq')
    cmd = f"-b {bucket} -c {credentials_path} download -f {f1target} -o /{dest} --silent"
    log.debug(cmd)
    res = runner.invoke(root, cmd.split())
    assert res.exit_code == 0