2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.datamodel.CigarParser;
24 import jalview.datamodel.Sequence;
25 import jalview.datamodel.SequenceI;
28 import java.io.IOException;
29 import java.util.SortedMap;
31 import htsjdk.samtools.SAMRecord;
32 import htsjdk.samtools.SAMRecordIterator;
33 import htsjdk.samtools.SamReader;
34 import htsjdk.samtools.SamReaderFactory;
35 import htsjdk.samtools.ValidationStringency;
37 public class BamFile extends AlignFile
43 * Creates a new BamFile object.
50 * Creates a new BamFile object.
60 public BamFile(String inFile, DataSourceType sourceType)
63 super(inFile, sourceType);
64 final SamReaderFactory factory = SamReaderFactory.makeDefault()
65 .enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS,
66 SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS)
67 .validationStringency(ValidationStringency.SILENT);
68 fileReader = factory.open(new File(inFile));
71 public BamFile(FileParse source) throws IOException
73 final SamReaderFactory factory = SamReaderFactory.makeDefault()
74 .enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS,
75 SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS)
76 .validationStringency(ValidationStringency.SILENT);
79 fileReader = factory.open(source.inFile);
84 public String print(SequenceI[] seqs, boolean jvsuffix)
86 // TODO Auto-generated method stub
91 public void parse() throws IOException
93 CigarParser parser = new CigarParser('-');
94 SAMRecordIterator it = fileReader.iterator();
95 SortedMap<Integer, Integer> insertions = parser.getInsertions(it);
98 it = fileReader.iterator();
101 SAMRecord rec = it.next();
102 int start = rec.getStart();
103 int end = rec.getEnd();
105 SequenceI seq = new Sequence(rec.getReadName(), rec.getReadString());
107 String cigarredRead = parser.parseCigarToSequence(rec, insertions);
109 SequenceI alsq = seq.deriveSequence();
110 alsq.setSequence(cigarredRead);
111 alsq.setStart(start);