final SAMSequenceDictionary readsDict) {
Map<Integer, Integer> newOrder = new HashMap<Integer, Integer>();
log.info("Reordering SAM/BAM file:");
for (final SAMSequenceRecord refRec : refDict.getSequences() ) {
final SAMSequenceRecord readsRec = readsDict.getSequence(refRec.getSequenceName());
if (readsRec != null) {
if ( refRec.getSequenceLength() != readsRec.getSequenceLength() ) {
String msg = String.format("Discordant contig lengths: read %s LN=%d, ref %s LN=%d",
readsRec.getSequenceName(), readsRec.getSequenceLength(),
refRec.getSequenceName(), refRec.getSequenceLength());
if ( ALLOW_CONTIG_LENGTH_DISCORDANCE ) {
log.warn(msg);
}
else {
throw new PicardException(msg);
}
}
log.info(String.format(" Reordering read contig %s [index=%d] to => ref contig %s [index=%d]%n",
readsRec.getSequenceName(), readsRec.getSequenceIndex(),
refRec.getSequenceName(), refRec.getSequenceIndex() ));
newOrder.put(readsRec.getSequenceIndex(), refRec.getSequenceIndex());
}
}
for ( SAMSequenceRecord readsRec : readsDict.getSequences() ) {
if ( ! newOrder.containsKey(readsRec.getSequenceIndex()) ) {
if ( ALLOW_INCOMPLETE_DICT_CONCORDANCE )
newOrder.put(readsRec.getSequenceIndex(), -1);
else
throw new PicardException("New reference sequence does not contain a matching contig for " + readsRec.getSequenceName());
}
}
return newOrder;
}