use of htsjdk.samtools.SAMSequenceRecord in project gatk by broadinstitute.
the class PlotACNVResults method doWork.
@Override
protected Object doWork() {
checkRegularReadableUserFiles();
//get sample name from input files (consistency check is performed)
final String sampleName = getSampleName();
//load contig names and lengths from the sequence dictionary into a LinkedHashMap
final SAMSequenceDictionary sequenceDictionary = ReferenceUtils.loadFastaDictionary(sequenceDictionaryFile);
Utils.validateArg(sequenceDictionary.getSequences().stream().map(SAMSequenceRecord::getSequenceName).noneMatch(n -> n.contains(CONTIG_DELIMITER)), String.format("Contig names cannot contain \"%s\".", CONTIG_DELIMITER));
final Map<String, Integer> contigLengthMap = sequenceDictionary.getSequences().stream().filter(s -> s.getSequenceLength() >= minContigLength).collect(Collectors.toMap(SAMSequenceRecord::getSequenceName, SAMSequenceRecord::getSequenceLength, (c, l) -> {
throw new IllegalArgumentException(String.format("Duplicate contig in sequence dictionary: %s", c));
}, LinkedHashMap::new));
Utils.validateArg(contigLengthMap.size() > 0, "There must be at least one contig above the threshold length in the sequence dictionary.");
logger.info("Contigs above length threshold: " + contigLengthMap.toString());
//check that contigs in input files are present in sequence dictionary and that data points are valid given lengths
validateContigs(contigLengthMap);
//generate the plots
final List<String> contigNames = new ArrayList<>(contigLengthMap.keySet());
final List<Integer> contigLengths = new ArrayList<>(contigLengthMap.values());
writeSegmentedAlleleFractionPlot(sampleName, contigNames, contigLengths);
return "SUCCESS";
}
use of htsjdk.samtools.SAMSequenceRecord in project gatk by broadinstitute.
the class PlotSegmentedCopyRatio method doWork.
@Override
protected Object doWork() {
checkRegularReadableUserFiles();
//get sample name from input files (consistency check is performed)
final String sampleName = getSampleName();
//load contig names and lengths from the sequence dictionary into a LinkedHashMap
final SAMSequenceDictionary sequenceDictionary = ReferenceUtils.loadFastaDictionary(sequenceDictionaryFile);
Utils.validateArg(sequenceDictionary.getSequences().stream().map(SAMSequenceRecord::getSequenceName).noneMatch(n -> n.contains(CONTIG_DELIMITER)), String.format("Contig names cannot contain \"%s\".", CONTIG_DELIMITER));
final Map<String, Integer> contigLengthMap = sequenceDictionary.getSequences().stream().filter(s -> s.getSequenceLength() >= minContigLength).collect(Collectors.toMap(SAMSequenceRecord::getSequenceName, SAMSequenceRecord::getSequenceLength, (c, l) -> {
throw new IllegalArgumentException(String.format("Duplicate contig in sequence dictionary: %s", c));
}, LinkedHashMap::new));
Utils.validateArg(contigLengthMap.size() > 0, "There must be at least one contig above the threshold length in the sequence dictionary.");
logger.info("Contigs above length threshold: " + contigLengthMap.toString());
//check that contigs in input files are present in sequence dictionary and that data points are valid given lengths
validateContigs(contigLengthMap);
//generate the plots
final List<String> contigNames = new ArrayList<>(contigLengthMap.keySet());
final List<Integer> contigLengths = new ArrayList<>(contigLengthMap.values());
writeSegmentedCopyRatioPlots(sampleName, contigNames, contigLengths);
return "SUCCESS";
}
use of htsjdk.samtools.SAMSequenceRecord in project gatk by broadinstitute.
the class IntervalUtils method intervalIsOnDictionaryContig.
/**
* Determines whether the provided interval is within the bounds of its assigned contig according to the provided dictionary
*
* @param interval interval to check
* @param dictionary dictionary to use to validate contig bounds
* @return true if the interval's contig exists in the dictionary, and the interval is within its bounds, otherwise false
*/
public static boolean intervalIsOnDictionaryContig(final SimpleInterval interval, final SAMSequenceDictionary dictionary) {
Utils.nonNull(interval);
Utils.nonNull(dictionary);
final SAMSequenceRecord contigRecord = dictionary.getSequence(interval.getContig());
if (contigRecord == null) {
return false;
}
return interval.getEnd() <= contigRecord.getSequenceLength();
}
use of htsjdk.samtools.SAMSequenceRecord in project gatk by broadinstitute.
the class SequenceDictionaryUtils method commonContigsAreInSameRelativeOrder.
/**
* Returns true if the common contigs in dict1 and dict2 are in the same relative order, without regard to
* absolute index position. This is accomplished by getting the common contigs in both dictionaries, sorting
* these according to their indices, and then walking through the sorted list to ensure that each ordered contig
* is equivalent
*
* @param commonContigs names of the contigs common to both dictionaries
* @param dict1 first SAMSequenceDictionary
* @param dict2 second SAMSequenceDictionary
* @return true if the common contigs occur in the same relative order in both dict1 and dict2, otherwise false
*/
private static boolean commonContigsAreInSameRelativeOrder(Set<String> commonContigs, SAMSequenceDictionary dict1, SAMSequenceDictionary dict2) {
final List<SAMSequenceRecord> list1 = getSequencesOfName(commonContigs, dict1);
final List<SAMSequenceRecord> list2 = getSequencesOfName(commonContigs, dict2);
list1.sort(SEQUENCE_INDEX_ORDER);
list2.sort(SEQUENCE_INDEX_ORDER);
for (int i = 0; i < list1.size(); i++) {
SAMSequenceRecord elt1 = list1.get(i);
SAMSequenceRecord elt2 = list2.get(i);
if (!elt1.getSequenceName().equals(elt2.getSequenceName()))
return false;
}
return true;
}
use of htsjdk.samtools.SAMSequenceRecord in project gatk by broadinstitute.
the class SequenceDictionaryUtils method findDisequalCommonContigs.
/**
* Returns a List(x,y) that contains two disequal sequence records among the common contigs in both dicts. Returns
* null if all common contigs are equivalent
*
* @param commonContigs
* @param dict1
* @param dict2
* @return
*/
private static List<SAMSequenceRecord> findDisequalCommonContigs(Set<String> commonContigs, SAMSequenceDictionary dict1, SAMSequenceDictionary dict2) {
for (String name : commonContigs) {
SAMSequenceRecord elt1 = dict1.getSequence(name);
SAMSequenceRecord elt2 = dict2.getSequence(name);
if (!sequenceRecordsAreEquivalent(elt1, elt2))
return Arrays.asList(elt1, elt2);
}
return null;
}
Aggregations