cwl

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2018 License: MIT Imports: 16 Imported by: 0

README

cwl.go

Build Status GoDoc

cwl.go is just a parser of CWL file and input files based on CWL, for example 1st-tool.yaml and echo-job.yml.

Fully documented here!

Example

package main

import (
	"fmt"
	"os"

	cwl "github.com/otiai10/cwl.go"
)

func main() {
	file, _ := os.Open("hello.cwl")
	doc := cwl.NewCWL()
	doc.Decode(file)
	fmt.Printf("%+v\n", doc)
}

Tests

Prerequisite

xtest.sh requires Go package github.com/otiai10/mint

To install it.

go get -u github.com/otiai10/mint

Why xtest.sh and How to do test with it.

Because there are both array and dictionary in CWL specification, and as you know Golang can't keep order of map keys, the test fails sometimes by order problem. Therefore, ./xtest.sh tries testing each case several times eagerly unless it passes.

For all cases,

./xtest.sh

For only 1 case which matches _wf3,

./xtest.sh _wf3

Or if you want to execute single test for just 1 time (NOT eagerly),

go test ./tests -run _wf3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StringArrayable

func StringArrayable(i interface{}) []string

StringArrayable converts "xxx" to ["xxx"] if it's not slice.

Types

type Alias

type Alias struct {
	// contains filtered or unexported fields
}

Alias represents an expression with "$(xxx.yyy)"

func (*Alias) Key

func (a *Alias) Key() string

Key extract the exact (and flattened) name of an expression.

type Argument

type Argument struct {
	Value   string
	Binding *Binding
}

Argument represents an element of "arguments" of CWL @see http://www.commonwl.org/v1.0/CommandLineTool.html#CommandLineTool

func (Argument) Flatten

func (arg Argument) Flatten() []string

Flatten ...

func (Argument) New

func (_ Argument) New(i interface{}) Argument

New constructs an "Argument" struct from any interface.

type Arguments

type Arguments []Argument

Arguments represents a list of "Argument"

func (Arguments) Len

func (args Arguments) Len() int

Len for sorting.

func (Arguments) Less

func (args Arguments) Less(i, j int) bool

Less for sorting.

func (Arguments) New

func (_ Arguments) New(i interface{}) Arguments

New constructs "Arguments" struct.

func (Arguments) Swap

func (args Arguments) Swap(i, j int)

Swap for sorting.

type BaseCommands

type BaseCommands []string

BaseCommands represents "baseCommand" of CWL CommandLineTool. @see http://www.commonwl.org/v1.0/CommandLineTool.html#CommandLineTool

func (BaseCommands) New

func (baseCommands BaseCommands) New(i interface{}) BaseCommands

New constructs "BaseCommands" struct.

type Binding

type Binding struct {
	// Common
	LoadContents bool
	// CommandLineBinding
	Position   int    `json:"position"`
	Prefix     string `json:"prefix"`
	Separate   bool   `json:"separate"`
	Separator  string `json:"separator"`
	ShellQuote bool   `json:"shellQuote"`
	ValueFrom  *Alias `json:"valueFrom"`
	// CommandOutputBinding
	Glob     []string `json:"glob"`
	Eval     *Eval    `json:"outputEval"`
	Contents bool     `json:"loadContents"`
}

Binding represents and combines "CommandLineBinding" and "CommandOutputBinding" @see - http://www.commonwl.org/v1.0/CommandLineTool.html#CommandLineBinding - http://www.commonwl.org/v1.0/CommandLineTool.html#CommandOutputBinding

func (Binding) New

func (binding Binding) New(i interface{}) *Binding

New constructs new "Binding".

type Directory

type Directory struct {
	Listing []Entry
}

Directory represents direcotry entry. @see http://www.commonwl.org/v1.0/CommandLineTool.html#Directory

type Dirent

type Dirent struct {
	Entry     string
	EntryName string
	Writable  bool
}

Dirent represents ? @see http://www.commonwl.org/v1.0/CommandLineTool.html#Dirent

type DockerRequirement

type DockerRequirement struct {
	DockerPull            string
	DockerLoad            string
	DockerFile            string
	DockerImport          string
	DockerImageID         string
	DockerOutputDirectory string
}

