I gave a call in this way:

print("-L", str(cfg.project["phenotype"][0]), str(cfg.project["phenotype"][1]))

This will read the below one
phenotype:
- embryo: [SAMN00990702-1]
- larva: [SAMN00990702-2]

And it should give:

-L embryo,larva

But it is giving like:

-L {'embryo': ['SAMN00990702-1']} {'larva': ['SAMN00990702-2']}

Can anyone help me in solving this problem. Thank you !!

Recommended Answers

All 5 Replies

It means that cfg.project["phenotype"][0] is a dictionary with a single key and you only want to print the key. You can get a key from a non empty dictionary with next(iter(dictionary)). So I suggest

d = cfg.project["phenotype"]
print("-L", next(iter(d[0])), next(iter(d[1])))

Of course, if there are more than 1 key in d[i], some keys won't be shown.

I should not replace cfg.project["phenotype"] with "d"

So, Can I give it in this way:

"-L", str(cfg.project(["phenotype"][0])), str(cfg.project(["phenotype"][1]))

Why shouldn't you replace cfg.project["phenotype"] with d ? d is shorter.

actually this is my whole command:

print(' '.join([cfg.tool_cmd("cuffdiff"), "-p", str(cfg.project["analysis"]["threads"]), "-b", str(cfg.project["genome"]["fasta"]), "-u", cfg.project["experiment"]["merged"], "-L", str(cfg.project(["phenotype"][0])), str(cfg.project(["phenotype"][1])), "-o", output_folder] + [cfg.project["samples"][0]["files"]["bam"] + ' ' + cfg.project["samples"][1]["files"]["bam"]], cfg.project["analysis"]["log_file"])

You can try something such as

p = cfg.project

command = (
    "{cuffdiff} -p {threads} -b {fasta} -u {merged} "
    "-L {pheno0},{pheno1} -o {ofolder} {bam0} {bam1} {log}"
    ).format(
    cuffdiff=cfg.tool_cmd("cuffdiff"),
    threads=p["analysis"]["threads"],
    fasta=p["genome"]["fasta"],
    merged=p["experiment"]["merged"],
    pheno0=p["phenotype"][0],
    pheno1=p["phenotype"][1],
    ofolder=output_folder,
    bam0=p["samples"][0]["files"]["bam"],
    bam1=p["samples"][1]["files"]["bam"],
    log=p["analysis"]["log_file"]
)

print(command)

with your corrections. (for example, you may try to replace p["phenotype"][0] with next(iter(p["phenotype"][0]))).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.