2017-09-06 43 views
1

私はsnakemakeに新しく、ファイルのファイルのいずれかまたはtrim_galoreのペアを取ることができます。トリミングされた出力ファイルのペアを取得します。私のSnakefileをすべて与えることなく、ルールをコピーして入力を変更したところ、以下の醜い解決策があります。よりよい解決策は何でしょうか?入力機能を使用してsnakemakeルール(.fq対.fq.gz)に少し異なる入力を受け入れる

#Trim galore paired end trimming rule for unzipped fastqs: 
rule trim_galore_unzipped_PE: 
    input: 
     r1=join(config['fq_in_path'], '{sample}1.fq'), 
     r2=join(config['fq_in_path'], '{sample}2.fq'), 
    output: 
     r1=join(config['trim_out_path'], '{sample}1_val_1.fq.gz'), 
     r2=join(config['trim_out_path'], '{sample}2_val_2.fq.gz'), 
    params: 
     out_path=config['trim_out_path'], 
    conda: 
     'envs/biotools.yaml', 
    shell: 
     'trim_galore --gzip -o {params.out_path} --paired {input.r1} {input.r2}' 

#Trim galore paired end trimming rule for gzipped fastqs: 
rule trim_galore_zipped_PE: 
    input: 
     r1=join(config['fq_in_path'], '{sample}1.fq.gz'), 
     r2=join(config['fq_in_path'], '{sample}2.fq.gz'), 
    output: 
     r1=join(config['trim_out_path'], '{sample}1_val_1.fq.gz'), 
     r2=join(config['trim_out_path'], '{sample}2_val_2.fq.gz'), 
    params: 
     out_path=config['trim_out_path'], 
    conda: 
     'envs/biotools.yaml', 
    shell: 
     'trim_galore --gzip -o {params.out_path} --paired {input.r1} {input.r2}' 

答えて

2

次のようにされて、おそらく最良の解決策です:既知のYAML値を使用して入力機能に

  1. パスのワイルドカード
  2. 、そのサンプル名を使用して、理論的なファイル名を作成。
  3. 使用Pythonの関数は、(技術的には、ファイルの拡張子は)
  4. 戻り、有効なファイルのリストを構築し、有効なファイルのリストを展開し、有効であるファイルを確認してください。

