Skip to content

Commit

Permalink
EnaReceiptToMarsTest, validInput & invalidInput
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedram-A-Keyvani committed Nov 19, 2024
1 parent d9aa6ab commit 225f4dc
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** Elixir BioHackathon 2022 */
package com.elixir.biohackaton.ISAToSRA;

import com.elixir.biohackaton.ISAToSRA.receipt.MarsReceiptException;
import com.elixir.biohackaton.ISAToSRA.receipt.isamodel.*;
import com.elixir.biohackaton.ISAToSRA.receipt.marsmodel.*;
import com.elixir.biohackaton.ISAToSRA.sra.model.Receipt;
import com.elixir.biohackaton.ISAToSRA.sra.service.MarsReceiptService;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -15,29 +15,47 @@
class EnaReceiptToMarsTest {

@Test
void convertToMars() {
try {
void convertToMars_validInput() {
String enaReceiptFilePath = "../../test-data/ena-receipt.json";
String marsReceiptPath = "../../test-data/mars-ena-receipt.json";
convertToMars(enaReceiptFilePath, marsReceiptPath);
}

@Test
void convertToMars_invalidInput() {
String enaReceiptFilePath = "../../test-data/ena-receipt-invalid.json";
String marsReceiptPath = "../../test-data/mars-ena-receipt-invalid.json";
convertToMars(enaReceiptFilePath, marsReceiptPath);
}

// Reading Inputs
String enaReceiptFilePath = "../../test-data/ena-receipt.json";
String isaJsonFilePath = "../../test-data/biosamples-input-isa.json";
String receiptFile = Files.readString(new File(enaReceiptFilePath).toPath());
String isaJsonFile = Files.readString(new File(isaJsonFilePath).toPath());
void convertToMars(final String enaReceiptFilePath, final String marsReceiptPath) {
ObjectMapper jsonMapper = new ObjectMapper();
MarsReceiptService marsReceiptService = new MarsReceiptService();
try {
try {
// Reading Inputs
String receiptFile = Files.readString(new File(enaReceiptFilePath).toPath());
String isaJsonFilePath = "../../test-data/biosamples-modified-isa.json";
String isaJsonFile = Files.readString(new File(isaJsonFilePath).toPath());

// Mapping inputs to the proper objects
ObjectMapper jsonMapper = new ObjectMapper();
Receipt receipt = jsonMapper.readValue(receiptFile, Receipt.class);
IsaJson isaJson = jsonMapper.readValue(isaJsonFile, IsaJson.class);
// Mapping inputs to the proper objects
Receipt receipt = jsonMapper.readValue(receiptFile, Receipt.class);
IsaJson isaJson = jsonMapper.readValue(isaJsonFile, IsaJson.class);

// Converting ENA receipt to MARS receipt
MarsReceiptService marsReceiptService = new MarsReceiptService();
MarsReceipt marsReceipt = marsReceiptService.convertReceiptToMars(receipt, isaJson);
// Converting ENA receipt to MARS receipt
marsReceiptService.convertReceiptToMars(receipt, isaJson);
} catch (MarsReceiptException e) {
marsReceiptService.setMarsReceiptErrors(e.getError());
} catch (Exception e) {
marsReceiptService.setMarsReceiptErrors(e.getMessage());
}

// Saving the result as a Json file
String marsReceiptPath = "../../test-data/mars-ena-receipt.json";
Files.write(new File(marsReceiptPath).toPath(), jsonMapper.writeValueAsBytes(marsReceipt));
} catch (Exception ex) {
System.console().printf("%s", ex);
Files.write(
new File(marsReceiptPath).toPath(),
jsonMapper.writeValueAsBytes(marsReceiptService.getMarsReceipt()));
} catch (Exception e) {
e.printStackTrace();
}
}
}
58 changes: 58 additions & 0 deletions test-data/ena-receipt-invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"success": true,
"receiptDate": "2023-11-16T10:44:41.618Z",
"experiments": [
{
"alias": "#other_material/332-0.5578006304577448",
"accession": "ERX13332762",
"status": "PRIVATE"
},
{
"alias": "#other_material/333-0.5578006304577448",
"accession": "ERX13332763",
"status": "PRIVATE"
}
],
"runs": [
{
"alias": "#assay/18_20_21-0.5578006304577448",
"accession": "ERR13930853",
"status": "PRIVATE"
}
],
"studies":[
{
"alias":"Arabidopsis thaliana-0.5578006304577448",
"status":"PRIVATE",
"holdUntilDate": "2023-01-01Z",
"externalAccession": {
"id": "PRJEB82366",
"db": "Project"
}
}
],
"projects": [
{
"alias": "Bob's investigation-0.5578006304577448",
"accession": "PRJEB82365",
"status": "PRIVATE",
"holdUntilDate": "2023-01-01Z",
"externalAccession": {
"id": "ERP166076",
"db": "study"
}
}
],
"submission": {
"alias": "SUBMISSION-07-11-2024-17:00:52:797",
"accession": "ERA30928821"
},
"messages": {
"info": [
"All objects in this submission are set to private status (HOLD)."
]
},
"actions": [
"ADD"
]
}
80 changes: 80 additions & 0 deletions test-data/mars-ena-receipt-invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"targetRepository": "ena",
"errors": [
{
"type": "INVALID_METADATA",
"message": "ENA receipt: Accession number of Arabidopsis thaliana-0.5578006304577448 is NULL"
}
],
"info": [
{
"message": "All objects in this submission are set to private status (HOLD)."
}
],
"accessions": [
{
"value": "ERX13332762",
"path": [
{
"key": "investigation"
},
{
"key": "studies",
"where": {
"key": "title",
"value": "Arabidopsis thaliana"
}
},
{
"key": "assays",
"where": {
"key": "@id",
"value": "#assay/18_20_21"
}
},
{
"key": "materials"
},
{
"key": "otherMaterials",
"where": {
"key": "@id",
"value": "#other_material/332"
}
}
]
},
{
"value": "ERX13332763",
"path": [
{
"key": "investigation"
},
{
"key": "studies",
"where": {
"key": "title",
"value": "Arabidopsis thaliana"
}
},
{
"key": "assays",
"where": {
"key": "@id",
"value": "#assay/18_20_21"
}
},
{
"key": "materials"
},
{
"key": "otherMaterials",
"where": {
"key": "@id",
"value": "#other_material/333"
}
}
]
}
]
}
27 changes: 1 addition & 26 deletions test-data/mars-ena-receipt.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"targetRepository": "ena.embl",
"targetRepository": "ena",
"errors": [],
"info": [
{
Expand All @@ -22,31 +22,6 @@
}
]
},
{
"value": "ERS27605861",
"path": [
{
"key": "investigation"
},
{
"key": "studies",
"where": {
"key": "title",
"value": "Arabidopsis thaliana"
}
},
{
"key": "materials"
},
{
"key": "samples",
"where": {
"key": "@id",
"value": "#sample/331"
}
}
]
},
{
"value": "ERX9223136",
"path": [
Expand Down

0 comments on commit 225f4dc

Please sign in to comment.