DockerRequirement is supposed to be embeded to Requirement. @see http://www.commonwl.org/v1.0/CommandLineTool.html#DockerRequirement

type Entry

type Entry struct {
	Class    string
	Location string
	Path     string
	Basename string
	File
	Directory
	Dirent
}

Entry represents fs entry, it means [File|Directory|Dirent]

func (*Entry) LinkTo

func (entry *Entry) LinkTo(destdir, srcdir string) error

LinkTo creates hardlink of this entry under destdir.

func (Entry) New

func (_ Entry) New(i interface{}) Entry

New constructs an Entry from interface

func (Entry) NewList

func (_ Entry) NewList(i interface{}) []Entry

NewList constructs a list of Entry from interface

type EnvDef

type EnvDef struct {
	Name  string
	Value string
}

EnvDef represents "EnvironmentDef", only appears if requirement class is "EnvVarRequirement" @see http://www.commonwl.org/v1.0/CommandLineTool.html#EnvironmentDef

func (EnvDef) NewList

func (_ EnvDef) NewList(i interface{}) []EnvDef

NewList constructs a list of EnvDef from interface

type EnvVarRequirement

type EnvVarRequirement struct {
	EnvDef []EnvDef
}

EnvVarRequirement is supposed to be embeded to Requirement. @see http://www.commonwl.org/v1.0/CommandLineTool.html#EnvVarRequirement

type Eval

type Eval struct {
	Raw string
}

Eval represents [output]Eval

func (Eval) ToJavaScriptString

func (eval Eval) ToJavaScriptString() (string, error)

ToJavaScriptString , Because "outputEval" is **NOT** pure JavaScript! What The Fuck!!!!!!!!!!!!!!!

type Field

type Field struct {
	Name    string
	Doc     string
	Types   []Type
	Binding *Binding
	Label   string
}

Field represents CommandInputRecordField @see http://www.commonwl.org/v1.0/CommandLineTool.html#CommandInputRecordField

func (Field) New

func (_ Field) New(i interface{}) Field

New constructs a Field struct from any interface.

type Fields

type Fields []Field

Inputs represents "inputs" field in CWL.

func (Fields) Len

func (ins Fields) Len() int

Len for sorting.

func (Fields) Less

func (ins Fields) Less(i, j int) bool

Less for sorting.

func (Fields) New

func (_ Fields) New(i interface{}) Fields

New constructs new "Inputs" struct.

func (Fields) Swap

func (ins Fields) Swap(i, j int)

Swap for sorting.

type File

type File struct {
	Dirname string
	Size    int64
	Format  string
}

File represents file entry. @see http://www.commonwl.org/v1.0/CommandLineTool.html#File

type Graph

type Graph struct {
	Run *Root
}

Graph represents an element of "steps"

type Graphs

type Graphs []*Root

Graphs represents "$graph" field in CWL.

func (Graphs) Len

func (g Graphs) Len() int

Len for sorting

func (Graphs) Less

func (g Graphs) Less(i, j int) bool

Less for sorting

func (Graphs) New

func (_ Graphs) New(i interface{}) Graphs

New constructs "Graphs" from interface.

func (Graphs) Swap

func (g Graphs) Swap(i, j int)

Swap for sorting

type Hint

type Hint struct {
	Class      string
	DockerPull string   // Only appears if class is "DockerRequirement"
	CoresMin   int      // Only appears if class is "ResourceRequirement"
	Envs       []EnvDef // Only appears if class is "EnvVarRequirement"
	FakeField  string   // Only appears if class is "ex:BlibberBlubberFakeRequirement"
	Import     string
}

Hint ...

func (Hint) New

func (_ Hint) New(i interface{}) Hint

New constructs Hint from interface.

type Hints

type Hints []Hint

Hints ...

func (Hints) New

func (_ Hints) New(i interface{}) Hints

New constructs "Hints" struct.

type InitialWorkDirRequirement

type InitialWorkDirRequirement struct {
	Listing []Entry
}

InitialWorkDirRequirement is supposed to be embeded to Requirement. @see http://www.commonwl.org/v1.0/CommandLineTool.html#InitialWorkDirRequirement

type InlineJavascriptRequirement

