Hi! I just started using Snakemake and am struggeling to figure whats wrong with my Snakefile or code. The rules get_pheno and get_var work fine. However, the rule merge_pheno_var generates the following error message. I appreciate any help and general advice!

Traceback (most recent call last):
  File "/Users/../Desktop/00_get_variables/.snakemake/scripts/tmpyt17geyr.merge.py", line 10, in <module>
    df.to_csv(snakemake.output.out, sep='t', index=False)
  File "/Users/../opt/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py", line 3402, in to_csv
    storage_options=storage_options,
  File "/Users/../opt/anaconda3/lib/python3.7/site-packages/pandas/io/formats/format.py", line 1083, in to_csv
    csv_formatter.save()
  File "/Users/../opt/anaconda3/lib/python3.7/site-packages/pandas/io/formats/csvs.py", line 234, in save
    storage_options=self.storage_options,
  File "/Users/../opt/anaconda3/lib/python3.7/site-packages/pandas/io/common.py", line 563, in get_handle
    storage_options=storage_options,
  File "/Users/../opt/anaconda3/lib/python3.7/site-packages/pandas/io/common.py", line 371, in _get_filepath_or_buffer
    raise ValueError(msg)
ValueError: Invalid file path or buffer object type: <class 'snakemake.io.Namedlist'>

Here my Snakefile:

configfile: 'config.yaml'

rule all:
    input:
        expand('results/{name}{key}.txt', name=config["names"], key=config["keys"])

rule get_pheno:
    input: 
        "data/pws_all_subs.phenpt", 
    output: 
        temp(expand('results/{name}{key}_temp.txt', name=config["names"], key=config["keys"]))
    conda: 
        'envs/env.yaml'
    script: 
        'scripts/get_pheno.py'


rule get_var:
    input:
        'data/02_var_movement.txt', 
        'data/pca_results.eigenvec',
        'results/pws_m_temp.txt'
    output:
        'results/var_pws_cd_ld.txt'
    conda:
        'envs/env.yaml'
    script:
        'scripts/get_var.py'


rule merge_pheno_var:
    input:
        'results/var_pws_cd_ld.txt',
        expand('results/{name}{key}_temp.txt', name=config["names"], key=config["keyes"])
    output:
        out = expand('results/{name}{key}.txt', name=config["names"], key=config["keyes"])
    conda:
        'envs/env.yaml'
    script:
        'scripts/merge.py'

My config file:

names:
 - cd_
 - ls_
 - pws_
keys:
 - hs
 - nb
 - dg
 - wp
 - m

And code of the rule merge_pheno_var:

import pandas as pd
covs = pd.read_csv(snakemake.input[0], sep='t')
pheno = pd.read_csv(snakemake.input[1], sep='t')
df = pd.merge(covs, pheno, on='IID', suffixes=(None, '_'))
df = df[['FID', 'IID','Pheno']]
df.to_csv(snakemake.output.out, sep='t', index=False)



Source link