DataMatrixIO { public static void convertToMap(String matrixFileZip, String entrezId2indexFileZip, Path outfileName) { Map<Integer, Integer> index = createIndex(entrezId2indexFileZip); DataMatrix dataMatrix = loadInMemoryDataMatrixFromFile(matrixFileZip, entrezId2indexFileZip, true); MVStore mvStore = MVStore.open(outfileName.toAbsolutePath().toString()); MVMap<Integer, Integer> rowIndex = mvStore.openMap("gene_id_row_index"); MVMap<Integer, float[]> columns = mvStore.openMap("columns"); FloatMatrix floatMatrix = dataMatrix.getMatrix(); for (Map.Entry<Integer, Integer> geneIdToIndex : index.entrySet()) { Integer geneId = geneIdToIndex.getKey(); Integer indexKey = geneIdToIndex.getValue(); rowIndex.put(geneId, indexKey); FloatMatrix col = floatMatrix.getColumn(indexKey); float[] colVals = col.toArray(); columns.put(geneId, colVals); } mvStore.commit(); mvStore.close(); } private  DataMatrixIO(); static void convertToMap(String matrixFileZip, String entrezId2indexFileZip, Path outfileName); static DataMatrix loadOffHeapDataMatrix(Path ppiMapPath); static DataMatrix loadInMemoryDataMatrix(Path ppiMapPath); static DataMatrix loadInMemoryDataMatrixFromFile(String matrixFileZip, String entrezId2indexFileZip, boolean shouldUseExponent); static void writeMatrix(DataMatrix dataMatrix, String file, boolean doLogarithm); static void writeMatrix(FloatMatrix matrix, String file, Map<String, Integer> id2index, boolean doLogarithm); static void writeMatrixInclHeaderAndRowIDs(DataMatrix dataMatrix, String file, boolean doLogarithm); static void writeMatrixInclHeaderAndRowIDs(FloatMatrix matrix, String file, Map<String, Integer> id2index, boolean doLogarithm);  }
@Test public void testConvertToMap() throws Exception{ String dataPath = "src/test/resources/prioritisers/"; String indexPath = dataPath + "test_ppi_matrix_id2index.gz"; String matrixPath = dataPath + "test_ppi_matrix.gz"; Path matrixMapFile = Files.createTempFile("test_ppi_matrix", ".mv"); DataMatrixIO.convertToMap(matrixPath, indexPath, matrixMapFile); DataMatrix inMemoryMapMatrix = DataMatrixIO.loadInMemoryDataMatrix(matrixMapFile); DataMatrix offHeapMapMatrix = DataMatrixIO.loadOffHeapDataMatrix(matrixMapFile); DataMatrix fromFile = DataMatrixIO.loadInMemoryDataMatrixFromFile(matrixPath, indexPath, true); assertThat(offHeapMapMatrix.getEntrezIdToRowIndex(), equalTo(fromFile.getEntrezIdToRowIndex())); testMatrixEquality(offHeapMapMatrix.getMatrix(), fromFile.getMatrix()); testMatrixEquality(inMemoryMapMatrix.getMatrix(), fromFile.getMatrix()); }