public void addSequence(final SAMSequenceRecord sequenceRecord) { mSequenceDictionary.addSequence(sequenceRecord); }
public void addSequence(final SAMSequenceRecord sequenceRecord) { mSequenceDictionary.addSequence(sequenceRecord); }
public void addSequence(final SAMSequenceRecord sequenceRecord) { mSequenceDictionary.addSequence(sequenceRecord); }
/** * 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 InMemoryReferenceSequenceFile(String[] contigNames, byte[][] sequences) { dictionary = new SAMSequenceDictionary(); for (int i = 0; i < contigNames.length; i++) { dictionary.addSequence(new SAMSequenceRecord(contigNames[i], sequences[i].length)); } this.sequences = sequences; } @Override
public void addSequence(final String name, final byte[] bases) { final SAMSequenceRecord r = new SAMSequenceRecord(name, bases.length); dictionary.addSequence(r); final int index = getSequenceDictionary().getSequenceIndex(name); sequences.put(index, bases); }
public void addSequence(final String name, final byte[] bases) { final SAMSequenceRecord r = new SAMSequenceRecord(name, bases.length); dictionary.addSequence(r); final int index = getSequenceDictionary().getSequenceIndex(name); sequences.put(index, bases); }
public void addSequence(String name, byte[] bases) { SAMSequenceRecord r = new SAMSequenceRecord(name, bases.length); dictionary.addSequence(r); int index = getSequenceDictionary().getSequenceIndex(name); sequences.put(index, bases); }
/** * create the sequence dictionary with the contig list; a backup approach * @param index the index file to use * @param dict the sequence dictionary to add contigs to * @return the filled-in sequence dictionary */ static SAMSequenceDictionary createSequenceDictionaryFromContigList(final Index index, final SAMSequenceDictionary dict) { final List<String> seqNames = index.getSequenceNames(); if (seqNames == null) { return dict; } for (final String name : seqNames) { SAMSequenceRecord seq = new SAMSequenceRecord(name, 0); dict.addSequence(seq); } return dict; }
public BGZF_ReferenceSequenceFile(File file) throws FileNotFoundException { if (!file.canRead()) throw new RuntimeException("Cannot find or read fasta file: " + file.getAbsolutePath()); File indexFile = new File(file.getAbsolutePath() + ".fai"); if (!indexFile.canRead()) throw new RuntimeException("Cannot find or read fasta index file: " + indexFile.getAbsolutePath()); Scanner scanner = new Scanner(indexFile); int seqID = 0; dictionary = new SAMSequenceDictionary(); while (scanner.hasNextLine()) { String line = scanner.nextLine(); FAIDX_FastaIndexEntry entry = FAIDX_FastaIndexEntry.fromString(seqID++, line); index.put(entry.getName(), entry); dictionary.addSequence(new SAMSequenceRecord(entry.getName(), entry.getLen())); } scanner.close(); if (index.isEmpty()) log.warn("No entries in the index: " + indexFile.getAbsolutePath()); is = new BlockCompressedInputStream(new SeekableFileStream(file)); }
@Test public void testEmptyCraiReadAsBai() throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final GZIPOutputStream gos = new GZIPOutputStream(baos); gos.close(); final SAMSequenceDictionary dictionary = new SAMSequenceDictionary(); dictionary.addSequence(new SAMSequenceRecord("1", 100)); final InputStream inputStream = SamIndexes.asBaiStreamOrNull(new ByteArrayInputStream(baos.toByteArray()), dictionary); for (final byte b : SamIndexes.BAI.magic) { Assert.assertEquals(inputStream.read(), 0xFF & b); } }
@Test public void testOpenIndexFileAsBaiOrNull_ReturnsNull() throws IOException { final SAMSequenceDictionary dictionary = new SAMSequenceDictionary(); dictionary.addSequence(new SAMSequenceRecord("1", 100)); File file = File.createTempFile("test", ".notbai"); file.deleteOnExit(); Assert.assertNull(SamIndexes.openIndexFileAsBaiOrNull(file, dictionary)); file.delete(); file = File.createTempFile("test", ".notcrai"); file.deleteOnExit(); Assert.assertNull(SamIndexes.openIndexFileAsBaiOrNull(file, dictionary)); file.delete(); }
@Test(expectedExceptions = NullPointerException.class) public void testOpenIndexFileAsBaiOrNull_NPE() throws IOException { final SAMSequenceDictionary dictionary = new SAMSequenceDictionary(); dictionary.addSequence(new SAMSequenceRecord("1", 100)); Assert.assertNull(SamIndexes.openIndexFileAsBaiOrNull(null, dictionary)); }
@BeforeClass public void init() { SAMSequenceDictionary sequenceDictionary = new SAMSequenceDictionary(); sequenceDictionary.addSequence(new SAMSequenceRecord("1",500)); sequenceDictionary.addSequence(new SAMSequenceRecord("2",500)); samFileHeader = new SAMFileHeader(); samFileHeader.setSequenceDictionary(sequenceDictionary); }
protected SAMSequenceDictionary loadSequenceDictionary() throws ErrorMsg { SAMSequenceDictionary dict = new SAMSequenceDictionary(); ReferenceIterator itRef = run.getReferences(); while (itRef.nextReference()) { dict.addSequence(new SAMSequenceRecord(itRef.getCanonicalName(), (int) itRef.getLength())); } return dict; } }
protected SAMSequenceDictionary loadSequenceDictionary() throws ErrorMsg { SAMSequenceDictionary dict = new SAMSequenceDictionary(); ReferenceIterator itRef = run.getReferences(); while (itRef.nextReference()) { dict.addSequence(new SAMSequenceRecord(itRef.getCanonicalName(), (int) itRef.getLength())); } return dict; } }
/** * Creates an artificial sam header, matching the parameters, chromosomes which will be labeled chr1, chr2, etc * * @param numberOfChromosomes the number of chromosomes to create * @param startingChromosome the starting number for the chromosome (most likely set to 1) * @param chromosomeSize the length of each chromosome * @return */ public static SAMFileHeader createArtificialSamHeader(int numberOfChromosomes, int startingChromosome, int chromosomeSize) { SAMFileHeader header = new SAMFileHeader(); header.setSortOrder(htsjdk.samtools.SAMFileHeader.SortOrder.coordinate); SAMSequenceDictionary dict = new SAMSequenceDictionary(); // make up some sequence records for (int x = startingChromosome; x < startingChromosome + numberOfChromosomes; x++) { SAMSequenceRecord rec = new SAMSequenceRecord("chr" + (x), chromosomeSize /* size */); dict.addSequence(rec); } header.setSequenceDictionary(dict); return header; }
private void doCRAITest(BiFunction<SAMSequenceDictionary, List<CRAIEntry>, SeekableStream> getBaiStreamForIndex) { final ArrayList<CRAIEntry> index = new ArrayList<>(); final CRAIEntry entry = CRAIEntryTest.newEntry(0, 1, 2, 5, 3, 4); index.add(entry); final SAMSequenceDictionary dictionary = new SAMSequenceDictionary(); dictionary.addSequence(new SAMSequenceRecord("1", 100)); final SeekableStream baiStream = getBaiStreamForIndex.apply(dictionary, index); final DiskBasedBAMFileIndex bamIndex = new DiskBasedBAMFileIndex(baiStream, dictionary); final BAMFileSpan span = bamIndex.getSpanOverlapping(entry.getSequenceId(), entry.getAlignmentStart(), entry.getAlignmentStart()); Assert.assertNotNull(span); final long[] coordinateArray = span.toCoordinateArray(); Assert.assertEquals(coordinateArray.length, 2); Assert.assertEquals(coordinateArray[0] >> 16, entry.getContainerStartByteOffset()); Assert.assertEquals(coordinateArray[1] & 0xFFFF, 1); }
@Test public void testContigHasColon() { SAMFileHeader header = new SAMFileHeader(); header.setSortOrder(htsjdk.samtools.SAMFileHeader.SortOrder.coordinate); SAMSequenceDictionary dict = new SAMSequenceDictionary(); SAMSequenceRecord rec = new SAMSequenceRecord("c:h:r1", 10); rec.setSequenceLength(10); dict.addSequence(rec); header.setSequenceDictionary(dict); final GenomeLocParser myGenomeLocParser = new GenomeLocParser(header.getSequenceDictionary()); GenomeLoc loc = myGenomeLocParser.parseGenomeLoc("c:h:r1:4-5"); assertEquals(0, loc.getContigIndex()); assertEquals(loc.getStart(), 4); assertEquals(loc.getStop(), 5); }
@DataProvider(name="haplotypeMapForWriting") public Object[][] haplotypeMapForWriting() { SAMFileHeader header = new SAMFileHeader(); header.setSortOrder(SAMFileHeader.SortOrder.coordinate); SAMSequenceDictionary sd = new SAMSequenceDictionary(); sd.addSequence(new SAMSequenceRecord("chr1", 101)); sd.addSequence(new SAMSequenceRecord("chr2", 101)); sd.addSequence(new SAMSequenceRecord("chr3", 101)); header.setSequenceDictionary(sd); HaplotypeMap newMap = new HaplotypeMap(header); HaplotypeBlock t1 = new HaplotypeBlock(0.151560926); t1.addSnp(new Snp("snp2", "chr1", 83, (byte)'A', (byte)'G', .16, null)); t1.addSnp(new Snp("snp1", "chr1", 51, (byte)'T', (byte)'C', 0.15, Collections.singletonList("SQNM_1CHIP_FingerprintAssays"))); newMap.addHaplotype(t1); HaplotypeBlock t2 = new HaplotypeBlock(.02d); t2.addSnp(new Snp("snp3", "chr2", 24, (byte)'C', (byte)'A', .20, null)); newMap.addHaplotype(t2); return new Object[][]{{newMap}}; }