step1.sf 2.33 KB
Newer Older
peguerin's avatar
peguerin committed
1
configfile: "config.yaml"
peguerin's avatar
peguerin committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
RUNS, = glob_wildcards('raw/{run}_R1.fastq.gz')
BARCODES, = glob_wildcards('barcodes/{barcode}.dat')
DICBARCODES={}
i=0
for bc in BARCODES:
   DICBARCODES[RUNS[i]]="barcodes/"+bc+".dat"
   i=i+1
#print(DICBARCODES)
rule all:
    input:
        expand('assembled/{run}/{run}.fastq', run=RUNS),
        expand('assembled/{run}/{run}.ali.fastq', run=RUNS),
        expand('assembled/{run}/{run}.ali.assigned.fastq', run=RUNS),
        expand('assembled/{run}/{run}.unidentified.fastq', run=RUNS),
        expand('log/remove_unaligned/{run}.log',run=RUNS),
        expand('log/illuminapairedend/{run}.log',run=RUNS),
        expand('log/assign_sequences/{run}.log',run=RUNS),
        expand('log/split_sequences/{run}.log',run=RUNS)

### Paired end alignment then keep reads with quality > 40
rule illuminapairedend:
    input:
        R1='raw/{run}_R1.fastq.gz',
        R2='raw/{run}_R2.fastq.gz'
    output:
        fq='assembled/{run}/{run}.fastq'
    log:
        'log/illuminapairedend/{run}.log'
peguerin's avatar
peguerin committed
30
31
    params:
        s_min=config["illuminapairedend"]["s_min"]
peguerin's avatar
peguerin committed
32
    shell:
peguerin's avatar
peguerin committed
33
        '''illuminapairedend -r {input.R2} {input.R1} --score-min={params.s_min} > {output.fq} 2> {log}'''
peguerin's avatar
peguerin committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

### Remove unaligned sequence records
rule remove_unaligned:
    input:
        fq='assembled/{run}/{run}.fastq'
    output:
        ali='assembled/{run}/{run}.ali.fastq'
    log:
        'log/remove_unaligned/{run}.log'
    shell:
        '''obigrep -p 'mode!=\"joined\"' {input.fq} > {output.ali} 2> {log}'''

### Assign each sequence record to the corresponding sample/marker combination
rule assign_sequences:
    input:
        'assembled/{run}/{run}.ali.fastq',
        lambda wildcards: DICBARCODES[wildcards.run]
    output:
        assign='assembled/{run}/{run}.ali.assigned.fastq',
        unid='assembled/{run}/{run}.unidentified.fastq'
    log:
        'log/assign_sequences/{run}.log'
    shell:
        '''ngsfilter -t {input[1]} -u {output.unid} {input[0]} --fasta-output > {output.assign} 2> {log}'''

### Split the input sequence file in a set of subfiles according to the values of attribute `sample`
rule split_sequences:
    input:
        'assembled/{run}/{run}.ali.assigned.fastq'
    params:
        'samples/{run}_sample_'
    log:
        'log/split_sequences/{run}.log'
    shell:
        '''obisplit -p "{params}" -t sample --fasta {input} 2> {log}'''