type InlineJavascriptRequirement struct {
	ExpressionLib []JavascriptExpression
}

InlineJavascriptRequirement is supposed to be embeded to Requirement. @see http://www.commonwl.org/v1.0/CommandLineTool.html#InlineJavascriptRequirement

type Input

type Input struct {
	ID             string          `json:"id"`
	Label          string          `json:"label"`
	Doc            string          `json:"doc"`
	Format         string          `json:"format"`
	Binding        *Binding        `json:"inputBinding"`
	Default        *InputDefault   `json:"default"`
	Types          []Type          `json:"type"`
	SecondaryFiles []SecondaryFile `json:"secondary_files"`
	// Input.Provided is what provided by parameters.(json|yaml)
	Provided *Provided `json:"-"`
	// Requirement ..
	RequiredType *Type
	Requirements Requirements
}

Input represents "CommandInputParameter". @see http://www.commonwl.org/v1.0/CommandLineTool.html#CommandInputParameter

func (*Input) Flatten

func (input *Input) Flatten() []string

Flatten ...

func (Input) New

func (input Input) New(i interface{}) *Input

New constructs "Input" struct from interface{}.

type InputDefault

type InputDefault struct {
	ID string

	Self  interface{}
	Kind  reflect.Kind
	Entry *Entry
	Error error

	// TODO: Refactor
	Int int
}

InputDefault represents "default" field in an element of "inputs".

func (*InputDefault) EntryFromDictionary

func (d *InputDefault) EntryFromDictionary(dict map[string]interface{}) (*Entry, error)

EntryFromDictionary ...

func (*InputDefault) Flatten

func (d *InputDefault) Flatten(binding *Binding) []string

Flatten ...

func (InputDefault) New

func (d InputDefault) New(i interface{}) *InputDefault

New constructs new "InputDefault".

type Inputs

type Inputs []*Input

Inputs represents "inputs" field in CWL.

func (Inputs) Len

func (ins Inputs) Len() int

Len for sorting.

func (Inputs) Less

func (ins Inputs) Less(i, j int) bool

Less for sorting.

func (Inputs) New

func (ins Inputs) New(i interface{}) Inputs

New constructs new "Inputs" struct.

func (Inputs) Swap

func (ins Inputs) Swap(i, j int)

Swap for sorting.

func (Inputs) ToJavaScriptVM

func (ins Inputs) ToJavaScriptVM() (*otto.Otto, error)

ToJavaScriptVM ...

type JavascriptExpression

type JavascriptExpression struct {
	Kind  string // could be "" or "$include"
	Value string
}

JavascriptExpression represents an element of "expressionLib" of InlineJavascriptRequirement.

func (JavascriptExpression) New

func (_ JavascriptExpression) New(i interface{}) JavascriptExpression

func (JavascriptExpression) NewList

func (_ JavascriptExpression) NewList(i interface{}) []JavascriptExpression

type Namespace

type Namespace map[string]interface{}

Namespace ...

func (Namespace) New

func (_ Namespace) New(i interface{}) Namespace

New constructs a Namespace from any interface.

type Namespaces

type Namespaces []Namespace

Namespaces ...

func (Namespaces) New

func (_ Namespaces) New(i interface{}) Namespaces

New constructs "Namespaces" struct.

type Output

type Output struct {
	ID             string   `json:"id"`
	Label          string   `json:"label"`
	Doc            []string `json:"doc"`
	Format         string   `json:"format"`
	Binding        *Binding `json:"outputBinding"`
	Source         []string `json:"outputSource"`
	Types          []Type   `json:"type"`
	SecondaryFiles []SecondaryFile

	// Loaded Contents if Binding.LoadContents == true
	Contents interface{} `json:"contents"`
}

Output represents and conbines "CommandOutputParameter" and "WorkflowOutputParameter" @see - http://www.commonwl.org/v1.0/CommandLineTool.html#CommandOutputParameter - http://www.commonwl.org/v1.0/Workflow.html#WorkflowOutputParameter

func (Output) DumpFileMeta

func (o Output) DumpFileMeta(dest map[string]interface{}, dir string, stdout, stderr string, w io.Writer) error

DumpFileMeta ...

func (Output) New

func (o Output) New(i interface{}) Output

