Skip to content

Commit

Permalink
Add tool+cwl spec to flatten a list of lists of files
Browse files Browse the repository at this point in the history
  • Loading branch information
Janneke van der Zwaan committed Oct 9, 2018
1 parent 3c0c8b5 commit db01d3f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
20 changes: 20 additions & 0 deletions nlppln/commands/flatten_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python
import click
import json
import codecs
import itertools


@click.command()
def command():
with codecs.open('files.json', encoding='utf-8') as data:
list_of_lists = json.load(data)

flattened = list(itertools.chain(*list_of_lists))

stdout_text = click.get_text_stream('stdout')
stdout_text.write(json.dumps({'out_files': flattened}))


if __name__ == '__main__':
command()
27 changes: 27 additions & 0 deletions nlppln/cwl/flatten-list.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env cwlrunner
cwlVersion: v1.0
class: CommandLineTool
baseCommand: ["python", "-m", "nlppln.commands.flatten_list"]
requirements:
InlineJavascriptRequirement: {}
InitialWorkDirRequirement:
listing:
- entryname: files.json
entry: $(JSON.stringify(inputs.list))

inputs:
list:
type:
type: array
items:
type: array
items: File


stdout: cwl.output.json

outputs:
out_files:
type: File[]
outputBinding:
glob: "*"

0 comments on commit db01d3f

Please sign in to comment.