|
| 1 | +package nl.tudelft.dnainator.graph.impl.command; |
| 2 | + |
| 3 | +import nl.tudelft.dnainator.annotation.impl.AnnotationCollectionImpl; |
| 4 | +import nl.tudelft.dnainator.annotation.impl.AnnotationImpl; |
| 5 | +import nl.tudelft.dnainator.core.EnrichedSequenceNode; |
| 6 | +import nl.tudelft.dnainator.core.impl.SequenceNodeFactoryImpl; |
| 7 | +import nl.tudelft.dnainator.graph.impl.Neo4jBatchBuilder; |
| 8 | +import nl.tudelft.dnainator.graph.impl.Neo4jGraph; |
| 9 | +import nl.tudelft.dnainator.graph.impl.NodeLabels; |
| 10 | +import nl.tudelft.dnainator.graph.impl.command.MutationFinderCommand; |
| 11 | +import nl.tudelft.dnainator.graph.impl.properties.SequenceProperties; |
| 12 | +import nl.tudelft.dnainator.parser.EdgeParser; |
| 13 | +import nl.tudelft.dnainator.parser.NodeParser; |
| 14 | +import nl.tudelft.dnainator.parser.TreeParser; |
| 15 | +import nl.tudelft.dnainator.parser.exceptions.ParseException; |
| 16 | +import nl.tudelft.dnainator.parser.impl.EdgeParserImpl; |
| 17 | +import nl.tudelft.dnainator.parser.impl.NodeParserImpl; |
| 18 | +import nl.tudelft.dnainator.tree.TreeNode; |
| 19 | + |
| 20 | +import org.junit.AfterClass; |
| 21 | +import org.junit.BeforeClass; |
| 22 | +import org.junit.Test; |
| 23 | +import org.neo4j.graphdb.Node; |
| 24 | +import org.neo4j.io.fs.FileUtils; |
| 25 | + |
| 26 | +import java.io.BufferedReader; |
| 27 | +import java.io.File; |
| 28 | +import java.io.IOException; |
| 29 | +import java.io.InputStream; |
| 30 | +import java.io.InputStreamReader; |
| 31 | +import java.net.URISyntaxException; |
| 32 | +import java.util.Collection; |
| 33 | +import java.util.stream.Collectors; |
| 34 | + |
| 35 | +import static org.junit.Assert.assertEquals; |
| 36 | +import static org.junit.Assert.fail; |
| 37 | + |
| 38 | +public class MutationFinderCommandTest { |
| 39 | + private static final String DB_PATH = "target/neo4j-tree-junit"; |
| 40 | + private static Neo4jGraph db; |
| 41 | + private static InputStream nodeFile; |
| 42 | + private static InputStream edgeFile; |
| 43 | + private static AnnotationImpl first; |
| 44 | + private static AnnotationImpl middle; |
| 45 | + private static AnnotationImpl last; |
| 46 | + |
| 47 | + /** |
| 48 | + * Setup the database and construct the graph. |
| 49 | + * @throws URISyntaxException |
| 50 | + */ |
| 51 | + @BeforeClass |
| 52 | + public static void setUp() throws URISyntaxException { |
| 53 | + try { |
| 54 | + FileUtils.deleteRecursively(new File(DB_PATH)); |
| 55 | + nodeFile = getNodeFile(); |
| 56 | + edgeFile = getEdgeFile(); |
| 57 | + NodeParser np = new NodeParserImpl(new SequenceNodeFactoryImpl(), |
| 58 | + new BufferedReader(new InputStreamReader(nodeFile, "UTF-8"))); |
| 59 | + EdgeParser ep = new EdgeParserImpl(new BufferedReader( |
| 60 | + new InputStreamReader(edgeFile, "UTF-8"))); |
| 61 | + TreeNode phylo = new TreeParser(getTreeFile()).parse(); |
| 62 | + db = (Neo4jGraph) new Neo4jBatchBuilder(DB_PATH, new AnnotationCollectionImpl(), phylo) |
| 63 | + .constructGraph(np, ep) |
| 64 | + .build(); |
| 65 | + } catch (IOException e) { |
| 66 | + fail("Couldn't initialize DB"); |
| 67 | + } catch (ParseException e) { |
| 68 | + fail("Couldn't parse file: " + e.getMessage()); |
| 69 | + } |
| 70 | + //CHECKSTYLE.OFF: MagicNumber |
| 71 | + first = new AnnotationImpl("first", 0, 10, true); |
| 72 | + middle = new AnnotationImpl("middle", 5, 25, true); |
| 73 | + last = new AnnotationImpl("last", 20, 30, true); |
| 74 | + //CHECKSTYLE.ON: MagicNumber |
| 75 | + db.addAnnotation(first); |
| 76 | + db.addAnnotation(middle); |
| 77 | + db.addAnnotation(last); |
| 78 | + } |
| 79 | + |
| 80 | + private static InputStream getNodeFile() { |
| 81 | + return MutationFinderCommandTest.class.getResourceAsStream("/strains/advancedtopo.node.graph"); |
| 82 | + } |
| 83 | + |
| 84 | + private static InputStream getEdgeFile() { |
| 85 | + return MutationFinderCommandTest.class.getResourceAsStream("/strains/advancedtopo.edge.graph"); |
| 86 | + } |
| 87 | + |
| 88 | + private static File getTreeFile() throws URISyntaxException { |
| 89 | + return new File(MutationFinderCommandTest.class.getResource("/strains/advancedtopo.nwk") |
| 90 | + .toURI()); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Test returning a source set. |
| 95 | + * @param expected |
| 96 | + * @param actual |
| 97 | + */ |
| 98 | + @Test |
| 99 | + public void testIndependentMutations() { |
| 100 | + db.execute(e -> { |
| 101 | + Node node = e.findNode(NodeLabels.NODE, SequenceProperties.ID.name(), "6"); |
| 102 | + new MutationFinderCommand(node).execute(e); |
| 103 | + }); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Clean up after ourselves. |
| 108 | + * @throws IOException when the database could not be deleted |
| 109 | + */ |
| 110 | + @AfterClass |
| 111 | + public static void cleanUp() throws IOException { |
| 112 | + db.shutdown(); |
| 113 | + } |
| 114 | +} |
0 commit comments