New constructs "Output" struct from interface.

type Outputs

type Outputs []Output

Outputs represents "outputs" field in "CWL".

func (Outputs) Dump

func (outs Outputs) Dump(vm *otto.Otto, dir string, stdout, stderr string, w io.Writer) error

Dump ...

func (Outputs) Len

func (outs Outputs) Len() int

Len for sorting

func (Outputs) Less

func (outs Outputs) Less(i, j int) bool

Less for sorting

func (Outputs) LoadContents

func (outs Outputs) LoadContents(srcdir string) (*otto.Otto, error)

LoadContents ...

func (Outputs) New

func (outs Outputs) New(i interface{}) Outputs

New constructs "Outputs" struct.

func (Outputs) Swap

func (outs Outputs) Swap(i, j int)

Swap for sorting

type Parameter

type Parameter interface{}

Parameter ...

type Parameters

type Parameters map[string]Parameter

Parameters represents specific parameters to run workflow which is described by CWL.

func NewParameters

func NewParameters() *Parameters

NewParameters ...

func (*Parameters) Decode

func (p *Parameters) Decode(f *os.File) error

Decode ...

type Provided

type Provided struct {
	ID    string
	Raw   interface{}
	Entry *Entry // In most cases, it's "File" if "Entry" exists
	Error error

	// TODO: Refactor
	Int int
}

Provided represents the provided input value by parameter files.

func (Provided) EntryFromDictionary

func (provided Provided) EntryFromDictionary(dict map[interface{}]interface{}) (*Entry, error)

EntryFromDictionary ...

func (Provided) New

func (provided Provided) New(id string, i interface{}) *Provided

New constructs new "Provided" struct.

type Requirement

Requirement represent an element of "requirements".

func (Requirement) New

func (_ Requirement) New(i interface{}) Requirement

New constructs "Requirement" struct from interface.

type Requirements

type Requirements []Requirement

Requirements represents "requirements" field in CWL.

func (Requirements) New

func (_ Requirements) New(i interface{}) Requirements

New constructs "Requirements" struct from interface.

type ResourceRequirement

type ResourceRequirement struct {
	CoresMin int
	CoresMax int
}

ResourceRequirement is supposed to be embeded to Requirement. @see http://www.commonwl.org/v1.0/CommandLineTool.html#ResourceRequirement

type Root

type Root struct {
	Version      string
	Class        string
	Hints        Hints
	Doc          string
	Graphs       Graphs
	BaseCommands BaseCommands
	Arguments    Arguments
	Namespaces   Namespaces
	Schemas      Schemas
	Stdin        string
	Stdout       string
	Stderr       string
	Inputs       Inputs `json:"inputs"`
	// ProvidedInputs ProvidedInputs `json:"-"`
	Outputs      Outputs
	Requirements Requirements
	Steps        Steps
	ID           string // ID only appears if this Root is a step in "steps"
	Expression   string // appears only if Class is "ExpressionTool"

	// Path
	Path string `json:"-"`
	// InputsVM
	InputsVM *otto.Otto
}

Root ...

func NewCWL

func NewCWL() *Root

NewCWL ...

func (*Root) AsStep

func (root *Root) AsStep(i interface{}) *Root

AsStep constructs Root as a step of "steps" from interface.

func (*Root) Decode

func (root *Root) Decode(r io.Reader) (err error)

Decode decodes specified file to this root

func (*Root) UnmarshalJSON

func (root *Root) UnmarshalJSON(b []byte) error

UnmarshalJSON ...

func (*Root) UnmarshalMap

func (root *Root) UnmarshalMap(docs map[string]interface{}) error

UnmarshalMap decode map[string]interface{} to *Root.

type Run

type Run struct {
	Value    string
	Workflow *Root
}

Run `run` accept string | CommandLineTool | ExpressionTool | Workflow

type SchemaDefRequirement

type SchemaDefRequirement struct {
	Types []Type
}

SchemaDefRequirement is supposed to be embeded to Requirement. @see http://www.commonwl.org/v1.0/CommandLineTool.html#SchemaDefRequirement

type Schemas

type Schemas []string

Schemas ...

func (Schemas) New

func (_ Schemas) New(i interface{}) Schemas

