Skip to content

Commit ae68a46

Browse files
author
Mark Robinson
committed
Mock githubService to allow testing without network
1 parent a9ab2f0 commit ae68a46

29 files changed

+161510
-12
lines changed

src/test/java/org/commonwl/view/cwl/CWLServiceTest.java

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,48 @@
11
package org.commonwl.view.cwl;
22

3+
import org.apache.commons.io.FileUtils;
4+
import org.commonwl.view.github.GitHubService;
35
import org.commonwl.view.github.GithubDetails;
46
import org.commonwl.view.workflow.Workflow;
57
import org.commonwl.view.workflow.WorkflowOverview;
68
import org.junit.Test;
7-
import org.junit.runner.RunWith;
8-
import org.springframework.beans.factory.annotation.Autowired;
9-
import org.springframework.boot.test.context.SpringBootTest;
10-
import org.springframework.test.context.junit4.SpringRunner;
9+
import org.mockito.Mockito;
10+
import org.mockito.invocation.InvocationOnMock;
11+
import org.mockito.stubbing.Answer;
1112

13+
import java.io.File;
1214
import java.util.Map;
1315

1416
import static org.junit.Assert.*;
17+
import static org.mockito.Matchers.anyObject;
18+
import static org.mockito.Mockito.when;
1519

