本文整理汇总了Java中htsjdk.samtools.util.Interval.getEnd方法的典型用法代码示例。如果您正苦于以下问题:Java Interval.getEnd方法的具体用法?Java Interval.getEnd怎么用?Java Interval.getEnd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.samtools.util.Interval
的用法示例。
在下文中一共展示了Interval.getEnd方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
}
示例2: 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());
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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();
}
示例7: 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;
}
示例8: 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();
}
示例9: extendInterval
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
private Interval extendInterval(final Interval i1) {
if(this.extentd<=0) return i1;
return new Interval(i1.getContig(),
Math.max(i1.getStart()-this.extentd,0),
i1.getEnd()+this.extentd
);
}
示例10: 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;
}
示例11: 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;
}
示例12: IntervalSplit
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
IntervalSplit(final Interval interval) {this.interval=interval;
if(interval.getStart()>=interval.getEnd()) throw new IllegalArgumentException(interval.toString());
}
示例13: 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);
}
}
示例14: readBedFile
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
private Map<String, List<Interval>> readBedFile(final File bedFile) throws IOException
{
final Map<String, List<Interval>> gene2interval=new TreeMap<String, List<Interval>>();
BufferedReader bedIn=null;
try
{
bedIn=IOUtils.openFileForBufferedReading(bedFile);
final BedLineCodec codec = new BedLineCodec();
String line=null;
while((line=bedIn.readLine())!=null)
{
if(line.isEmpty() || line.startsWith("#")) continue;
final BedLine bedLine = codec.decode(line);
if(bedLine==null) continue;
if(bedLine.getColumnCount()<4)
{
throw new IOException("bad bed line in "+line+" "+bedFile);
}
final String chrom = bedLine.getContig();
final int chromStart1= bedLine.getStart();
final int chromEnd1= bedLine.getEnd();
final String gene = bedLine.get(3);
if(gene.isEmpty()) throw new IOException("bad bed gene in "+line+" "+bedFile);
List<Interval> intervals = gene2interval.get(gene);
if(intervals==null)
{
intervals=new ArrayList<>();
gene2interval.put(gene,intervals);
}
else if(!intervals.get(0).getContig().equals(chrom))
{
throw new IOException("more than one chromosome for gene:"+gene);
}
else
{
for(final Interval interval:intervals)
{
if(interval.getEnd()<chromStart1) continue;
if(interval.getStart()>chromEnd1) continue;
throw new IOException("overlapping region: "+line+" and "+interval);
}
}
intervals.add(new Interval(chrom, chromStart1, chromEnd1));
}
bedIn.close();
return gene2interval;
}
finally
{
CloserUtil.close(bedIn);
}
}