def parse_and_link(file, symlink_dir, metadata_dict):
    match_old = re.match(r".*?/([^_/]+)_([a-zA-Z0-9-.]+)_s_([0-9]+)_(1|2)_sequence.txt.gz",file)
    match_new = re.match(r".*?/([a-zA-Z0-9-.]+)_([^_/]+)_[CAGTN]+_L([0-9]+)_R(1|2).fastq.gz",file)
    if match_old:
        run_id = match_old.group(1)
        sample = match_old.group(2)
        lane = int(match_old.group(3))
        pair = match_old.group(4)
        encoding = 'I'
    elif match_new:
        run_id = match_new.group(2)
        sample = match_new.group(1)
        lane = int(match_new.group(3))
        pair = match_new.group(4)
        encoding = 'S'
    else:
        print "Unable to parse name of fastq file %s ." % file
        sys.exit(1)
    newfile = os.path.join(symlink_dir, "%s_%s_L%d_%s.fastq.gz" % 
                                    (sample, run_id, lane, pair))
    metadata_dict[os.path.basename(newfile)]['sample'] = sample
    metadata_dict[os.path.basename(newfile)]['run_id'] = run_id
    metadata_dict[os.path.basename(newfile)]['lane'] = lane
    metadata_dict[os.path.basename(newfile)]['pair'] = pair
    metadata_dict[os.path.basename(newfile)]['encoding'] = encoding
    relative_sourcefile = os.path.relpath(file, symlink_dir)
    mkLink(relative_sourcefile, newfile)
    return newfile
Parse metadata out of input filename and construct symlink.
dataset/ETHPy150Open vlsci/variant_calling_pipeline/input_fastq.py/parse_and_link