16-
@RunWith(SpringRunner.class)
17-
@SpringBootTest
1820
public class CWLServiceTest {
1921

20-
/**
21-
* Create a service to test
22-
*/
23-
@Autowired
24-
private CWLService cwlService;
25-
2622
/**
2723
* Test main parsing of a the LobSTR workflow CWL version draft-3
2824
*/
2925
@Test
3026
public void parseLobSTRDraft3Workflow() throws Exception {
3127

28+
// Mock githubService class
29+
GitHubService githubService = Mockito.mock(GitHubService.class);
30+
Answer fileAnswer = new Answer<String>() {
31+
@Override
32+
public String answer(InvocationOnMock invocation) throws Throwable {
33+
Object[] args = invocation.getArguments();
34+
GithubDetails details = (GithubDetails) args[0];
35+
File workflowFile = new File("src/test/resources/cwl/lobstr-draft3/"
36+
+ details.getPath().replace("workflows/lobSTR/", ""));
37+
return FileUtils.readFileToString(workflowFile);
38+
}
39+
};
40+
when(githubService.downloadFile(anyObject())).thenAnswer(fileAnswer);
41+
when(githubService.downloadFile(anyObject(), anyObject())).thenAnswer(fileAnswer);
42+
43+
// Test cwl service
44+
CWLService cwlService = new CWLService(githubService, 5242880);
45+
3246
// Get workflow from community repo by commit ID so it will not change
3347
GithubDetails lobSTRDraft3Details = new GithubDetails("common-workflow-language",
3448
"workflows", null, "workflows/lobSTR/lobSTR-workflow.cwl");
@@ -46,6 +60,24 @@ public void parseLobSTRDraft3Workflow() throws Exception {
4660
@Test
4761
public void parseLobSTRv1Workflow() throws Exception {
4862

63+
// Mock githubService class
64+
GitHubService githubService = Mockito.mock(GitHubService.class);
65+
Answer fileAnswer = new Answer<String>() {
66+
@Override
67+
public String answer(InvocationOnMock invocation) throws Throwable {
68+
Object[] args = invocation.getArguments();
69+
GithubDetails details = (GithubDetails) args[0];
70+
File workflowFile = new File("src/test/resources/cwl/lobstr-v1/"
71+
+ details.getPath().replace("workflows/lobSTR/", ""));
72+
return FileUtils.readFileToString(workflowFile);
73+
}
74+
};
75+
when(githubService.downloadFile(anyObject())).thenAnswer(fileAnswer);
76+
when(githubService.downloadFile(anyObject(), anyObject())).thenAnswer(fileAnswer);
77+
78+
// Test cwl service
79+
CWLService cwlService = new CWLService(githubService, 5242880);
80+
4981
// Get workflow from community repo by commit ID so it will not change
5082
GithubDetails lobSTRv1Details = new GithubDetails("common-workflow-language",
5183
"workflows", null, "workflows/lobSTR/lobSTR-workflow.cwl");
@@ -104,6 +136,15 @@ private void testLobSTRWorkflow(Workflow lobSTR) throws Exception {
104136
@Test
105137
public void getHelloWorkflowOverview() throws Exception {
106138

139+
// Mock githubService class
140+
GitHubService githubService = Mockito.mock(GitHubService.class);
141+
File workflowFile = new File("src/test/resources/cwl/hello/hello.cwl");
142+
when(githubService.downloadFile(anyObject()))
143+
.thenReturn(FileUtils.readFileToString(workflowFile));
144+
145+
// Test cwl service
146+
CWLService cwlService = new CWLService(githubService, 5242880);
147+
107148
// Get workflow from community repo by commit ID so it will not change
108149
GithubDetails helloDetails = new GithubDetails("common-workflow-language",
109150
"workflows", "8296e92d358bb5da4dc3c6e7aabefa89726e3409", "workflows/hello/hello.cwl");
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
A simple CWL workflow printing "Hello World" into a File.
2+
3+
See : https://github.com/common-workflow-language/workflows/pull/2
4+
5+
## echo 'Hello'
6+
7+
Execute:
8+
9+
```bash
10+
$ cwl-runner hello.cwl
11+
cwl-runner 1.0.20150728161219
12+
Must provide input in the form of a json file or command line parameters.
13+
[job 177019500] exec echo 'Hello World' > /tmp/tmpz9BXNP/messageout.txt
14+
[workflow 177019180] outdir is /path/to/workflows/workflows/hello
15+
Final process status is success
16+
{
17+
"output": {
18+
"path": "//path/to/workflows/workflows/hello/messageout.txt",
19+
"checksum": "sha1$648a6a6ffffdaa0badb23b8baf90b6168dd16b3a",
20+
"class": "File",
21+
"size": 12
22+
}
23+
}
24+
25+
26+
$ cat /path/to/workflows/workflows/hello/messageout.txt
27+
Hello World
28+
```
29+
30+
## echo 'Hello' with parameters
31+
32+
```bash
33+
$ cwl-runner hello-param.cwl params.json
34+
cwl-runner 1.0.20150728161219
35+
[job 153175084] exec echo -n -e 'Hello, CWL !
36+
Hello World !' > /tmp/tmp1er8QF/useroutput.txt
37+
[workflow 153177196] outdir is workflows/hello
38+
Final process status is success
39+
{
40+
"output": {
41+
"path": "workflows/hello/useroutput.txt",
42+
"checksum": "sha1$e8bb28df025c10299db8e73281fbf96d402a1bc0",
43+
"class": "File",
44+
"size": 26
45+
}
46+
}
47+
48+
$ cat useroutput.txt
49+
Hello, CWL !
50+
Hello World !
51+
```
52+
53+
with parameters specified on the command line:
54+
55+
```bash
56+
$ cwl-runner hello-param.cwl --usermessage "Yellow submarine" --useroutput song.txt
57+
cwl-runner 1.0.20150728161219
58+
[job 154935692] exec echo -n -e 'Yellow submarine' > /tmp/tmpljSIiy/song.txt
59+
[workflow 154938540] outdir is workflows/hello
60+
Final process status is success
61+
{
62+
"output": {
63+
"path": "workflows/hello/song.txt",
64+
"checksum": "sha1$72fd47e534c95ce205f8fa1d2f78ab144e6a04ff",
65+
"class": "File",
66+
"size": 16
67+
}
68+
}lindenb@hardyweinberg:~/src/cwl-workflows/workflows/hello$ cat song.txt
69+
Yellow submarine
70+
```
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env cwl-runner
2+
3+
cwlVersion: v1.0
4+
$graph:
5+
- id: echocmd
6+
class: CommandLineTool
7+
inputs:
8+
echo-in-message:
9+
type: string
10+
label: "Message"
11+
doc: "The message to print"
12+
default: "Hello World"
13+
inputBinding: {}
14+
echo-in-outputfile:
15+
type: string
16+
label: "Output file"
17+
doc: "The file containing the message"
18+
outputs:
19+
echo-out-filename:
20+
type: stdout
21+
label: "Printed Message"
22+
doc: "The file containing the message"
23+
baseCommand: echo
24+
arguments:
25+
- "-n"
26+
- "-e"
27+
stdout: $(inputs['echo-in-outputfile'])
28+
29+
- id: main
30+
class: Workflow
31+
label: "Hello World"
32+
doc: "Puts a message into a file using echo"
33+
inputs:
34+
usermessage: string
35+
useroutput: string
36+
outputs:
37+
output:
38+
type: File
39+
outputSource: step0/echo-out-filename
40+
steps :
41+
- id: step0
42+
run: "#echocmd"
43+
in:
44+
echo-in-message: usermessage
45+
echo-in-outputfile: useroutput
46+
out: [echo-out-filename]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env cwl-runner
2+
3+
cwlVersion: v1.0
4+
$graph:
5+
- id: echocmd
6+
class: CommandLineTool
7+
inputs:
8+
echo-in:
9+
type: string
10+
label: "Message"
11+
doc: "The message to print"
12+
default: "Hello World"
13+
inputBinding: {}
14+
outputs:
15+
echo-out:
16+
type: stdout
17+
label: "Printed Message"
18+
doc: "The file containing the message"
19+
baseCommand: echo
20+
stdout: messageout.txt
21+
22+
- id: main
23+
class: Workflow
24+
label: "Hello World"
25+
doc: "Puts a message into a file using echo"
26+
inputs: []
27+
outputs:
28+
output:
29+
type: File
30+
outputSource: step0/echo-out
31+
steps:
32+
step0:
33+
run: "#echocmd"
34+
in: []
35+
out: [echo-out]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env cwl-runner
2+
{
3+
"cwl:tool" : "hello-param.cwl#main",
4+
"usermessage" : "Hello, CWL !\nHello World !",
5+
"useroutput" : "useroutput.txt"
6+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
lobSTR is a tool for profiling Short Tandem Repeats (STRs) from high throughput sequencing data.
2+
3+
This lobSTR workflow is based on http://melissagymrek.com/lobstr-code/usage.html
4+
5+
To run locally, you may install the reference implementation of CWL:
6+
7+
1) Install the reference implementation of cwl-runner with "pip install cwl-runner".
8+
9+
2) Download reference data:
10+
11+
$ wget http://files.teamerlich.org/lobstr/v3/ref/lobSTR_v3.0.2_hg19_resource_bundle.tar.gz
12+
$ tar xvzf lobSTR_v3.0.2_hg19_resource_bundle.tar.gz
13+
14+
3) Ensure your docker version is compatible with the Arvados image ( < 1.10 ):
15+
16+
$ docker --version
17+
18+
4) Run the demo:
19+
20+
$ ./lobSTR-workflow.cwl lobSTR-demo.json
21+
22+
23+
Alternately, you may run lobSTR on Curoverse cloud. This does not require
24+
downloading the reference data.
25+
26+
1) Install Arvados cwl-runner using "pip install arvados-cwl-runner".
27+
28+
2) Sign up for a Curoverse Cloud account at https://cloud.curoverse.com
29+
30+
3) Navigate to https://cloud.curoverse.com/current_token and follow the
31+
instructions to set ARVADOS_API_TOKEN and ARVADOS_API_HOST into your shell
32+
session (these are your Curoverse cloud credentials).
33+
34+
4) You can now run the lobSTR workflow and submit jobs to run on Curoverse
35+
cloud:
36+
37+
$ ./lobSTR-workflow.cwl lobSTR-arvados-demo.json
38+
39+
Note that the output data will also be stored on Curoverse cloud, and may be
40+
downloaded through the Workbench web interface or using "arv-get".
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env cwl-runner
2+
cwlVersion: "cwl:draft-3"
3+
4+
class: CommandLineTool
5+
6+
description: Run lobSTR allelotype classifier.
7+
8+
requirements:
9+
- class: InlineJavascriptRequirement
10+
11+
inputs:
12+
- id: bam
13+
type: File
14+
description: |
15+
BAM file to analyze. Should have a unique read group and be sorted and indexed.
16+
inputBinding:
17+
prefix: "--bam"
18+
secondaryFiles:
19+
- ".bai"
20+
21+
- id: output_prefix
22+
type: string
23+
description: "Prefix for output files. will output prefix.vcf and prefix.genotypes.tab"
24+
inputBinding:
25+
prefix: "--out"
26+
27+
- id: noise_model
28+
type: File
29+
description: |
30+
File to read noise model parameters from (.stepmodel)
31+
inputBinding:
32+
prefix: "--noise_model"
33+
valueFrom: |
34+
${ return {"path": self.path.match(/(.*)\.stepmodel/)[1], "class": "File"}; }
35+
secondaryFiles:
36+
- "^.stuttermodel"
37+
38+
- id: strinfo
39+
type: File
40+
description: |
41+
File containing statistics for each STR.
42+
inputBinding:
43+
prefix: "--strinfo"
44+
45+
- id: reference
46+
type: File
47+
description: "lobSTR's bwa reference files"
48+
inputBinding:
49+
prefix: "--index-prefix"
50+
valueFrom: |
51+
${ return {"path": self.path.match(/(.*)ref\.fasta/)[1], "class": "File"}; }
52+
53+
secondaryFiles:
54+
- ".amb"
55+
- ".ann"
56+
- ".bwt"
57+
- ".pac"
58+
- ".rbwt"
59+
- ".rpac"
60+
- ".rsa"
61+
- ${return self.path.replace(/(.*)ref\.fasta/, "$1chromsizes.tab")}
62+
- ${return self.path.replace(/(.*)ref\.fasta/, "$1mergedref.bed")}
63+
- ${return self.path.replace(/(.*)ref\.fasta/, "$1ref_map.tab")}
64+
65+
outputs:
66+
- id: vcf
67+
type: File
68+
outputBinding:
69+
glob: $(inputs['output_prefix'] + '.vcf')
70+
- id: "#vcf_stats"
71+
type: File
72+
outputBinding:
73+
glob: $(inputs['output_prefix'] + '.allelotype.stats')
74+
75+
baseCommand: ["allelotype", "--command", "classify"]
76+
77+
arguments:
78+
- "--noweb"

0 commit comments

Comments
 (0)