Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

String yaml representation of sample #369

Closed
nsheff opened this issue Jun 22, 2021 · 5 comments · Fixed by #489
Closed

String yaml representation of sample #369

nsheff opened this issue Jun 22, 2021 · 5 comments · Fixed by #489
Assignees

Comments

@nsheff
Copy link
Contributor

nsheff commented Jun 22, 2021

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
Copy link
Contributor Author

nsheff commented Jun 22, 2021

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' ?

@stolarczyk
Copy link
Member

stolarczyk commented Jun 22, 2021

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())

@nsheff
Copy link
Contributor Author

nsheff commented Jun 22, 2021

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

@stolarczyk
Copy link
Member

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

@nsheff
Copy link
Contributor Author

nsheff commented Jun 22, 2021

ah, I see now. I misread it indeed.

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants