Skip to content

Commit

Permalink
Merge pull request #193 from samtools/gg_allow_liftover_comment_lines
Browse files Browse the repository at this point in the history
Allow comment lines in liftover chain files.
  • Loading branch information
gbggrant committed May 27, 2015
2 parents ea46734 + d4f1ead commit b6bc0ad
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/java/htsjdk/samtools/liftover/Chain.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,10 @@ public int hashCode() {
* @return OverlapDetector will all Chains from reader loaded into it.
*/
static OverlapDetector<Chain> loadChains(final File chainFile) {
final Set<Integer> ids = new HashSet<Integer>();
BufferedLineReader reader = new BufferedLineReader(IOUtil.openFileForReading(chainFile));
final BufferedLineReader reader = new BufferedLineReader(IOUtil.openFileForReading(chainFile));
final OverlapDetector<Chain> ret = new OverlapDetector<Chain>(0, 0);
Chain chain;
while ((chain = Chain.loadChain(reader, chainFile.toString())) != null) {
if (ids.contains(chain.id)) {
throw new SAMException("Chain id " + chain.id + " appears more than once in chain file.");
}
ids.add(chain.id);
ret.addLhs(chain, chain.interval);
}
reader.close();
Expand All @@ -336,11 +331,18 @@ static OverlapDetector<Chain> loadChains(final File chainFile) {
* @return New Chain with associated ContinuousBlocks.
*/
private static Chain loadChain(final BufferedLineReader reader, final String chainFile) {
String line = reader.readLine();
if (line == null) {
return null;
String line;
while (true) {
line = reader.readLine();
if (line == null) {
return null;
}
// Skip comment lines
if (!line.startsWith("#")) {
break;
}
}
String[] chainFields = SPLITTER.split(line);
final String[] chainFields = SPLITTER.split(line);
if (chainFields.length != 13) {
throwChainFileParseException("chain line has wrong number of fields", chainFile, reader.getLineNumber());
}
Expand Down

0 comments on commit b6bc0ad

Please sign in to comment.