注:彼らはそれは入力機能で問題

  • が発生していない場合

    • 入力と出力が、それは空文字列を返すことができませんことを確認し、同じワイルドカードを持っている必要がありますSnakemakeはこれを「入力の欠如」の要件と解釈します。これはあなたが望むものではありません。
    • これらの提案を採用する場合は、ルール名を更新します。忘れました。

    Snakefile:

    configfile: "config.yaml" 
    
    from os.path import join 
    from os.path import exists 
    
    rule all: 
        input: 
         expand("{trim_out_path}/{sample}.{readDirection}.fq.gz", 
          trim_out_path=config["trim_out_path"], 
          sample=config["sampleList"], 
          readDirection=['1','2']) 
    
    
    def trim_galore_input_determination(wildcards): 
        potential_file_path_list = [] 
        # Cycle through both suffix possibilities: 
        for fastqSuffix in [".fq", ".fq.gz"]: 
    
         # Cycle through both read directions 
         for readDirection in ['.1','.2']: 
    
          #Build the list for ech suffix 
          potential_file_path = config["fq_in_path"] + "/" + wildcards.sample + readDirection + fastqSuffix 
    
          #Check if this file actually exists 
          if exists(potential_file_path): 
    
           #If file is legit, add to list of acceptable files 
           potential_file_path_list.append(potential_file_path) 
    
        # Checking for an empty list 
        if len(potential_file_path_list): 
         return potential_file_path_list 
        else: 
         return ["trim_galore_input_determination_FAILURE" + wildcards.sample] 
    
    rule trim_galore_unzipped_PE: 
        input: 
         unpack(trim_galore_input_determination) 
        output: 
         expand("{trim_out_path}/{{sample}}.{readDirection}.fq.gz", 
          trim_out_path=config["trim_out_path"], 
          readDirection=['1','2']) 
        params: 
         out_path=config['trim_out_path'], 
        conda: 
         'envs/biotools.yaml', 
        shell: 
         'trim_galore --gzip -o {params.out_path} --paired {input}' 
    

    config.yaml:

    fq_in_path: input/fq 
    trim_out_path: output 
    sampleList: ["mySample1", "mySample2"] 
    

    $ツリー:

    |-- [tboyarsk  1540 Sep 6 15:17] Snakefile 
    |-- [tboyarsk  82 Sep 6 15:17] config.yaml 
    |-- [tboyarsk  512 Sep 6 8:55] input 
    | |-- [tboyarsk  512 Sep 6 8:33] fq 
    | | |-- [tboyarsk   0 Sep 6 7:50] mySample1.1.fq 
    | | |-- [tboyarsk   0 Sep 6 8:24] mySample1.2.fq 
    | | |-- [tboyarsk   0 Sep 6 7:50] mySample2.1.fq 
    | | `-- [tboyarsk   0 Sep 6 8:24] mySample2.2.fq 
    | `-- [tboyarsk  512 Sep 6 8:55] fqgz 
    |  |-- [tboyarsk   0 Sep 6 7:50] mySample1.1.fq.gz 
    |  |-- [tboyarsk   0 Sep 6 8:32] mySample1.2.fq.gz 
    |  |-- [tboyarsk   0 Sep 6 8:33] mySample2.1.fq.gz 
    |  `-- [tboyarsk   0 Sep 6 8:32] mySample2.2.fq.gz 
    `-- [tboyarsk  512 Sep 6 7:55] output 
    

    $ snakemake -dry(入力:FG)

    rule trim_galore_unzipped_PE: 
        input: input/fq/mySample1.1.fq, input/fq/mySample1.2.fq 
        output: output/mySample1.1.fq.gz, output/mySample1.2.fq.gz 
        jobid: 1 
        wildcards: sample=mySample1 
    
    
    rule trim_galore_unzipped_PE: 
        input: input/fq/mySample2.1.fq, input/fq/mySample2.2.fq 
        output: output/mySample2.1.fq.gz, output/mySample2.2.fq.gz 
        jobid: 2 
        wildcards: sample=mySample2 
    
    
    localrule all: 
        input: output/mySample1.1.fq.gz, output/mySample2.1.fq.gz, output/mySample1.2.fq.gz, output/ mySample2.2.fq.gz 
        jobid: 0 
    
    Job counts: 
         count jobs 
         1  all 
         2  trim_galore_unzipped_PE 
         3 
    

    $ snakemake -dry(入力:fgqz)

    rule trim_galore_unzipped_PE: 
        input: input/fqgz/mySample1.1.fq.gz, input/fqgz/mySample1.2.fq.gz 
        output: output/mySample1.1.fq.gz, output/mySample1.2.fq.gz 
        jobid: 1 
        wildcards: sample=mySample1 
    
    
    rule trim_galore_unzipped_PE: 
        input: input/fqgz/mySample2.1.fq.gz, input/fqgz/mySample2.2.fq.gz 
        output: output/mySample2.1.fq.gz, output/mySample2.2.fq.gz 
        jobid: 2 
        wildcards: sample=mySample2 
    
    
    localrule all: 
        input: output/mySample1.1.fq.gz, output/mySample1.2.fq.gz, output/mySample2.1.fq.gz, output/ mySample2.2.fq.gz 
        jobid: 0 
    
    Job counts: 
         count jobs 
         1  all 
         2  trim_galore_unzipped_PE 
         3 
    

    それをより汎用的にする方法がありますが、あなた以来YAMLの設定を宣言して使用してファイル名の大部分をビルドします。私はその答えで議論することは避けます。単にそれが可能であり、幾分奨励されていると言います。

    「 - {{input}」が展開され、両方のファイルが提供されます。 forループのため、1は常に2の前に来ます。

  • 関連する問題