Skip to content
Snippets Groups Projects
Commit 1331ea0a authored by Piotr Gawron's avatar Piotr Gawron
Browse files

unit tests fixed (model cannot contain reactions with the same id)

parent eb819fd5
No related branches found
No related tags found
1 merge request!190Resolve "uploading zip file from MAC"
Pipeline #
......@@ -616,4 +616,6 @@ public interface Model {
void addFunction(SbmlFunction sbmlFunction);
SbmlArgument getFunctionById(String id);
void removeReactions(Collection<Reaction> reactions);
}
......@@ -734,4 +734,13 @@ public class ModelFullIndexed implements Model {
}
return null;
}
@Override
public void removeReactions(Collection<Reaction> reactions) {
Set<Reaction> reactionsToRemove = new HashSet<>();
reactionsToRemove.addAll(reactions);
for (Reaction reaction : reactionsToRemove) {
removeReaction(reaction);
}
}
}
......@@ -35,495 +35,506 @@ import lcsb.mapviewer.services.utils.data.ExportFileType;
import lcsb.mapviewer.services.view.PubmedAnnotatedElementsView;
public class ExporterServiceTest extends ServiceTestFunctions {
Logger logger = Logger.getLogger(ExporterServiceTest.class);
@Autowired
IExporterService exporter2;
ExporterService exporter;
@Before
public void setUp() throws Exception {
exporter = (ExporterService) exporter2;
}
@After
public void tearDown() throws Exception {
}
@Test
public void testGetExportSpeciesStringForTabSeparatedFile() throws Exception {
try {
Model model = getModelForFile("testFiles/export_with_artifitial_comp.xml", false);
ExportColumn columns[] = { ExportColumn.NAME, ExportColumn.ID, ExportColumn.COMPONENT_NAME, ExportColumn.COMPARTMENT_NAME, ExportColumn.TYPE };
ExporterParameters params = new IExporterService.ExporterParameters().model(model).column(columns).fileType(ExportFileType.TAB_SEPARATED);
// full export (all elements)
String string = exporter.getExportSpeciesString(params);
String lines[] = string.split("\n");
assertTrue("Not enough elements in the result file", lines.length > 1);
String response = lines[0];
String textColumns[] = response.split("\t");
assertEquals(5, textColumns.length);
// only proteins for self-made modules
new CreateHierarchyCommand(model, 8, 80).execute();
string = exporter.getExportSpeciesString(params.type(GenericProtein.class));
lines = string.split("\n");
assertTrue(lines.length > 1);
boolean differenceBetweenComponentCompartmnet = false;
int lineCount = 0;
for (String string2 : lines) {
if (lineCount == 0) {
textColumns = string2.split("\t");
assertEquals(ExportColumn.TYPE.getTitle(), textColumns[4]);
} else {
textColumns = string2.split("\t");
assertEquals(GenericProtein.class.getSimpleName(), textColumns[4]);
if (!textColumns[2].equalsIgnoreCase(textColumns[3])) {
differenceBetweenComponentCompartmnet = true;
}
}
lineCount++;
}
assertTrue(differenceBetweenComponentCompartmnet);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testDuplicatesInGetExportSpeciesString() throws Exception {
try {
Model model = getModelForFile("testFiles/export_duplicate_elements.xml", false);
ExportColumn columns[] = { ExportColumn.NAME, ExportColumn.COMPONENT_NAME, ExportColumn.TYPE };
ExporterParameters params = new IExporterService.ExporterParameters().model(model).column(columns).fileType(ExportFileType.TAB_SEPARATED);
// full export (all elements)
String string = exporter.getExportSpeciesString(params);
String lines[] = string.split("\n");
Set<String> uniqueNames = new HashSet<String>();
for (String string2 : lines) {
uniqueNames.add(string2);
}
assertEquals(uniqueNames.size(), lines.length);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetExportStringForOneSpecies_Complex() {
try {
Model model = getModelForFile("testFiles/export/hsp70.xml", true);
Species alias = (Species) model.getElementByElementId("csa1");
ExportColumn columns[] = { ExportColumn.NAME };
ExporterParameters params = new IExporterService.ExporterParameters().model(model).//
column(columns).//
complexElementsName(false).//
fileType(ExportFileType.TAB_SEPARATED);
List<String> elements = exporter.getExportStringForOneSpecies(alias, params);
assertTrue(elements.contains("HSP70:chaperon"));
// now the results are concatenated children
params.complexElementsName(true);
elements = exporter.getExportStringForOneSpecies(alias, params);
assertTrue(elements.size() > 0);
String string = elements.get(0);
assertFalse(string.equals("HSP70:chaperon"));
assertTrue(string.contains("HSP70"));
assertTrue(string.contains("STUB1"));
assertTrue(string.contains("DNAJB2"));
assertTrue(string.contains("BAG1"));
// and now check complexes with mix of proteins and molecules
alias = (Species) model.getElementByElementId("csa3");
elements = exporter.getExportStringForOneSpecies(alias, params);
assertTrue(elements.size() > 0);
string = elements.get(0);
assertTrue(string.contains("UBA1"));
assertTrue(string.contains("UBA6"));
assertTrue(string.contains("AMP"));
elements = exporter.getExportStringForOneSpecies(alias, params.type(Protein.class));
assertTrue(elements.size() > 0);
string = elements.get(0);
assertTrue(string.contains("UBA1"));
assertTrue(string.contains("UBA6"));
assertFalse(string.contains("AMP"));
} catch (Exception e) {
e.printStackTrace();
fail("Exception occured");
}
}
@Test
public void testGetExportStringForOneReaction() throws Exception {
try {
Model model = getModelForFile("testFiles/export/reaction.xml", false);
Set<Compartment> aliases = new HashSet<>();
for (Compartment alias : model.getCompartments()) {
if (alias.getName().equalsIgnoreCase("Dopamine loaded synaptic vesicle"))
aliases.add(alias);
}
Reaction reaction = model.getReactionByReactionId("re2");
ExporterParameters params = new IExporterService.ExporterParameters().model(model).//
fileType(ExportFileType.SIF).//
type(Protein.class).//
type(Complex.class).//
fileType(ExportFileType.SIF).//
complexElementsName(false).//
excluded(aliases);
String string = exporter.getExportSingleInteractionString(reaction, params).get(0);
assertNotNull(string);
assertTrue(string.contains("Calcium channel:RIMBP:RIM:MUNC13:RAB"));
assertTrue(string.contains("CSP:Hsc70:SGT"));
assertTrue(string.contains("SNCA"));
assertTrue(string.contains("trans-SNARE complex"));
assertFalse(string.contains("VAMP2"));
params = new IExporterService.ExporterParameters().model(model).fileType(ExportFileType.SIF).type(Complex.class).type(Protein.class);
string = exporter.getExportSingleInteractionString(reaction, params).get(0);
assertTrue(string.contains("VAMP2"));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetExportStringForOneReactionInGeneral() {
try {
Model model = getModelForFile("testFiles/export/reaction.xml", true);
Reaction reaction = model.getReactionByReactionId("re2");
ExporterParameters params = new IExporterService.ExporterParameters().model(model).//
fileType(ExportFileType.SIF).//
complexElementsName(false).//
type(Complex.class).type(Protein.class);
String string = exporter.getExportSingleInteractionString(reaction, params).get(0);
assertNotNull(string);
assertTrue(string.contains("Calcium channel:RIMBP:RIM:MUNC13:RAB"));
assertTrue(string.contains("CSP:Hsc70:SGT"));
assertTrue(string.contains("SNCA"));
assertTrue(string.contains("trans-SNARE complex"));
assertTrue(string.contains("SNAP25"));
assertFalse(string.contains("RAB3A"));
params.complexElementsName(true);
string = exporter.getExportSingleInteractionString(reaction, params).get(0);
assertFalse(string.contains("trans-SNARE complex"));
assertTrue(string.contains("RAB3A"));
} catch (Exception e) {
e.printStackTrace();
fail("Exception occured");
}
}
@Test
public void testGetExportStringForOneReactionInGeneralWithOnlyOneElement() throws Exception {
try {
Model model = getModelForFile("testFiles/export/reaction.xml", false);
Reaction reaction = model.getReactionByReactionId("re11");
model.getReactions().clear();
model.addReaction(reaction);
Set<Compartment> aliases = new HashSet<Compartment>();
aliases.add((Compartment) model.getElementByElementId("ca1"));
ExporterParameters params = new IExporterService.ExporterParameters()
.model(model).fileType(ExportFileType.SIF).included("dopamine loaded synaptic vesicle");
assertEquals(0, exporter.getExportSingleInteractionString(reaction, params).size());
params = new IExporterService.ExporterParameters().model(model).fileType(ExportFileType.SIF);
assertEquals(1, exporter.getExportSingleInteractionString(reaction, params).size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetExportSingleInteractionString_text() {
try {
Model model = getModelForFile("testFiles/export_with_artifitial_comp.xml", false);
for (Reaction reaction : model.getReactions()) {
String str = exporter
.getExportSingleInteractionString(
reaction, new IExporterService.ExporterParameters().fileType(ExportFileType.TAB_SEPARATED).type(Species.class))
.get(0);
List<String> strings = new ArrayList<String>();
strings.add(ReactionLineData.getByReactionType(reaction.getClass()).getCellDesignerString());
strings.add(reaction.getIdReaction());
for (ReactionNode node : reaction.getReactionNodes()) {
strings.add(node.getElement().getName());
}
for (String string : strings) {
assertTrue("Description \"" + str + "\" doesn't contain " + string + ". reactionId=" + reaction.getIdReaction(), str.contains(string));
}
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception occured");
}
}
@Test
public void testGetExportComponentAndCompartments() throws Exception {
try {
Model model = getModelForFile("testFiles/export/export_model.xml", false);
new CreateHierarchyCommand(model, 7, 80).execute();
ExporterParameters params = new IExporterService.ExporterParameters()
.model(model).fileType(ExportFileType.TAB_SEPARATED).column(ExportColumn.NAME).column(ExportColumn.COMPONENT_NAME)
.column(ExportColumn.COMPARTMENT_NAME);
List<String> list = exporter.getExportStringForOneSpecies((Species) model.getElementByElementId("sa1"), params);
String desc = list.get(0);
String compartment = desc.split("\t")[2];
assertEquals("c1", compartment);
String component = desc.split("\t")[1];
assertEquals("Test3", component);
list = exporter.getExportStringForOneSpecies((Species) model.getElementByElementId("sa2"), params);
desc = null;
for (String string : list) {
if (string.contains("Test 1")) {
desc = string;
}
}
compartment = desc.split("\t")[2];
assertEquals("c2", compartment);
component = desc.split("\t")[1];
assertEquals("Test 1", component);
for (String string : list) {
if (string.contains("Test2")) {
desc = string;
}
}
compartment = desc.split("\t")[2];
assertEquals("c2", compartment);
component = desc.split("\t")[1];
assertEquals("Test2", component);
for (String string : list) {
if (string.contains("Test3")) {
desc = string;
}
}
compartment = desc.split("\t")[2];
assertEquals("c2", compartment);
component = desc.split("\t")[1];
assertEquals("Test3", component);
list = exporter.getExportStringForOneSpecies((Species) model.getElementByElementId("sa3"), params);
boolean ok = false;
for (String string : list) {
if (string.split("\t")[2].equals("null") && string.split("\t")[1].equals("Test2")) {
ok = true;
}
}
assertTrue(ok);
list = exporter.getExportStringForOneSpecies((Species) model.getElementByElementId("sa4"), params);
desc = list.get(0);
compartment = desc.split("\t")[2];
assertEquals("null", compartment);
component = desc.split("\t")[1];
assertEquals("Test3", component);
list = exporter.getExportStringForOneSpecies((Species) model.getElementByElementId("sa5"), params);
desc = list.get(0);
compartment = desc.split("\t")[2];
assertEquals("c3", compartment);
component = desc.split("\t")[1];
assertEquals("null", component);
list = exporter.getExportStringForOneSpecies((Species) model.getElementByElementId("sa6"), params);
desc = list.get(0);
compartment = desc.split("\t")[2];
assertEquals("null", compartment);
component = desc.split("\t")[1];
assertEquals("null", component);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetExportSpeciesStringForTabSeparatedFile2() throws Exception {
try {
Model model = getModelForFile("testFiles/export_with_artifitial_comp.xml", false);
ExportColumn columns[] = { ExportColumn.NAME, ExportColumn.ID, ExportColumn.COMPONENT_NAME, ExportColumn.COMPARTMENT_NAME, ExportColumn.TYPE };
ExporterParameters params = new IExporterService.ExporterParameters()
.model(model).column(columns).fileType(ExportFileType.TAB_SEPARATED).type(Object.class);
// full export (all elements)
String string = exporter.getExportSpeciesString(params);
String lines[] = string.split("\n");
assertTrue("Not enough elements in the result file", lines.length > 1);
String response = lines[0];
String textColumns[] = response.split("\t");
assertEquals(columns.length, textColumns.length);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetExportCompartmentsString() throws Exception {
try {
Model model = getModelForFile("testFiles/export/export_compartments.xml", false);
ExporterParameters params = new IExporterService.ExporterParameters().model(model).fileType(ExportFileType.TAB_SEPARATED).type(Object.class);
// full export (all compartments)
String string = exporter.getExportCompartmentsString(params);
String lines[] = string.split("\n");
assertTrue("Not enough elements in the result file", lines.length >= 2);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAllExportColumnsSpecies() throws Exception {
try {
Model model = getModelForFile("testFiles/export_with_artifitial_comp.xml", false);
List<ExportColumn> columns = new ArrayList<ExportColumn>();
for (ExportColumn column : ExportColumn.values()) {
if (column.getClazz().isAssignableFrom(Species.class)) {
columns.add(column);
}
}
ExporterParameters params = new IExporterService.ExporterParameters().model(model).column(columns).fileType(ExportFileType.TAB_SEPARATED);
// full export (all elements)
String string = exporter.getExportSpeciesString(params);
assertNotNull(string);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAllExportColumnsReaction() throws Exception {
try {
Model model = getModelForFile("testFiles/export_with_artifitial_comp.xml", false);
List<ExportColumn> columns = new ArrayList<ExportColumn>();
for (ExportColumn column : ExportColumn.values()) {
if (column.getClazz().isAssignableFrom(Reaction.class)) {
columns.add(column);
}
}
ExporterParameters params = new IExporterService.ExporterParameters().model(model).column(columns).fileType(ExportFileType.TAB_SEPARATED);
// full export (all elements)
String string = exporter.getExportInteractionString(params);
assertNotNull(string);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetTabSeparatedReaction() throws Exception {
try {
Model model = getModelForFile("testFiles/export/reaction.xml", false);
Set<Compartment> aliases = new HashSet<>();
for (Compartment alias : model.getCompartments()) {
if (alias.getName().equalsIgnoreCase("Dopamine loaded synaptic vesicle"))
aliases.add(alias);
}
ExporterParameters params = new IExporterService.ExporterParameters().model(model).//
fileType(ExportFileType.TAB_SEPARATED).//
column(ExportColumn.REACTION_ID).//
column(ExportColumn.REACTION_TYPE).//
type(Species.class);
String string = exporter.getExportInteractionString(params);
assertTrue(string.indexOf("STATE_TRANSITION REACTANT") >= 0);
assertTrue(string.indexOf("sa7") >= 0);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void test() throws Exception {
try {
Model model = getModelForFile("testFiles/export/new_line_file.xml", false);
List<ExportColumn> columns = new ArrayList<ExportColumn>();
for (ExportColumn column : ExportColumn.values()) {
if (column.getClazz().isAssignableFrom(Species.class)) {
columns.add(column);
}
}
ExporterParameters params = new IExporterService.ExporterParameters().model(model).column(columns).fileType(ExportFileType.TAB_SEPARATED);
// full export (all elements)
String string = exporter.getExportSpeciesString(params);
String tmp[] = string.split("\n");
for (String string2 : tmp) {
assertTrue(string2, columns.size() <= string2.split("\t", -1).length);
}
assertNotNull(string);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testPubmedSummary() throws Exception {
try {
Model model = getModelForFile("testFiles/export/reaction.xml", false);
List<PubmedAnnotatedElementsView> result = exporter.getPublicationModelSummary(model);
assertNotNull(result);
for (PubmedAnnotatedElementsView pubmedAnnotatedElementsView : result) {
assertNotNull(pubmedAnnotatedElementsView.getArticle());
assertNotNull(pubmedAnnotatedElementsView.getArticle().getTitle());
assertTrue(pubmedAnnotatedElementsView.getElements().size() > 0);
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
Logger logger = Logger.getLogger(ExporterServiceTest.class);
@Autowired
IExporterService exporter2;
ExporterService exporter;
@Before
public void setUp() throws Exception {
exporter = (ExporterService) exporter2;
}
@After
public void tearDown() throws Exception {
}
@Test
public void testGetExportSpeciesStringForTabSeparatedFile() throws Exception {
try {
Model model = getModelForFile("testFiles/export_with_artifitial_comp.xml", false);
ExportColumn columns[] = { ExportColumn.NAME, ExportColumn.ID, ExportColumn.COMPONENT_NAME,
ExportColumn.COMPARTMENT_NAME, ExportColumn.TYPE };
ExporterParameters params = new IExporterService.ExporterParameters().model(model).column(columns)
.fileType(ExportFileType.TAB_SEPARATED);
// full export (all elements)
String string = exporter.getExportSpeciesString(params);
String lines[] = string.split("\n");
assertTrue("Not enough elements in the result file", lines.length > 1);
String response = lines[0];
String textColumns[] = response.split("\t");
assertEquals(5, textColumns.length);
// only proteins for self-made modules
new CreateHierarchyCommand(model, 8, 80).execute();
string = exporter.getExportSpeciesString(params.type(GenericProtein.class));
lines = string.split("\n");
assertTrue(lines.length > 1);
boolean differenceBetweenComponentCompartmnet = false;
int lineCount = 0;
for (String string2 : lines) {
if (lineCount == 0) {
textColumns = string2.split("\t");
assertEquals(ExportColumn.TYPE.getTitle(), textColumns[4]);
} else {
textColumns = string2.split("\t");
assertEquals(GenericProtein.class.getSimpleName(), textColumns[4]);
if (!textColumns[2].equalsIgnoreCase(textColumns[3])) {
differenceBetweenComponentCompartmnet = true;
}
}
lineCount++;
}
assertTrue(differenceBetweenComponentCompartmnet);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testDuplicatesInGetExportSpeciesString() throws Exception {
try {
Model model = getModelForFile("testFiles/export_duplicate_elements.xml", false);
ExportColumn columns[] = { ExportColumn.NAME, ExportColumn.COMPONENT_NAME, ExportColumn.TYPE };
ExporterParameters params = new IExporterService.ExporterParameters().model(model).column(columns)
.fileType(ExportFileType.TAB_SEPARATED);
// full export (all elements)
String string = exporter.getExportSpeciesString(params);
String lines[] = string.split("\n");
Set<String> uniqueNames = new HashSet<String>();
for (String string2 : lines) {
uniqueNames.add(string2);
}
assertEquals(uniqueNames.size(), lines.length);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetExportStringForOneSpecies_Complex() {
try {
Model model = getModelForFile("testFiles/export/hsp70.xml", true);
Species alias = (Species) model.getElementByElementId("csa1");
ExportColumn columns[] = { ExportColumn.NAME };
ExporterParameters params = new IExporterService.ExporterParameters().model(model).//
column(columns).//
complexElementsName(false).//
fileType(ExportFileType.TAB_SEPARATED);
List<String> elements = exporter.getExportStringForOneSpecies(alias, params);
assertTrue(elements.contains("HSP70:chaperon"));
// now the results are concatenated children
params.complexElementsName(true);
elements = exporter.getExportStringForOneSpecies(alias, params);
assertTrue(elements.size() > 0);
String string = elements.get(0);
assertFalse(string.equals("HSP70:chaperon"));
assertTrue(string.contains("HSP70"));
assertTrue(string.contains("STUB1"));
assertTrue(string.contains("DNAJB2"));
assertTrue(string.contains("BAG1"));
// and now check complexes with mix of proteins and molecules
alias = (Species) model.getElementByElementId("csa3");
elements = exporter.getExportStringForOneSpecies(alias, params);
assertTrue(elements.size() > 0);
string = elements.get(0);
assertTrue(string.contains("UBA1"));
assertTrue(string.contains("UBA6"));
assertTrue(string.contains("AMP"));
elements = exporter.getExportStringForOneSpecies(alias, params.type(Protein.class));
assertTrue(elements.size() > 0);
string = elements.get(0);
assertTrue(string.contains("UBA1"));
assertTrue(string.contains("UBA6"));
assertFalse(string.contains("AMP"));
} catch (Exception e) {
e.printStackTrace();
fail("Exception occured");
}
}
@Test
public void testGetExportStringForOneReaction() throws Exception {
try {
Model model = getModelForFile("testFiles/export/reaction.xml", false);
Set<Compartment> aliases = new HashSet<>();
for (Compartment alias : model.getCompartments()) {
if (alias.getName().equalsIgnoreCase("Dopamine loaded synaptic vesicle"))
aliases.add(alias);
}
Reaction reaction = model.getReactionByReactionId("re2");
ExporterParameters params = new IExporterService.ExporterParameters().model(model).//
fileType(ExportFileType.SIF).//
type(Protein.class).//
type(Complex.class).//
fileType(ExportFileType.SIF).//
complexElementsName(false).//
excluded(aliases);
String string = exporter.getExportSingleInteractionString(reaction, params).get(0);
assertNotNull(string);
assertTrue(string.contains("Calcium channel:RIMBP:RIM:MUNC13:RAB"));
assertTrue(string.contains("CSP:Hsc70:SGT"));
assertTrue(string.contains("SNCA"));
assertTrue(string.contains("trans-SNARE complex"));
assertFalse(string.contains("VAMP2"));
params = new IExporterService.ExporterParameters().model(model).fileType(ExportFileType.SIF).type(Complex.class)
.type(Protein.class);
string = exporter.getExportSingleInteractionString(reaction, params).get(0);
assertTrue(string.contains("VAMP2"));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetExportStringForOneReactionInGeneral() {
try {
Model model = getModelForFile("testFiles/export/reaction.xml", true);
Reaction reaction = model.getReactionByReactionId("re2");
ExporterParameters params = new IExporterService.ExporterParameters().model(model).//
fileType(ExportFileType.SIF).//
complexElementsName(false).//
type(Complex.class).type(Protein.class);
String string = exporter.getExportSingleInteractionString(reaction, params).get(0);
assertNotNull(string);
assertTrue(string.contains("Calcium channel:RIMBP:RIM:MUNC13:RAB"));
assertTrue(string.contains("CSP:Hsc70:SGT"));
assertTrue(string.contains("SNCA"));
assertTrue(string.contains("trans-SNARE complex"));
assertTrue(string.contains("SNAP25"));
assertFalse(string.contains("RAB3A"));
params.complexElementsName(true);
string = exporter.getExportSingleInteractionString(reaction, params).get(0);
assertFalse(string.contains("trans-SNARE complex"));
assertTrue(string.contains("RAB3A"));
} catch (Exception e) {
e.printStackTrace();
fail("Exception occured");
}
}
@Test
public void testGetExportStringForOneReactionInGeneralWithOnlyOneElement() throws Exception {
try {
Model model = getModelForFile("testFiles/export/reaction.xml", false);
Reaction reaction = model.getReactionByReactionId("re11");
model.removeReactions(model.getReactions());
model.addReaction(reaction);
Set<Compartment> aliases = new HashSet<>();
aliases.add((Compartment) model.getElementByElementId("ca1"));
ExporterParameters params = new IExporterService.ExporterParameters().model(model).fileType(ExportFileType.SIF)
.included("dopamine loaded synaptic vesicle");
assertEquals(0, exporter.getExportSingleInteractionString(reaction, params).size());
params = new IExporterService.ExporterParameters().model(model).fileType(ExportFileType.SIF);
assertEquals(1, exporter.getExportSingleInteractionString(reaction, params).size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetExportSingleInteractionString_text() {
try {
Model model = getModelForFile("testFiles/export_with_artifitial_comp.xml", false);
for (Reaction reaction : model.getReactions()) {
String str = exporter
.getExportSingleInteractionString(reaction,
new IExporterService.ExporterParameters().fileType(ExportFileType.TAB_SEPARATED).type(Species.class))
.get(0);
List<String> strings = new ArrayList<String>();
strings.add(ReactionLineData.getByReactionType(reaction.getClass()).getCellDesignerString());
strings.add(reaction.getIdReaction());
for (ReactionNode node : reaction.getReactionNodes()) {
strings.add(node.getElement().getName());
}
for (String string : strings) {
assertTrue(
"Description \"" + str + "\" doesn't contain " + string + ". reactionId=" + reaction.getIdReaction(),
str.contains(string));
}
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception occured");
}
}
@Test
public void testGetExportComponentAndCompartments() throws Exception {
try {
Model model = getModelForFile("testFiles/export/export_model.xml", false);
new CreateHierarchyCommand(model, 7, 80).execute();
ExporterParameters params = new IExporterService.ExporterParameters().model(model)
.fileType(ExportFileType.TAB_SEPARATED).column(ExportColumn.NAME).column(ExportColumn.COMPONENT_NAME)
.column(ExportColumn.COMPARTMENT_NAME);
List<String> list = exporter.getExportStringForOneSpecies((Species) model.getElementByElementId("sa1"), params);
String desc = list.get(0);
String compartment = desc.split("\t")[2];
assertEquals("c1", compartment);
String component = desc.split("\t")[1];
assertEquals("Test3", component);
list = exporter.getExportStringForOneSpecies((Species) model.getElementByElementId("sa2"), params);
desc = null;
for (String string : list) {
if (string.contains("Test 1")) {
desc = string;
}
}
compartment = desc.split("\t")[2];
assertEquals("c2", compartment);
component = desc.split("\t")[1];
assertEquals("Test 1", component);
for (String string : list) {
if (string.contains("Test2")) {
desc = string;
}
}
compartment = desc.split("\t")[2];
assertEquals("c2", compartment);
component = desc.split("\t")[1];
assertEquals("Test2", component);
for (String string : list) {
if (string.contains("Test3")) {
desc = string;
}
}
compartment = desc.split("\t")[2];
assertEquals("c2", compartment);
component = desc.split("\t")[1];
assertEquals("Test3", component);
list = exporter.getExportStringForOneSpecies((Species) model.getElementByElementId("sa3"), params);
boolean ok = false;
for (String string : list) {
if (string.split("\t")[2].equals("null") && string.split("\t")[1].equals("Test2")) {
ok = true;
}
}
assertTrue(ok);
list = exporter.getExportStringForOneSpecies((Species) model.getElementByElementId("sa4"), params);
desc = list.get(0);
compartment = desc.split("\t")[2];
assertEquals("null", compartment);
component = desc.split("\t")[1];
assertEquals("Test3", component);
list = exporter.getExportStringForOneSpecies((Species) model.getElementByElementId("sa5"), params);
desc = list.get(0);
compartment = desc.split("\t")[2];
assertEquals("c3", compartment);
component = desc.split("\t")[1];
assertEquals("null", component);
list = exporter.getExportStringForOneSpecies((Species) model.getElementByElementId("sa6"), params);
desc = list.get(0);
compartment = desc.split("\t")[2];
assertEquals("null", compartment);
component = desc.split("\t")[1];
assertEquals("null", component);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetExportSpeciesStringForTabSeparatedFile2() throws Exception {
try {
Model model = getModelForFile("testFiles/export_with_artifitial_comp.xml", false);
ExportColumn columns[] = { ExportColumn.NAME, ExportColumn.ID, ExportColumn.COMPONENT_NAME,
ExportColumn.COMPARTMENT_NAME, ExportColumn.TYPE };
ExporterParameters params = new IExporterService.ExporterParameters().model(model).column(columns)
.fileType(ExportFileType.TAB_SEPARATED).type(Object.class);
// full export (all elements)
String string = exporter.getExportSpeciesString(params);
String lines[] = string.split("\n");
assertTrue("Not enough elements in the result file", lines.length > 1);
String response = lines[0];
String textColumns[] = response.split("\t");
assertEquals(columns.length, textColumns.length);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetExportCompartmentsString() throws Exception {
try {
Model model = getModelForFile("testFiles/export/export_compartments.xml", false);
ExporterParameters params = new IExporterService.ExporterParameters().model(model)
.fileType(ExportFileType.TAB_SEPARATED).type(Object.class);
// full export (all compartments)
String string = exporter.getExportCompartmentsString(params);
String lines[] = string.split("\n");
assertTrue("Not enough elements in the result file", lines.length >= 2);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAllExportColumnsSpecies() throws Exception {
try {
Model model = getModelForFile("testFiles/export_with_artifitial_comp.xml", false);
List<ExportColumn> columns = new ArrayList<ExportColumn>();
for (ExportColumn column : ExportColumn.values()) {
if (column.getClazz().isAssignableFrom(Species.class)) {
columns.add(column);
}
}
ExporterParameters params = new IExporterService.ExporterParameters().model(model).column(columns)
.fileType(ExportFileType.TAB_SEPARATED);
// full export (all elements)
String string = exporter.getExportSpeciesString(params);
assertNotNull(string);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAllExportColumnsReaction() throws Exception {
try {
Model model = getModelForFile("testFiles/export_with_artifitial_comp.xml", false);
List<ExportColumn> columns = new ArrayList<ExportColumn>();
for (ExportColumn column : ExportColumn.values()) {
if (column.getClazz().isAssignableFrom(Reaction.class)) {
columns.add(column);
}
}
ExporterParameters params = new IExporterService.ExporterParameters().model(model).column(columns)
.fileType(ExportFileType.TAB_SEPARATED);
// full export (all elements)
String string = exporter.getExportInteractionString(params);
assertNotNull(string);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetTabSeparatedReaction() throws Exception {
try {
Model model = getModelForFile("testFiles/export/reaction.xml", false);
Set<Compartment> aliases = new HashSet<>();
for (Compartment alias : model.getCompartments()) {
if (alias.getName().equalsIgnoreCase("Dopamine loaded synaptic vesicle"))
aliases.add(alias);
}
ExporterParameters params = new IExporterService.ExporterParameters().model(model).//
fileType(ExportFileType.TAB_SEPARATED).//
column(ExportColumn.REACTION_ID).//
column(ExportColumn.REACTION_TYPE).//
type(Species.class);
String string = exporter.getExportInteractionString(params);
assertTrue(string.indexOf("STATE_TRANSITION REACTANT") >= 0);
assertTrue(string.indexOf("sa7") >= 0);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void test() throws Exception {
try {
Model model = getModelForFile("testFiles/export/new_line_file.xml", false);
List<ExportColumn> columns = new ArrayList<ExportColumn>();
for (ExportColumn column : ExportColumn.values()) {
if (column.getClazz().isAssignableFrom(Species.class)) {
columns.add(column);
}
}
ExporterParameters params = new IExporterService.ExporterParameters().model(model).column(columns)
.fileType(ExportFileType.TAB_SEPARATED);
// full export (all elements)
String string = exporter.getExportSpeciesString(params);
String tmp[] = string.split("\n");
for (String string2 : tmp) {
assertTrue(string2, columns.size() <= string2.split("\t", -1).length);
}
assertNotNull(string);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testPubmedSummary() throws Exception {
try {
Model model = getModelForFile("testFiles/export/reaction.xml", false);
List<PubmedAnnotatedElementsView> result = exporter.getPublicationModelSummary(model);
assertNotNull(result);
for (PubmedAnnotatedElementsView pubmedAnnotatedElementsView : result) {
assertNotNull(pubmedAnnotatedElementsView.getArticle());
assertNotNull(pubmedAnnotatedElementsView.getArticle().getTitle());
assertTrue(pubmedAnnotatedElementsView.getElements().size() > 0);
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
......@@ -40,195 +40,197 @@ import lcsb.mapviewer.services.ServiceTestFunctions;
import lcsb.mapviewer.services.overlay.ChebiTreeRow;
public class FullAliasViewFactoryTest extends ServiceTestFunctions {
Logger logger = Logger.getLogger(FullAliasViewFactoryTest.class);
@Autowired
FullAliasViewFactory fullAliasViewFactory;
@Autowired
private ChebiAnnotator backend;
private Species alias;
private Species alias2;
private Point2D midPoint;
private Reaction reaction;
private Species alias3;
private Model model;
private Compartment compartmentAlias;
@Before
public void setUp() throws Exception {
model = new ModelFullIndexed(null);
model.setWidth(20010);
model.setHeight(20010);
model.setTileSize(256);
model.setZoomLevels(7);
model.addLayout(new Layout());
model.getModelData().setId(-12);
alias = new GenericProtein("AL1");
alias.setName("blablabla");
alias.setNotes("nottttttes");
alias.setX(10.0);
alias.setY(12.0);
alias.getMiriamData().add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.WIKIPEDIA, "144352"));
alias.getMiriamData().add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.PUBMED, "43345"));
model.addElement(alias);
alias2 = new GenericProtein("AL2");
alias2.setName("blablabla2");
alias2.setX(100.0);
alias2.setY(120.0);
model.addElement(alias2);
midPoint = new Point2D.Double(30, 100);
reaction = new Reaction();
Reactant reactant = new Reactant(alias);
reactant.setLine(new PolylineData(alias.getCenter(), midPoint));
reaction.addReactant(reactant);
Product product = new Product(alias2);
product.setLine(new PolylineData(alias2.getCenter(), midPoint));
reaction.addProduct(product);
model.addReaction(reaction);
alias3 = new GenericProtein("AL3");
alias3.setName("blablabla3");
alias3.setX(200.0);
alias3.setY(120.0);
model.addElement(alias3);
reaction = new NegativeInfluenceReaction(reaction);
reaction.getMiriamData().add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.CAS, "cc"));
model.addReaction(reaction);
compartmentAlias = new Compartment("AL4");
compartmentAlias.setX(10);
compartmentAlias.setY(10);
compartmentAlias.setWidth(10);
compartmentAlias.setHeight(10);
model.addElement(compartmentAlias);
}
@After
public void tearDown() throws Exception {
}
@Test
public void testCreateGson() {
try {
Element alias = new GenericProtein("id");
alias.setName("12");
alias.setModel(new ModelFullIndexed(null));
FullAliasView object = fullAliasViewFactory.create(alias);
String gson = fullAliasViewFactory.createGson(object);
assertNotNull(gson);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAliasOverlay() throws Exception {
try {
FullAliasView result = fullAliasViewFactory.create(alias);
assertNotNull(result);
assertEquals(model.getId(), result.getModelId());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAliasOverlay2() throws Exception {
try {
FullAliasView result = fullAliasViewFactory.create(alias2);
assertNotNull(result);
assertEquals(model.getId(), result.getModelId());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetNotes() throws Exception {
try {
Model model = getModelForFile("testFiles/protein_with_modification.xml", true);
model.setTileSize(256);
Species alias = (Species) model.getElementByElementId("sa1");
FullAliasView marker = fullAliasViewFactory.create(alias);
List<?> list = (List<?>) marker.getOther("posttranslationalModifications");
assertNotNull(list);
assertEquals(2, list.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testCreateChebiTree() throws Exception {
try {
Chebi chebi = backend.getChebiElementForChebiId(new MiriamData(MiriamType.CHEBI, "CHEBI:15377"));
TreeNode root = fullAliasViewFactory.createTreeForChebi(chebi);
Set<String> el = new HashSet<String>();
assertNotNull(root);
Queue<TreeNode> elements = new LinkedList<TreeNode>();
elements.add(root);
while (!elements.isEmpty()) {
TreeNode node = elements.peek();
elements.remove();
el.add(((ChebiTreeRow) node.getData()).getName());
for (TreeNode child : node.getChildren()) {
elements.add(child);
}
}
assertTrue(el.size() > 3);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAnnotationsInConversionForChebiTree() throws Exception {
try {
Model model = getModelForFile("testFiles/graph_path_example3.xml", false);
model.setTileSize(256);
Species alias = (Species) model.getElementByElementId("sa4");
assertNotNull(alias);
FullAliasView result = fullAliasViewFactory.create(alias);
assertNotNull(result.getOther("chebiTree"));
alias = (Species) model.getElementByElementId("sa3");
result = fullAliasViewFactory.create(alias);
assertNull(result.getOther("chebiTree"));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
Logger logger = Logger.getLogger(FullAliasViewFactoryTest.class);
@Autowired
FullAliasViewFactory fullAliasViewFactory;
@Autowired
private ChebiAnnotator backend;
private Species alias;
private Species alias2;
private Point2D midPoint;
private Reaction reaction;
private Species alias3;
private Model model;
private Compartment compartmentAlias;
@Before
public void setUp() throws Exception {
model = new ModelFullIndexed(null);
model.setWidth(20010);
model.setHeight(20010);
model.setTileSize(256);
model.setZoomLevels(7);
model.addLayout(new Layout());
model.getModelData().setId(-12);
alias = new GenericProtein("AL1");
alias.setName("blablabla");
alias.setNotes("nottttttes");
alias.setX(10.0);
alias.setY(12.0);
alias.getMiriamData()
.add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.WIKIPEDIA, "144352"));
alias.getMiriamData().add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.PUBMED, "43345"));
model.addElement(alias);
alias2 = new GenericProtein("AL2");
alias2.setName("blablabla2");
alias2.setX(100.0);
alias2.setY(120.0);
model.addElement(alias2);
midPoint = new Point2D.Double(30, 100);
reaction = new Reaction("re1");
Reactant reactant = new Reactant(alias);
reactant.setLine(new PolylineData(alias.getCenter(), midPoint));
reaction.addReactant(reactant);
Product product = new Product(alias2);
product.setLine(new PolylineData(alias2.getCenter(), midPoint));
reaction.addProduct(product);
model.addReaction(reaction);
alias3 = new GenericProtein("AL3");
alias3.setName("blablabla3");
alias3.setX(200.0);
alias3.setY(120.0);
model.addElement(alias3);
reaction = new NegativeInfluenceReaction(reaction);
reaction.setIdReaction("re2");
reaction.getMiriamData().add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.CAS, "cc"));
model.addReaction(reaction);
compartmentAlias = new Compartment("AL4");
compartmentAlias.setX(10);
compartmentAlias.setY(10);
compartmentAlias.setWidth(10);
compartmentAlias.setHeight(10);
model.addElement(compartmentAlias);
}
@After
public void tearDown() throws Exception {
}
@Test
public void testCreateGson() {
try {
Element alias = new GenericProtein("id");
alias.setName("12");
alias.setModel(new ModelFullIndexed(null));
FullAliasView object = fullAliasViewFactory.create(alias);
String gson = fullAliasViewFactory.createGson(object);
assertNotNull(gson);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAliasOverlay() throws Exception {
try {
FullAliasView result = fullAliasViewFactory.create(alias);
assertNotNull(result);
assertEquals(model.getId(), result.getModelId());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAliasOverlay2() throws Exception {
try {
FullAliasView result = fullAliasViewFactory.create(alias2);
assertNotNull(result);
assertEquals(model.getId(), result.getModelId());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetNotes() throws Exception {
try {
Model model = getModelForFile("testFiles/protein_with_modification.xml", true);
model.setTileSize(256);
Species alias = (Species) model.getElementByElementId("sa1");
FullAliasView marker = fullAliasViewFactory.create(alias);
List<?> list = (List<?>) marker.getOther("posttranslationalModifications");
assertNotNull(list);
assertEquals(2, list.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testCreateChebiTree() throws Exception {
try {
Chebi chebi = backend.getChebiElementForChebiId(new MiriamData(MiriamType.CHEBI, "CHEBI:15377"));
TreeNode root = fullAliasViewFactory.createTreeForChebi(chebi);
Set<String> el = new HashSet<String>();
assertNotNull(root);
Queue<TreeNode> elements = new LinkedList<TreeNode>();
elements.add(root);
while (!elements.isEmpty()) {
TreeNode node = elements.peek();
elements.remove();
el.add(((ChebiTreeRow) node.getData()).getName());
for (TreeNode child : node.getChildren()) {
elements.add(child);
}
}
assertTrue(el.size() > 3);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAnnotationsInConversionForChebiTree() throws Exception {
try {
Model model = getModelForFile("testFiles/graph_path_example3.xml", false);
model.setTileSize(256);
Species alias = (Species) model.getElementByElementId("sa4");
assertNotNull(alias);
FullAliasView result = fullAliasViewFactory.create(alias);
assertNotNull(result.getOther("chebiTree"));
alias = (Species) model.getElementByElementId("sa3");
result = fullAliasViewFactory.create(alias);
assertNull(result.getOther("chebiTree"));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment