Skip to content

Commit 225f4dc

Browse files
EnaReceiptToMarsTest, validInput & invalidInput
1 parent d9aa6ab commit 225f4dc

File tree

4 files changed

+176
-45
lines changed

4 files changed

+176
-45
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/** Elixir BioHackathon 2022 */
22
package com.elixir.biohackaton.ISAToSRA;
33

4+
import com.elixir.biohackaton.ISAToSRA.receipt.MarsReceiptException;
45
import com.elixir.biohackaton.ISAToSRA.receipt.isamodel.*;
5-
import com.elixir.biohackaton.ISAToSRA.receipt.marsmodel.*;
66
import com.elixir.biohackaton.ISAToSRA.sra.model.Receipt;
77
import com.elixir.biohackaton.ISAToSRA.sra.service.MarsReceiptService;
88
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -15,29 +15,47 @@
1515
class EnaReceiptToMarsTest {
1616

1717
@Test
18-
void convertToMars() {
19-
try {
18+
void convertToMars_validInput() {
19+
String enaReceiptFilePath = "../../test-data/ena-receipt.json";
20+
String marsReceiptPath = "../../test-data/mars-ena-receipt.json";
21+
convertToMars(enaReceiptFilePath, marsReceiptPath);
22+
}
23+
24+
@Test
25+
void convertToMars_invalidInput() {
26+
String enaReceiptFilePath = "../../test-data/ena-receipt-invalid.json";
27+
String marsReceiptPath = "../../test-data/mars-ena-receipt-invalid.json";
28+
convertToMars(enaReceiptFilePath, marsReceiptPath);
29+
}
2030

21-
// Reading Inputs
22-
String enaReceiptFilePath = "../../test-data/ena-receipt.json";
23-
String isaJsonFilePath = "../../test-data/biosamples-input-isa.json";
24-
String receiptFile = Files.readString(new File(enaReceiptFilePath).toPath());
25-
String isaJsonFile = Files.readString(new File(isaJsonFilePath).toPath());
31+
void convertToMars(final String enaReceiptFilePath, final String marsReceiptPath) {
32+
ObjectMapper jsonMapper = new ObjectMapper();
33+
MarsReceiptService marsReceiptService = new MarsReceiptService();
34+
try {
35+
try {
36+
// Reading Inputs
37+
String receiptFile = Files.readString(new File(enaReceiptFilePath).toPath());
38+
String isaJsonFilePath = "../../test-data/biosamples-modified-isa.json";
39+
String isaJsonFile = Files.readString(new File(isaJsonFilePath).toPath());
2640

27-
// Mapping inputs to the proper objects
28-
ObjectMapper jsonMapper = new ObjectMapper();
29-
Receipt receipt = jsonMapper.readValue(receiptFile, Receipt.class);
30-
IsaJson isaJson = jsonMapper.readValue(isaJsonFile, IsaJson.class);
41+
// Mapping inputs to the proper objects
42+
Receipt receipt = jsonMapper.readValue(receiptFile, Receipt.class);
43+
IsaJson isaJson = jsonMapper.readValue(isaJsonFile, IsaJson.class);
3144

32-
// Converting ENA receipt to MARS receipt
33-
MarsReceiptService marsReceiptService = new MarsReceiptService();
34-
MarsReceipt marsReceipt = marsReceiptService.convertReceiptToMars(receipt, isaJson);
45+
// Converting ENA receipt to MARS receipt
46+
marsReceiptService.convertReceiptToMars(receipt, isaJson);
47+
} catch (MarsReceiptException e) {
48+
marsReceiptService.setMarsReceiptErrors(e.getError());
49+
} catch (Exception e) {
50+
marsReceiptService.setMarsReceiptErrors(e.getMessage());
51+
}
3552

3653
// Saving the result as a Json file
37-
String marsReceiptPath = "../../test-data/mars-ena-receipt.json";
38-
Files.write(new File(marsReceiptPath).toPath(), jsonMapper.writeValueAsBytes(marsReceipt));
39-
} catch (Exception ex) {
40-
System.console().printf("%s", ex);
54+
Files.write(
55+
new File(marsReceiptPath).toPath(),
56+
jsonMapper.writeValueAsBytes(marsReceiptService.getMarsReceipt()));
57+
} catch (Exception e) {
58+
e.printStackTrace();
4159
}
4260
}
4361
}

test-data/ena-receipt-invalid.json

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"success": true,
3+
"receiptDate": "2023-11-16T10:44:41.618Z",
4+
"experiments": [
5+
{
6+
"alias": "#other_material/332-0.5578006304577448",
7+
"accession": "ERX13332762",
8+
"status": "PRIVATE"
9+
},
10+
{
11+
"alias": "#other_material/333-0.5578006304577448",
12+
"accession": "ERX13332763",
13+
"status": "PRIVATE"
14+
}
15+
],
16+
"runs": [
17+
{
18+
"alias": "#assay/18_20_21-0.5578006304577448",
19+
"accession": "ERR13930853",
20+
"status": "PRIVATE"
21+
}
22+
],
23+
"studies":[
24+
{
25+
"alias":"Arabidopsis thaliana-0.5578006304577448",
26+
"status":"PRIVATE",
27+
"holdUntilDate": "2023-01-01Z",
28+
"externalAccession": {
29+
"id": "PRJEB82366",
30+
"db": "Project"
31+
}
32+
}
33+
],
34+
"projects": [
35+
{
36+
"alias": "Bob's investigation-0.5578006304577448",
37+
"accession": "PRJEB82365",
38+
"status": "PRIVATE",
39+
"holdUntilDate": "2023-01-01Z",
40+
"externalAccession": {
41+
"id": "ERP166076",
42+
"db": "study"
43+
}
44+
}
45+
],
46+
"submission": {
47+
"alias": "SUBMISSION-07-11-2024-17:00:52:797",
48+
"accession": "ERA30928821"
49+
},
50+
"messages": {
51+
"info": [
52+
"All objects in this submission are set to private status (HOLD)."
53+
]
54+
},
55+
"actions": [
56+
"ADD"
57+
]
58+
}
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"targetRepository": "ena",
3+
"errors": [
4+
{
5+
"type": "INVALID_METADATA",
6+
"message": "ENA receipt: Accession number of Arabidopsis thaliana-0.5578006304577448 is NULL"
7+
}
8+
],
9+
"info": [
10+
{
11+
"message": "All objects in this submission are set to private status (HOLD)."
12+
}
13+
],
14+
"accessions": [
15+
{
16+
"value": "ERX13332762",
17+
"path": [
18+
{
19+
"key": "investigation"
20+
},
21+
{
22+
"key": "studies",
23+
"where": {
24+
"key": "title",
25+
"value": "Arabidopsis thaliana"
26+
}
27+
},
28+
{
29+
"key": "assays",
30+
"where": {
31+
"key": "@id",
32+
"value": "#assay/18_20_21"
33+
}
34+
},
35+
{
36+
"key": "materials"
37+
},
38+
{
39+
"key": "otherMaterials",
40+
"where": {
41+
"key": "@id",
42+
"value": "#other_material/332"
43+
}
44+
}
45+
]
46+
},
47+
{
48+
"value": "ERX13332763",
49+
"path": [
50+
{
51+
"key": "investigation"
52+
},
53+
{
54+
"key": "studies",
55+
"where": {
56+
"key": "title",
57+
"value": "Arabidopsis thaliana"
58+
}
59+
},
60+
{
61+
"key": "assays",
62+
"where": {
63+
"key": "@id",
64+
"value": "#assay/18_20_21"
65+
}
66+
},
67+
{
68+
"key": "materials"
69+
},
70+
{
71+
"key": "otherMaterials",
72+
"where": {
73+
"key": "@id",
74+
"value": "#other_material/333"
75+
}
76+
}
77+
]
78+
}
79+
]
80+
}

test-data/mars-ena-receipt.json

+1-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"targetRepository": "ena.embl",
2+
"targetRepository": "ena",
33
"errors": [],
44
"info": [
55
{
@@ -22,31 +22,6 @@
2222
}
2323
]
2424
},
25-
{
26-
"value": "ERS27605861",
27-
"path": [
28-
{
29-
"key": "investigation"
30-
},
31-
{
32-
"key": "studies",
33-
"where": {
34-
"key": "title",
35-
"value": "Arabidopsis thaliana"
36-
}
37-
},
38-
{
39-
"key": "materials"
40-
},
41-
{
42-
"key": "samples",
43-
"where": {
44-
"key": "@id",
45-
"value": "#sample/331"
46-
}
47-
}
48-
]
49-
},
5025
{
5126
"value": "ERX9223136",
5227
"path": [

0 commit comments

Comments
 (0)