New constructs "Schemas" struct.

type SecondaryFile

type SecondaryFile struct {
	Entry string
}

SecondaryFile represents an element of "secondaryFiles".

func (SecondaryFile) NewList

func (_ SecondaryFile) NewList(i interface{}) []SecondaryFile

NewList constructs list of "SecondaryFile".

type ShellCommandRequirement

type ShellCommandRequirement struct {
}

ShellCommandRequirement is supposed to be embeded to Requirement. @see http://www.commonwl.org/v1.0/CommandLineTool.html#ShellCommandRequirement

type SoftwarePackage

type SoftwarePackage struct {
	Package  string
	Versions []string
	Specs    []string
}

SoftwarePackage represents an element of SoftwarePackage.Packages

type SoftwareRequirement

type SoftwareRequirement struct {
	Packages []SoftwarePackage
}

SoftwareRequirement is supposed to be embeded to Requirement. @see http://www.commonwl.org/v1.0/CommandLineTool.html#SoftwareRequirement

type Step

type Step struct {
	ID            string
	In            StepInputs
	Out           []StepOutput
	Run           Run
	Requirements  []Requirement
	Scatter       []string
	ScatterMethod string
}

Step represents WorkflowStep. @see http://www.commonwl.org/v1.0/Workflow.html#WorkflowStep

func (Step) New

func (_ Step) New(i interface{}) Step

New constructs "Step" from interface.

type StepInput

type StepInput struct {
	ID        string
	Source    []string
	LinkMerge string
	Default   *InputDefault
	ValueFrom string
}

StepInput represents WorkflowStepInput. @see http://www.commonwl.org/v1.0/Workflow.html#WorkflowStepInput

func (StepInput) New

func (_ StepInput) New(i interface{}) StepInput

New constructs a StepInput struct from any interface.

func (StepInput) NewList

func (_ StepInput) NewList(i interface{}) StepInputs

NewList constructs a list of StepInput from interface.

type StepInputs

type StepInputs []StepInput

StepInputs represents []StepInput

func (StepInputs) Len

func (s StepInputs) Len() int

Len for sorting

func (StepInputs) Less

func (s StepInputs) Less(i, j int) bool

Less for sorting

func (StepInputs) Swap

func (s StepInputs) Swap(i, j int)

Swap for sorting

type StepOutput

type StepOutput struct {
	ID string
}

StepOutput represents StepWorkflowOutput. @see http://www.commonwl.org/v1.0/Workflow.html#WorkflowStepOutput

func (StepOutput) New

func (_ StepOutput) New(i interface{}) StepOutput

New constructs a StepOutput from interface.

func (StepOutput) NewList

func (_ StepOutput) NewList(i interface{}) []StepOutput

NewList constructs a list of StepOutput from interface.

type Steps

type Steps []Step

Steps represents "steps" field in CWL.

func (Steps) Len

func (steps Steps) Len() int

Len for sorting

func (Steps) Less

func (steps Steps) Less(i, j int) bool

Less for sorting

func (Steps) New

func (_ Steps) New(i interface{}) Steps

New constructs "Steps" from interface.

func (Steps) Swap

func (steps Steps) Swap(i, j int)

Swap for sorting

type Type

type Type struct {
	Type    string
	Label   string
	Binding *Binding
	Fields  Fields   // from CommandInputRecordSchema
	Symbols []string // from CommandInputEnumSchema
	Items   []Type   // from CommandInputArraySchema
	Name    string
}

Type represents CWL Typeable objects. - http://www.commonwl.org/v1.0/CommandLineTool.html#CWLType - http://www.commonwl.org/v1.0/CommandLineTool.html#CommandInputRecordSchema - http://www.commonwl.org/v1.0/CommandLineTool.html#CommandInputEnumSchema - http://www.commonwl.org/v1.0/CommandLineTool.html#CommandInputArraySchema

func (Type) NeedRequirement

func (t Type) NeedRequirement() (string, bool)

NeedRequirement ...

func (Type) New

func (_ Type) New(i interface{}) Type

New constructs single Type struct from any interface.

func (Type) NewList

func (_ Type) NewList(i interface{}) []Type

NewList constructs a list of Type from any interface. It only handles []interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL