/* * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.io; import jalview.datamodel.CigarParser; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import java.io.File; import java.io.IOException; import java.util.SortedMap; import htsjdk.samtools.SAMRecord; import htsjdk.samtools.SAMRecordIterator; import htsjdk.samtools.SamReader; import htsjdk.samtools.SamReaderFactory; import htsjdk.samtools.ValidationStringency; public class BamFile extends AlignFile { SamReader fileReader; /** * Creates a new BamFile object. */ public BamFile() { } /** * Creates a new BamFile object. * * @param inFile * DOCUMENT ME! * @param sourceType * DOCUMENT ME! * * @throws IOException * DOCUMENT ME! */ public BamFile(String inFile, DataSourceType sourceType) throws IOException { super(inFile, sourceType); final SamReaderFactory factory = SamReaderFactory.makeDefault() .enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS) .validationStringency(ValidationStringency.SILENT); fileReader = factory.open(new File(inFile)); } public BamFile(FileParse source) throws IOException { final SamReaderFactory factory = SamReaderFactory.makeDefault() .enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS) .validationStringency(ValidationStringency.SILENT); // File-based bam fileReader = factory.open(source.inFile); parse(); } @Override public String print(SequenceI[] seqs, boolean jvsuffix) { // TODO Auto-generated method stub return null; } @Override public void parse() throws IOException { CigarParser parser = new CigarParser('-'); SAMRecordIterator it = fileReader.iterator(); SortedMap insertions = parser.getInsertions(it); it.close(); it = fileReader.iterator(); while (it.hasNext()) { SAMRecord rec = it.next(); int start = rec.getStart(); int end = rec.getEnd(); SequenceI seq = new Sequence(rec.getReadName(), rec.getReadString()); String cigarredRead = parser.parseCigarToSequence(rec, insertions); SequenceI alsq = seq.deriveSequence(); alsq.setSequence(cigarredRead); alsq.setStart(start); alsq.setEnd(end); seqs.add(alsq); } } }