本文整理汇总了Java中htsjdk.samtools.SAMSequenceDictionary.getSequence方法的典型用法代码示例。如果您正苦于以下问题:Java SAMSequenceDictionary.getSequence方法的具体用法?Java SAMSequenceDictionary.getSequence怎么用?Java SAMSequenceDictionary.getSequence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.samtools.SAMSequenceDictionary
的用法示例。
在下文中一共展示了SAMSequenceDictionary.getSequence方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addIntervalFeatureTrackFromVCF
import htsjdk.samtools.SAMSequenceDictionary; //导入方法依赖的package包/类
private void addIntervalFeatureTrackFromVCF(String sourceName, GenomicCoords gc, String trackTag) throws ClassNotFoundException, IOException, InvalidGenomicCoordsException, InvalidRecordException, SQLException {
int idForTrack= this.getNextTrackId();
// String trackId= new File(sourceName).getName() + "#" + idForTrack;
String trackId= sourceName + "#" + idForTrack;
// If this VCF file has sequence dictionary, check the coordinates in gc are compatible
// If they are not, throw an exception which force resetting the coords.
SAMSequenceDictionary seqDict = Utils.getVCFHeader(sourceName).getSequenceDictionary();
if(seqDict != null && seqDict.getSequence(gc.getChrom()) == null){
throw new InvalidGenomicCoordsException();
}
TrackIntervalFeature tif= new TrackIntervalFeature(sourceName, gc);
tif.setTrackTag(trackId);
this.trackList.add(tif);
}
示例2: createRandomIntervals
import htsjdk.samtools.SAMSequenceDictionary; //导入方法依赖的package包/类
private List<SimpleInterval> createRandomIntervals(final SAMSequenceDictionary referenceDictionary, final int numberOfIntervals, final int minIntervalSize, final int maxIntervalSize, final int meanIntervalSize, final double intervalSizeStdev) {
final List<SimpleInterval> result = new ArrayList<>(numberOfIntervals);
final int numberOfSequences = referenceDictionary.getSequences().size();
for (int i = 0; i < numberOfIntervals; i++) {
final SAMSequenceRecord contig = referenceDictionary.getSequence(RANDOM.nextInt(numberOfSequences));
final String contigName = contig.getSequenceName();
final int intervalSize = Math.min(maxIntervalSize, (int) Math.max(minIntervalSize, Math.round(RANDOM.nextDouble() * intervalSizeStdev + meanIntervalSize)));
final int intervalStart = 1 + RANDOM.nextInt(contig.getSequenceLength() - intervalSize);
final int intervalEnd = intervalStart + intervalSize - 1;
final SimpleInterval interval = new SimpleInterval(contigName, intervalStart, intervalEnd);
result.add(interval);
}
final Comparator<SimpleInterval> comparator =
Comparator.comparing(SimpleInterval::getContig,
(a, b) -> Integer.compare(
referenceDictionary.getSequenceIndex(a),
referenceDictionary.getSequenceIndex(b)))
.thenComparingInt(SimpleInterval::getStart)
.thenComparingInt(SimpleInterval::getEnd);
Collections.sort(result, comparator);
return result;
}
示例3: correctCoordsAgainstSeqDict
import htsjdk.samtools.SAMSequenceDictionary; //导入方法依赖的package包/类
public void correctCoordsAgainstSeqDict(SAMSequenceDictionary samSeqDict) throws InvalidGenomicCoordsException, IOException{
if(samSeqDict == null || samSeqDict.size() == 0){
// Just check start pos
if (this.from <=0 ){
this.from= 1;
}
return;
}
if(this.chrom == null){ // Nothing to do
return;
}
if(samSeqDict.getSequence(this.chrom) == null){ // Not found: Nullify everything
this.chrom= null;
this.from= null;
this.to= null;
return;
}
// Reset min coords
if( this.from != null && this.from < 1) {
this.from= 1;
}
// Reset max coords
if( this.from != null && this.from > samSeqDict.getSequence(this.chrom).getSequenceLength() ) {
this.from= samSeqDict.getSequence(this.chrom).getSequenceLength() - this.getGenomicWindowSize() + 1;
if(this.from <= 0){
this.from= 1;
}
this.to= this.from + this.getGenomicWindowSize() - 1;
if(this.to > samSeqDict.getSequence(this.chrom).getSequenceLength()){
this.to= samSeqDict.getSequence(this.chrom).getSequenceLength();
}
}
if( this.to != null && this.to > samSeqDict.getSequence(this.chrom).getSequenceLength() ) {
this.to= samSeqDict.getSequence(this.chrom).getSequenceLength();
}
}
示例4: intervalIsOnDictionaryContig
import htsjdk.samtools.SAMSequenceDictionary; //导入方法依赖的package包/类
/**
* 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();
}
示例5: supersets
import htsjdk.samtools.SAMSequenceDictionary; //导入方法依赖的package包/类
/**
* Utility function that tests whether dict1's set of contigs is a superset of dict2's
*
* @param dict1 first sequence dictionary
* @param dict2 second sequence dictionary
* @return true if dict1's set of contigs supersets dict2's
*/
private static boolean supersets( SAMSequenceDictionary dict1, SAMSequenceDictionary dict2 ) {
// Cannot rely on SAMSequenceRecord.equals() as it's too strict (takes extended attributes into account).
for ( final SAMSequenceRecord dict2Record : dict2.getSequences() ) {
final SAMSequenceRecord dict1Record = dict1.getSequence(dict2Record.getSequenceName());
if ( dict1Record == null || ! sequenceRecordsAreEquivalent(dict2Record, dict1Record) ) {
return false;
}
}
return true;
}
示例6: findDisequalCommonContigs
import htsjdk.samtools.SAMSequenceDictionary; //导入方法依赖的package包/类
/**
* 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;
}
示例7: commonContigsAreAtSameIndices
import htsjdk.samtools.SAMSequenceDictionary; //导入方法依赖的package包/类
/**
* Checks whether the common contigs in the given sequence dictionaries occur at the same indices
* in both dictionaries
*
* @param commonContigs Set of names of the contigs that occur in both dictionaries
* @param dict1 first sequence dictionary
* @param dict2 second sequence dictionary
* @return true if the contigs common to dict1 and dict2 occur at the same indices in both dictionaries,
* otherwise false
*/
private static boolean commonContigsAreAtSameIndices( final Set<String> commonContigs, final SAMSequenceDictionary dict1, final SAMSequenceDictionary dict2 ) {
for ( String commonContig : commonContigs ) {
SAMSequenceRecord dict1Record = dict1.getSequence(commonContig);
SAMSequenceRecord dict2Record = dict2.getSequence(commonContig);
// Each common contig must have the same index in both dictionaries
if ( dict1Record.getSequenceIndex() != dict2Record.getSequenceIndex() ) {
return false;
}
}
return true;
}
示例8: getReferenceSequenceDictionaryFromMap
import htsjdk.samtools.SAMSequenceDictionary; //导入方法依赖的package包/类
/**
* Given a reference map, get a SAMSequenceDictionary that lists its contigs and their length.
* Note that this does NOT use the referenceContig order from the API. Instead, we'll sort them
* and try to match the read sequence dictionary order, if given.
*
* @param referenceMap - return value from getReferenceNameToReferenceTable
* @param optReadSequenceDictionaryToMatch - (optional) the sequence dictionary of the reads, we'll match its order if possible.
* @return a SAMSequenceDictionary that lists the referenceset's contigs and their length.
*/
public SAMSequenceDictionary getReferenceSequenceDictionaryFromMap(final Map<String, Reference> referenceMap, final SAMSequenceDictionary optReadSequenceDictionaryToMatch) {
SAMSequenceDictionary refDictionary = new SAMSequenceDictionary();
ArrayList<SAMSequenceRecord> refContigs = new ArrayList<>();
for (Map.Entry<String, Reference> e : referenceMap.entrySet()) {
if (e.getKey()!=null && e.getValue().getLength()!=null) {
refContigs.add(new SAMSequenceRecord(e.getKey(), e.getValue().getLength().intValue()));
}
}
HashMap<String,Integer> indexBuilder = null;
if (null!=optReadSequenceDictionaryToMatch) {
indexBuilder = new LinkedHashMap<>();
for (int i=0; i<optReadSequenceDictionaryToMatch.size(); i++) {
final SAMSequenceRecord sequence = optReadSequenceDictionaryToMatch.getSequence(i);
indexBuilder.put(sequence.getSequenceName(), i);
}
}
final Map<String,Integer> optReadSequenceDictionaryToMatchIndex = indexBuilder;
// GATK requires human contigs in karyotypic order: 1, 2, ..., 10, 11, ..., 20, 21, 22, X, Y with M either leading or trailing these contigs.
// So we sort them.
Collections.sort(refContigs, new Comparator<SAMSequenceRecord>() {
@Override
public int compare(SAMSequenceRecord o1, SAMSequenceRecord o2) {
// if those are ordered in the readDictionary, then match that order
if (null != optReadSequenceDictionaryToMatchIndex) {
if (optReadSequenceDictionaryToMatchIndex.containsKey(o1.getSequenceName()) && optReadSequenceDictionaryToMatchIndex.containsKey(o2.getSequenceName())) {
return optReadSequenceDictionaryToMatchIndex.get(o1.getSequenceName()).compareTo(optReadSequenceDictionaryToMatchIndex.get(o2.getSequenceName()));
}
}
// otherwise, order them in karyotypic order.
int r1 = getRank(o1.getSequenceName());
int r2 = getRank(o2.getSequenceName());
if (r1 < r2) return -1;
if (r2 < r1) return 1;
return o1.getSequenceName().compareTo(o2.getSequenceName());
}
private int getRank(String name) {
if (name.equalsIgnoreCase("x")) return 23;
if (name.equalsIgnoreCase("y")) return 24;
if (name.equalsIgnoreCase("m")) return 25;
if (name.equalsIgnoreCase("mt")) return 25;
StringBuilder b = new StringBuilder();
for (char c : name.toCharArray()) {
if (Character.isDigit(c)) {
b.append(c);
}
}
String numsOnly = b.toString();
if (numsOnly.isEmpty()) return 0;
return Integer.parseInt(numsOnly);
}
});
for (SAMSequenceRecord s : refContigs) {
refDictionary.addSequence(s);
}
return refDictionary;
}
示例9: expandWithinContig
import htsjdk.samtools.SAMSequenceDictionary; //导入方法依赖的package包/类
/**
* Returns a new SimpleInterval that represents this interval as expanded by the specified amount in both
* directions, bounded by the contig start/stop if necessary.
*
* @param padding amount to expand this interval
* @param sequenceDictionary dictionary to use to determine the length of this interval's contig
* @return a new SimpleInterval that represents this interval as expanded by the specified amount in both
* directions, bounded by the contig start/stop if necessary.
*/
public SimpleInterval expandWithinContig( final int padding, final SAMSequenceDictionary sequenceDictionary ) {
Utils.nonNull(sequenceDictionary);
final SAMSequenceRecord contigRecord = sequenceDictionary.getSequence(contig);
Utils.nonNull( contigRecord, () -> "Contig " + contig + " not found in provided dictionary");
return expandWithinContig(padding, contigRecord.getSequenceLength());
}