本文整理汇总了Java中htsjdk.samtools.util.Interval.getStart方法的典型用法代码示例。如果您正苦于以下问题:Java Interval.getStart方法的具体用法?Java Interval.getStart怎么用?Java Interval.getStart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.samtools.util.Interval
的用法示例。
在下文中一共展示了Interval.getStart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: emitPerBaseCoverageIfRequested
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
/** Emits a file with per base coverage if an output file has been set. */
private void emitPerBaseCoverageIfRequested() {
if (this.perBaseOutput == null) return;
final PrintWriter out = new PrintWriter(IOUtil.openFileForBufferedWriting(this.perBaseOutput));
out.println("chrom\tpos\ttarget\tcoverage");
for (final Map.Entry<Interval,Coverage> entry : this.highQualityCoverageByTarget.entrySet()) {
final Interval interval = entry.getKey();
final String chrom = interval.getContig();
final int firstBase = interval.getStart();
final int[] cov = entry.getValue().getDepths();
for (int i = 0; i < cov.length; ++i) {
out.print(chrom);
out.print('\t');
out.print(firstBase + i);
out.print('\t');
out.print(interval.getName());
out.print('\t');
out.print(cov[i]);
out.println();
}
}
out.close();
}
示例2: design
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
@Override
List<Bait> design(final BaitDesigner designer, final Interval target, final ReferenceSequence reference) {
final List<Bait> baits = new LinkedList<Bait>();
final int baitSize = designer.BAIT_SIZE;
final int baitOffset = designer.BAIT_OFFSET;
final int lastPossibleBaitStart = Math.min(target.getEnd(), reference.length() - baitSize);
final int baitCount = 1 + (int) Math.floor((lastPossibleBaitStart - target.getStart()) / (double) baitOffset);
int i = 0;
for (int start = target.getStart(); start < lastPossibleBaitStart; start += baitOffset) {
final Bait bait = new Bait(target.getContig(),
start,
CoordMath.getEnd(start, baitSize),
target.isNegativeStrand(),
designer.makeBaitName(target.getName(), ++i, baitCount));
bait.addBases(reference, designer.DESIGN_ON_TARGET_STRAND);
baits.add(bait);
}
return baits;
}
示例3: reverseComplement
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
private static Allele reverseComplement(final Allele oldAllele, final Interval target, final ReferenceSequence referenceSequence, final boolean isBiAllelicIndel, final boolean addToStart){
if (oldAllele.isSymbolic() || oldAllele.isNoCall()) {
return oldAllele;
}
else if (isBiAllelicIndel) {
// target.getStart is 1-based, reference bases are 0-based
final StringBuilder alleleBuilder = new StringBuilder(target.getEnd() - target.getStart() + 1);
if (addToStart) {
alleleBuilder.append((char) referenceSequence.getBases()[target.getStart() - 2]);
}
alleleBuilder.append(SequenceUtil.reverseComplement(oldAllele.getBaseString().substring(1, oldAllele.length())));
if (!addToStart) {
alleleBuilder.append((char) referenceSequence.getBases()[target.getEnd() - 1]);
}
return Allele.create(alleleBuilder.toString(), oldAllele.isReference());
} else {
return Allele.create(SequenceUtil.reverseComplement(oldAllele.getBaseString()), oldAllele.isReference());
}
}
示例4: convertSimpleIntervalToQueryInterval
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
/**
* Converts an interval in SimpleInterval format into an htsjdk QueryInterval.
*
* In doing so, a header lookup is performed to convert from contig name to index
*
* @param interval interval to convert
* @param sequenceDictionary sequence dictionary used to perform the conversion
* @return an equivalent interval in QueryInterval format
*/
private static QueryInterval convertSimpleIntervalToQueryInterval( final Interval interval, final SAMSequenceDictionary sequenceDictionary ) {
if (interval == null) {
throw new IllegalArgumentException("interval may not be null");
}
if (sequenceDictionary == null) {
throw new IllegalArgumentException("sequence dictionary may not be null");
}
final int contigIndex = sequenceDictionary.getSequenceIndex(interval.getContig());
if ( contigIndex == -1 ) {
throw new IllegalArgumentException("Contig " + interval.getContig() + " not present in reads sequence " +
"dictionary");
}
return new QueryInterval(contigIndex, interval.getStart(), interval.getEnd());
}
示例5: getSortKey
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
private KeySorter getSortKey() {
if(_sortKey==null) {
final Function<String,String> normalize=C->C.startsWith("chr")?C.substring(3):C;
final Interval rgn = getInterval() ;
_sortKey = new KeySorter();
_sortKey.st = this.ctx.getStructuralVariantType();
_sortKey.contig1 = normalize.apply(rgn.getContig());
if(_sortKey.st.equals(StructuralVariantType.BND)) {
_sortKey.contig2 = normalize.apply(LumpyConstants.getBnDContig(this.ctx.getAlternateAllele(0).getDisplayString()));
}
else
{
_sortKey.contig2 = _sortKey.contig1;
}
_sortKey.start = rgn.getStart();
_sortKey.end = rgn.getEnd();
_sortKey.id=this.id;
}
return _sortKey;
}
示例6: isInPseudoAutosomalRegion
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
/**
* Tests whether the variant is within one of the pseudo-autosomal regions
*/
private boolean isInPseudoAutosomalRegion(final String chr, final int pos) {
for (final Interval par : parIntervals) {
if (par.getContig().equals(chr) && pos >= par.getStart() && pos <= par.getEnd()) return true;
}
return false;
}
示例7: reverseComplementVariantContext
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
protected static VariantContextBuilder reverseComplementVariantContext(final VariantContext source, final Interval target, final ReferenceSequence refSeq){
if (target.isPositiveStrand()) {
throw new IllegalArgumentException("This should only be called for negative strand liftovers");
}
// not currently supported
if (source.isIndel() && !source.isBiallelic()) {
return null;
}
final List<Allele> origAlleles = new ArrayList<>(source.getAlleles());
final VariantContextBuilder vcb = new VariantContextBuilder(source);
vcb.chr(target.getContig());
// By convention, indels are left aligned and include the base prior to that indel.
// When reverse complementing, will be necessary to include this additional base.
// This check prevents the presumably rare situation in which the indel occurs on the first position of the sequence
final boolean addToStart = source.isIndel() && target.getStart() > 1;
final int start = target.getStart() - (addToStart ? 1 : 0);
vcb.start(start);
final int stop = target.getEnd() - (addToStart ? 1 : 0);
vcb.stop(stop);
vcb.alleles(reverseComplementAlleles(origAlleles, target, refSeq, source.isIndel(), addToStart));
if (source.isIndel()) {
// check that the reverse complemented bases match the new reference
if (!referenceAlleleMatchesReferenceForIndel(vcb.getAlleles(), refSeq, start, stop)) {
return null;
}
leftAlignVariant(vcb, start, stop, vcb.getAlleles(), refSeq);
}
vcb.genotypes(fixGenotypes(source.getGenotypes(), origAlleles, vcb.getAlleles()));
return vcb;
}
示例8: lookupIntervalContainingLocus
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
private static Interval lookupIntervalContainingLocus(final IntervalList source, final String chromosome, final int startIndex) {
for (final Interval interval : source) {
if (interval.getContig().equals(chromosome) && startIndex >= interval.getStart() && startIndex <= interval.getEnd()) {
return interval;
}
}
throw new NoSuchElementException();
}
示例9: generateBins
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
private static IntervalList generateBins(final IntervalList preparedIntervalList, final int binLength, final SAMSequenceDictionary sequenceDictionary) {
if (binLength == 0) {
return IntervalList.copyOf(preparedIntervalList);
}
final IntervalList bins = new IntervalList(sequenceDictionary);
for (final Interval interval : preparedIntervalList) {
for (int binStart = interval.getStart(); binStart <= interval.getEnd(); binStart += binLength) {
final int binEnd = FastMath.min(binStart + binLength - 1, interval.getEnd());
bins.add(new Interval(interval.getContig(), binStart, binEnd));
}
}
return bins;
}
示例10: compare
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
@Override
public int compare(final Interval o1, final Interval o2) {
int i = o1.getName().compareTo(o2.getName());
if(i!=0) return i;
if(!o1.getContig().equals(o2.getContig())) {
throw new IllegalStateException("not same contig???");
}
i =o1.getStart() - o2.getStart();
if(i!=0) return i;
return o1.getEnd() - o2.getEnd();
}
示例11: trimInterval
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
private Interval trimInterval(final Interval interval) {
if(interval.length()<=this.max_interval_length) return interval;
final Interval interval2 = new Interval(
interval.getContig(),
interval.getStart(),
interval.getStart()+this.max_interval_length-1
);
LOG.debug("trim interval "+interval+" to "+interval2);
return interval2;
}
示例12: performLiftOver
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
private static List<GenomeRange> performLiftOver(List<GenomeRange> inRange) {
List<GenomeRange> toReturn = new ArrayList<>();
LiftOver liftOverTool = new LiftOver(new File(ARGS.liftOverChainPath));
int all = inRange.size();
int current = 0;
int currentMarker = 1;
for (GenomeRange currRange : inRange) {
int oneBasedClosedStart = (int) currRange.getStart() + 1;
int oneBasedClosedEnd = (int) currRange.getEnd();
if ((long) oneBasedClosedStart != currRange.getStart() + 1
|| (long) oneBasedClosedEnd != currRange.getEnd()) {
throw new IllegalArgumentException("performLiftOver: cannot specify ranges which are "
+ "greater than Integer.MAX_VALUE");
}
// These intervals are 1-based, close ended
final Interval currInterval = new Interval(currRange.getChromosome(), oneBasedClosedStart,
oneBasedClosedEnd, !currRange.isPositiveStrand(), currRange.getName());
Interval liftedInterval = liftOverTool.liftOver(currInterval, ARGS.minMatch);
if (liftedInterval == null) {
warn("failed to liftover an interval");
} else {
// Change from one based to 0 based
GenomeRange toAdd = new GenomeRange(liftedInterval.getSequence(),
liftedInterval.getStart() - 1, liftedInterval.getEnd(), liftedInterval.getName(),
liftedInterval.isPositiveStrand());
toReturn.add(toAdd);
}
if ((100 * current++) / all > currentMarker) {
logger.log(Level.INFO, String.format("performing liftover: at %d%%", currentMarker++));
}
}
return toReturn;
}
示例13: intervalFileToList
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
/**
* Read a file of genome locations to process. The file may be in Picard
* or GATK interval format.
*
* @param glParser GenomeLocParser
* @param fileName interval file
* @return List<GenomeLoc> List of Genome Locs that have been parsed from file
*/
public static List<GenomeLoc> intervalFileToList(final GenomeLocParser glParser, final String fileName) {
Utils.nonNull(glParser, "glParser is null");
Utils.nonNull(fileName, "file name is null");
final Path inputPath = IOUtils.getPath(fileName);
final List<GenomeLoc> ret = new ArrayList<>();
/**
* First try to read the file as a Picard interval file since that's well structured --
* we'll fail quickly if it's not a valid file.
*/
boolean isPicardInterval = false;
try {
// Note: Picard will skip over intervals with contigs not in the sequence dictionary
final IntervalList il = IntervalList.fromPath(inputPath);
isPicardInterval = true;
for (final Interval interval : il.getIntervals()) {
// The current Agilent exome interval list is off-by-one on all end positions. Until this is fixed we
// need to tolerate intervals where the end is one before the start. We should remove this once a
// corrected version of the interval list is released. This is tracked in:
// https://github.com/broadinstitute/gatk/issues/2089
if (interval.getStart() - interval.getEnd() == 1 ) {
logger.warn("Ignoring possibly incorrectly converted length 1 interval : " + interval);
}
else if ( glParser.isValidGenomeLoc(interval.getContig(), interval.getStart(), interval.getEnd(), true)) {
ret.add(glParser.createGenomeLoc(interval.getContig(), interval.getStart(), interval.getEnd(), true));
} else {
throw new UserException(inputPath.toUri() + " has an invalid interval : " + interval) ;
}
}
}
// if that didn't work, try parsing file as a GATK interval file
catch (final Exception e) {
if ( isPicardInterval ) // definitely a picard file, but we failed to parse
{
throw new UserException.CouldNotReadInputFile(inputPath, e);
} else {
try (PathLineIterator reader = new PathLineIterator(inputPath)) {
for (final String line : reader) {
if (!line.trim().isEmpty()) {
ret.add(glParser.parseGenomeLoc(line));
}
}
}
}
}
if ( ret.isEmpty() ) {
throw new UserException.MalformedFile(inputPath, "It contains no intervals.");
}
return ret;
}
示例14: IntervalSplit
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
IntervalSplit(final Interval interval) {this.interval=interval;
if(interval.getStart()>=interval.getEnd()) throw new IllegalArgumentException(interval.toString());
}
示例15: doWork
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
@Override
public int doWork(final List<String> args) {
if(StringUtil.isBlank(this.regionStr))
{
LOG.error("Undefined interval.");
return -1;
}
final IntervalParser intervalParser =new IntervalParser().setFixContigName(true);
PrintWriter out=null;
SamReader samReader=null;
SAMRecordIterator iter=null;
try {
out = super.openFileOrStdoutAsPrintWriter(outputFile);
for(final String inputName: IOUtils.unrollFiles(args)) {
samReader = openSamReader(inputName);
final Interval interval = intervalParser.
setDictionary(samReader.getFileHeader().getSequenceDictionary()).
parse(this.regionStr);
if(interval==null)
{
LOG.error("Bad interval "+this.regionStr);
return -1;
}
iter=samReader.query(
interval.getContig(),
interval.getStart(),
interval.getEnd(),
false);
while(iter.hasNext())
{
final SAMRecord rec=iter.next();
if(rec.getReadUnmappedFlag()) continue;
if(this.SamRecordFilter.filterOut(rec)) continue;
final Cigar cigar =rec.getCigar();
if(cigar==null || cigar.isEmpty()) continue;
if(!rec.getReferenceName().equals(interval.getContig())) continue;
if(this.readEnd.apply(rec) < interval.getStart() ) continue;
if(this.readStart.apply(rec) > interval.getEnd() ) continue;
printRead(out,rec,interval);
}
iter.close();
iter=null;
samReader.close();
samReader=null;
}
out.flush();
out.close();out=null;
return 0;
}
catch (final Exception err) {
LOG.error(err);
return -1;
}
finally
{
CloserUtil.close(iter);
CloserUtil.close(samReader);
CloserUtil.close(out);
}
}