peppy icon indicating copy to clipboard operation
peppy copied to clipboard

String yaml representation of sample

Open nsheff opened this issue 4 years ago • 5 comments

Is there any way for me to get a straight-up yaml representation of a sample? I found sample.to_yaml() but this appears to only be able to output to a file.

I can also just print(sample), but then I get all this extra stuff too:

Sample 'sample1' in Project (/home/nsheff/code/refgenie_looper_demo/pep_bio.yaml)

sample_name:         sample1
protocol:            RNA-seq
organism:            human
read1:               data/sample1_1.fq.gz
read2:               data/sample1_2.fq.gz
Index:               /home/nsheff/code/refgenie_sandbox/alias/t7/bwa_index/default/t7.fa
pipeline_interfaces: pipeline_interface.yaml
InputFile1:          data/sample1_1.fq.gz
InputFile2:          data/sample1_2.fq.gz
genome:              t7
prealignments:       t7, t7, t7

...                (showing first 10)

What I need is just a function that gives me the yaml representation of the sample.

nsheff avatar Jun 22 '21 19:06 nsheff

there's also something confusing int he docs for to_yaml:

Serializes itself in YAML format. Parameters:

path (str): A file path to write yaml to; provide this orthe subs_folder_path

what is 'orthe subs_folder_path' ?

nsheff avatar Jun 22 '21 19:06 nsheff

yes, to_yaml method requires a path. For now, you should be able to do something like this:

import yaml
from peppy import Project

yaml.dump(Project("config.yaml").samples[0].to_dict())

stolarczyk avatar Jun 22 '21 20:06 stolarczyk

I want to do this in a jinja template, so it's not ideal to write to disk and then re-read it. I'm actually not sure it would work

nsheff avatar Jun 22 '21 21:06 nsheff

The line I pasted doesn't write to disk. It converts the sample to dict and then to string representation of YAML.

stolarczyk avatar Jun 22 '21 21:06 stolarczyk

ah, I see now. I misread it indeed.

unfortunately I can't use yaml.dump in a jinja template, though

nsheff avatar Jun 22 '21 21:06 nsheff