<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Questions
Could this be a CWL compiler?
WIll it take a root document and return the whole structure?
Can I find the dockerRequirement anywhere in the doc?
Can I find the dockerRequirement using the schema?
1. CWL Docker Compiler
What does that mean? Abstractly, that it would read an input document, look for all docker requirements and hints, pull the images, and then write a shell script to reload everything
2. Root document and return whole structure?
Step1:  Yes, that works
Step2:  extract docker image names
Step3:  Docker IO
Query docker for the sha of the docker image id
<ASSISTANT_TASK:>
Python Code:
workflow = parse('/Users/dcl9/Code/python/mmap-cwl/mmap.cwl')
Explanation: Questions
Could this be a CWL compiler?
WIll it take a root document and return the whole structure?
Can I find the dockerRequirement anywhere in the doc?
Can I find the dockerRequirement using the schema?
1. CWL Docker Compiler
What does that mean? Abstractly, that it would read an input document, look for all docker requirements and hints, pull the images, and then write a shell script to reload everything
2. Root document and return whole structure?
End of explanation
# This function will find dockerImageId anyhwere in the tree
def find_key(d, key, path=[]):
    if isinstance(d, list):
        for i, v in enumerate(d):
            for f in find_key(v, key, path + [str(i)]):
                yield f
    elif isinstance(d, dict):
        if key in d:
            pathstring = '/'.join(path + [key])
            yield pathstring
        for k, v in d.items():
            for f in find_key(v, key, path + [k]):
                yield f
    
# Could adapt to find class: DockerRequirement instead
for x in find_key(workflow, 'dockerImageId'):
    print x, dpath.util.get(workflow, x)
dpath.util.get(workflow, 'steps/0/run/steps/0/run/hints/0')
Explanation: Yes, that works
End of explanation
def image_names(workflow):
    image_ids = []
    for x in find_key(workflow, 'dockerImageId'):
        image_id = dpath.util.get(workflow, x)
        if image_id not in image_ids: image_ids.append(image_id) 
    return image_ids
image_names(workflow)
import docker
def docker_hashes(image_ids):
    for name in image_ids:
        print name
docker_hashes(image_names(workflow))
Explanation: extract docker image names
End of explanation
%%sh
eval $(docker-machine env default)
import docker_io
images = get_image_metadata(client, 'dukegcb/xgenovo')
for img in images:
    write_image(client, img, '/tmp/images')
md
Explanation: Docker IO
Query docker for the sha of the docker image id
End of explanation
<END_TASK>