from os import listdir
from os.path import isfile, dirname

def getPath(sample, mate):
    if mate == "1":
        return config['entries'][sample]['main']['forward_reads']
    elif mate == "2":
        return config['entries'][sample]['main']['reverse_reads']

rule all:
    input: 
         expand("preprocessing/{sample}_R{mate}.fastq.gz", sample=config['entry_order'], mate=[1,2])

rule create_hardlink:
    input:
        lambda wildcards: getPath(wildcards.sample, wildcards.mate)
    output:
        "preprocessing/{sample}_R{mate, \d}.{extension}"
    threads:
        1
    shell:
        """
        if file {input} | grep -q "gzip"; then
            ln `readlink -f {input}` {output}
        else
            gzip -c {input} > {output}
        fi
        """
