/** * get the sequence dictionary from the track, if available. If not, make it from the contig list that is always in the index * @param index the index file to use * @return a SAMSequenceDictionary if available, null if unavailable */ public static SAMSequenceDictionary getSequenceDictionaryFromProperties(Index index) { SAMSequenceDictionary dict = new SAMSequenceDictionary(); for (Map.Entry<String,String> entry : index.getProperties().entrySet()) { if (entry.getKey().startsWith(SequenceDictionaryPropertyPredicate)) dict.addSequence(new SAMSequenceRecord(entry.getKey().substring(SequenceDictionaryPropertyPredicate.length() , entry.getKey().length()), Integer.valueOf(entry.getValue()))); } return dict; }
public String[] getSamples() { if (this.tribbleFeatureSource.isIndexed()) { // Load the index for meta information. Its already loaded, but not public in the htsjdk class. Index idx = loadIndex(this.locator.getPath()); if (idx != null) { Map<String, String> map = idx.getProperties(); if (map != null && map.containsKey("samples")) { return Globals.commaPattern.split(map.get("samples")); } } } // Try to fetch features from codec. This is to support a deprecated option to // specify sample names in the .mut or .maf file header. MUTCodec codec = new MUTCodec(locator.getPath(), null); return codec.getSamples(); }
@Test(dataProvider = "writeIndexData") public void testWriteIndex(final File inputFile, final IndexFactory.IndexType type, final FeatureCodec codec) throws Exception { // temp index file for this test final File tempIndex = File.createTempFile("index", (type == IndexFactory.IndexType.TABIX) ? TabixUtils.STANDARD_INDEX_EXTENSION : Tribble.STANDARD_INDEX_EXTENSION); tempIndex.delete(); tempIndex.deleteOnExit(); // create the index final Index index = IndexFactory.createIndex(inputFile, codec, type); Assert.assertFalse(tempIndex.exists()); // write the index to a file index.write(tempIndex); Assert.assertTrue(tempIndex.exists()); // load the generated index final Index loadedIndex = IndexFactory.loadIndex(tempIndex.getAbsolutePath()); //TODO: This is just a smoke test; it can pass even if the generated index is unusable for queries. // test that the sequences and properties are the same Assert.assertEquals(loadedIndex.getSequenceNames(), index.getSequenceNames()); Assert.assertEquals(loadedIndex.getProperties(), index.getProperties()); // test that write to a stream does not blows ip index.write(new LittleEndianOutputStream(nullOutputStrem)); }