本文整理汇总了Java中htsjdk.samtools.SAMRecordIterator.close方法的典型用法代码示例。如果您正苦于以下问题:Java SAMRecordIterator.close方法的具体用法?Java SAMRecordIterator.close怎么用?Java SAMRecordIterator.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.samtools.SAMRecordIterator
的用法示例。
在下文中一共展示了SAMRecordIterator.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryNameSortedBAM
import htsjdk.samtools.SAMRecordIterator; //导入方法依赖的package包/类
private static File queryNameSortedBAM(final SamReader reader, final QueryInterval[] intervals, final String name) throws IOException {
final SAMFileHeader header = reader.getFileHeader().clone();
header.setSortOrder(SAMFileHeader.SortOrder.queryname);
final File file = File.createTempFile(name, ".bam");
final SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(header, false, file);
final SAMRecordIterator iterator = reader.queryOverlapping(intervals);
while (iterator.hasNext()) {
writer.addAlignment(iterator.next());
}
iterator.close();
writer.close();
return file;
}
示例2: countJunctions
import htsjdk.samtools.SAMRecordIterator; //导入方法依赖的package包/类
/**
* Given a SamReader, find all reads within a region (ref:start-end) that span a splice junction and tally the number of times
* each junction is spanned. Optionally tally the average values of "tallyTagName" tags (eg. NM).
*
* @param reader
* @param ref
* @param start
* @param end
* @param orient
* @param minOverlap
* @param tallyTagName
* @param separateReadCounts
* @return
*/
public static SortedMap<GenomeSpan, MappedReadCounter> countJunctions(SamReader reader, String ref, int start, int end, Orientation orient, int minOverlap, String tallyTagName) {
SAMRecordIterator it = reader.query(ref, start, end, true);
SortedMap<GenomeSpan, MappedReadCounter> counters = new TreeMap<GenomeSpan, MappedReadCounter>();
while (it.hasNext()) {
SAMRecord read = it.next();
if (read.isSecondaryOrSupplementary() || read.getDuplicateReadFlag() || read.getNotPrimaryAlignmentFlag() || read.getReadUnmappedFlag() || read.getSupplementaryAlignmentFlag()) {
// skip all secondary / duplicate / unmapped reads
continue;
}
if (isJunctionSpanning(read)) {
for (GenomeSpan junction: getJunctionsForRead(read, orient, minOverlap)) {
if (!counters.containsKey(junction)) {
counters.put(junction, new MappedReadCounter(tallyTagName));
}
counters.get(junction).addRead(read);
}
}
}
it.close();
return counters;
}
示例3: scan
import htsjdk.samtools.SAMRecordIterator; //导入方法依赖的package包/类
private void scan(final SamReader in)
{
final SAMSequenceDictionary dict=in.getFileHeader().getSequenceDictionary();
if(dict==null) throw new RuntimeException("Sequence dictionary missing...");
final SAMRecordIterator iter=in.iterator();
final SAMSequenceDictionaryProgress progress=new SAMSequenceDictionaryProgress(dict);
while(iter.hasNext() && !this.out.checkError())
{
final SAMRecord rec=progress.watch(iter.next());
if(rec.getReadUnmappedFlag()) continue;
for(final PslAlign a:makePslAlign(rec,dict))
{
out.println(toString(a,rec));
}
}
progress.finish();
iter.close();
}
示例4: scan
import htsjdk.samtools.SAMRecordIterator; //导入方法依赖的package包/类
private void scan(final SamReader in) throws IOException
{
SAMRecordIterator iter=in.iterator();
while(iter.hasNext())
{
final SAMRecord rec = iter.next();
String sampleName= this.partition.getPartion(rec);
if(sampleName==null || sampleName.isEmpty()) sampleName="__UNDEFINED_"+this.partition.name().toUpperCase()+"_";
Counter<Integer> counter = this.lengths.get(sampleName);
if(counter==null) {
counter = new Counter<>();
this.lengths.put(sampleName,counter);
}
final int len = rec.getReadLength();
counter.incr(len);
this.max_length=Math.max(max_length, len);
}
iter.close();
}
示例5: writeToSlice
import htsjdk.samtools.SAMRecordIterator; //导入方法依赖的package包/类
private static void writeToSlice(final String path, final SamReader reader, final QueryInterval[] intervals) {
final File outputBAM = new File(path);
final SAMFileWriter writer = new SAMFileWriterFactory().makeBAMWriter(reader.getFileHeader(), true, outputBAM);
final SAMRecordIterator iterator = reader.queryOverlapping(intervals);
while (iterator.hasNext()) {
writer.addAlignment(iterator.next());
}
iterator.close();
writer.close();
}
示例6: mergeVariants
import htsjdk.samtools.SAMRecordIterator; //导入方法依赖的package包/类
@NotNull
public List<VariantContext> mergeVariants(@NotNull final PotentialMNVRegion potentialMnvRegion) {
if (potentialMnvRegion.potentialMnvs().size() == 0) {
return potentialMnvRegion.variants();
} else {
final SAMRecordIterator samIterator = queryBam(potentialMnvRegion);
final MNVRegionValidator regionValidator = validateMNVs(samIterator, potentialMnvRegion);
samIterator.close();
return outputVariants(regionValidator);
}
}
示例7: getSamReadLength
import htsjdk.samtools.SAMRecordIterator; //导入方法依赖的package包/类
public static int getSamReadLength(SamReader reader, int recordsToScan) {
int i = 0;
int size = 0;
SAMRecordIterator it = reader.iterator();
while (it.hasNext() && i < recordsToScan) {
SAMRecord read = it.next();
size = Math.max(size, read.getReadLength());
i++;
}
it.close();
return size;
}
示例8: findOverlappingReads
import htsjdk.samtools.SAMRecordIterator; //导入方法依赖的package包/类
/**
* Find reads that overlap a given genomic region
* @param reader
* @param pos
* @param orient
* @param readLength
* @param minOverlap
* @param allowGaps
* @return
*/
public static List<SAMRecord> findOverlappingReads(SamReader reader, GenomeSpan pos, Orientation orient, int readLength, int minOverlap, boolean allowGaps) {
List<SAMRecord> out = new ArrayList<SAMRecord>();
SAMRecordIterator it = reader.query(pos.ref, pos.start - readLength + minOverlap, pos.start + readLength - minOverlap, true);
while (it.hasNext()) {
SAMRecord read = it.next();
if (read.isSecondaryOrSupplementary() || read.getDuplicateReadFlag() || read.getNotPrimaryAlignmentFlag() || read.getReadUnmappedFlag() || read.getSupplementaryAlignmentFlag()) {
// skip all secondary / duplicate / unmapped reads
continue;
}
if (!allowGaps) {
// skip all reads with gaps
for (CigarElement el: read.getCigar().getCigarElements()) {
if (el.getOperator() == CigarOperator.N) {
continue;
}
}
}
if (ReadUtils.getFragmentEffectiveStrand(read, orient) != pos.strand) {
continue;
}
for (GenomeSpan region: ReadUtils.getJunctionFlankingRegions(read, orient, minOverlap)) {
if (region.start <= (pos.start - minOverlap) && region.end >= (pos.start + minOverlap)) {
out.add(read);
break;
}
}
}
it.close();
return out;
}
示例9: writeReads
import htsjdk.samtools.SAMRecordIterator; //导入方法依赖的package包/类
/**
* Helper function that writes reads from iterator it into writer out, updating each SAMRecord along the way
* according to the newOrder mapping from dictionary index -> index. Name is used for printing only.
*/
private void writeReads(final SAMFileWriter out,
final SAMRecordIterator it,
final Map<Integer, Integer> newOrder,
final String name) {
long counter = 0;
log.info(" Processing " + name);
while (it.hasNext()) {
counter++;
final SAMRecord read = it.next();
final int oldRefIndex = read.getReferenceIndex();
final int oldMateIndex = read.getMateReferenceIndex();
final int newRefIndex = newOrderIndex(read, oldRefIndex, newOrder);
read.setHeader(out.getFileHeader());
read.setReferenceIndex(newRefIndex);
final int newMateIndex = newOrderIndex(read, oldMateIndex, newOrder);
if (oldMateIndex != -1 && newMateIndex == -1) { // becoming unmapped
read.setMateAlignmentStart(0);
read.setMateUnmappedFlag(true);
read.setAttribute(SAMTag.MC.name(), null); // Set the Mate Cigar String to null
}
read.setMateReferenceIndex(newMateIndex);
out.addAlignment(read);
}
it.close();
log.info("Wrote " + counter + " reads");
}
示例10: getHeaderFromBAMFile
import htsjdk.samtools.SAMRecordIterator; //导入方法依赖的package包/类
public static HeaderInfo getHeaderFromBAMFile(Storage.Objects storage, String BAMPath, Iterable<Contig> explicitlyRequestedContigs) throws IOException {
HeaderInfo result = null;
// Open and read start of BAM
LOG.info("Reading header from " + BAMPath);
final SamReader samReader = BAMIO
.openBAM(storage, BAMPath, ValidationStringency.DEFAULT_STRINGENCY);
final SAMFileHeader header = samReader.getFileHeader();
Contig firstContig = getFirstExplicitContigOrNull(header, explicitlyRequestedContigs);
if (firstContig == null) {
final SAMSequenceRecord seqRecord = header.getSequence(0);
firstContig = new Contig(seqRecord.getSequenceName(), -1, -1);
}
LOG.info("Reading first chunk of reads from " + BAMPath);
final SAMRecordIterator recordIterator = samReader.query(
firstContig.referenceName, (int)firstContig.start + 1, (int)firstContig.end + 1, false);
Contig firstShard = null;
while (recordIterator.hasNext() && result == null) {
SAMRecord record = recordIterator.next();
final int alignmentStart = record.getAlignmentStart();
if (firstShard == null && alignmentStart > firstContig.start &&
(alignmentStart < firstContig.end || firstContig.end == -1)) {
firstShard = new Contig(firstContig.referenceName, alignmentStart, alignmentStart);
LOG.info("Determined first shard to be " + firstShard);
result = new HeaderInfo(header, firstShard);
}
}
recordIterator.close();
samReader.close();
if (result == null) {
throw new IOException("Did not find reads for the first contig " + firstContig.toString());
}
LOG.info("Finished header reading from " + BAMPath);
return result;
}
示例11: call
import htsjdk.samtools.SAMRecordIterator; //导入方法依赖的package包/类
private int call(final String inputName) throws Exception {
PrintWriter out=null;
SamReader sfr=null;
final SamJsonWriterFactory factory =SamJsonWriterFactory.newInstance().
printHeader(this.print_header).
printReadName(!this.disable_readName).
printAttributes(!this.disable_atts).
expandFlag(this.expflag).
expandCigar(this.excigar)
;
SAMFileWriter swf=null;
try
{
sfr = super.openSamReader(inputName);
out = super.openFileOrStdoutAsPrintWriter(this.output);
swf = factory.open(sfr.getFileHeader(), out);
final SAMRecordIterator iter=sfr.iterator();
while(iter.hasNext() && !out.checkError())
{
swf.addAlignment(iter.next());
}
iter.close();
out.flush();
swf.close();swf=null;
LOG.info("done");
return 0;
}
catch(final Exception err) {
LOG.error(err);
return -1;
}
finally {
CloserUtil.close(sfr);
CloserUtil.close(swf);
}
}
示例12: fetchDP
import htsjdk.samtools.SAMRecordIterator; //导入方法依赖的package包/类
/** return DP at given position */
private int fetchDP(final VariantContext ctx,final String sample,List<SamReader> samReaders)
{
int depth=0;
if(samReaders==null) samReaders=Collections.emptyList();
for(final SamReader sr: samReaders)
{
final SAMRecordIterator iter=sr.query(ctx.getContig(), ctx.getStart(), ctx.getEnd(), false);
while(iter.hasNext())
{
final SAMRecord rec=iter.next();
if(rec.getReadUnmappedFlag()) continue;
if(filter.filterOut(rec)) continue;
final SAMReadGroupRecord rg=rec.getReadGroup();
if(!sample.equals(rg.getSample())) continue;
final Cigar cigar=rec.getCigar();
if(cigar==null) continue;
int refPos=rec.getAlignmentStart();
for(final CigarElement ce:cigar.getCigarElements())
{
if( refPos > ctx.getEnd() ) break;
if(!ce.getOperator().consumesReferenceBases()) continue;
if( ce.getOperator().consumesReadBases())
{
for(int n=0;n< ce.getLength();++n )
{
if( refPos+n < ctx.getStart() ) continue;
if( refPos+n > ctx.getEnd()) break;
depth++;
}
}
refPos+= ce.getLength();
}
}
iter.close();
}
depth /= ( 1 + ctx.getEnd() - ctx.getStart() );
return depth;
}
示例13: scan
import htsjdk.samtools.SAMRecordIterator; //导入方法依赖的package包/类
private void scan(final SamReader r) {
final SAMRecordIterator iter=r.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;
if(!this.interval.getContig().equals(rec.getReferenceName())) continue;
if(super.readRight.apply(rec) < this.interval.getStart())
{
continue;
}
if(super.readLeft.apply(rec) > this.interval.getEnd()) {
break;
}
final String group=this.groupBy.apply(rec.getReadGroup());
if(group==null) continue;
PartitionImage partition = this.key2partition.get(group);
if( partition == null)
{
partition=new PartitionImage(group);
this.key2partition.put(group,partition);
}
partition.add(rec);
}
iter.close();
}
示例14: scan
import htsjdk.samtools.SAMRecordIterator; //导入方法依赖的package包/类
private void scan(SamReader in)
{
SAMSequenceDictionary dict=in.getFileHeader().getSequenceDictionary();
if(dict==null) throw new RuntimeException("Sequence dictionary missing");
SAMRecordIterator iter=in.iterator();
SAMSequenceDictionaryProgress progress=new SAMSequenceDictionaryProgress(dict);
while(iter.hasNext())
{
final SAMRecord rec=iter.next();
if(rec.getReadUnmappedFlag()) continue;
if(rec.isSecondaryOrSupplementary()) continue;
progress.watch(rec);
if(isWeird(rec,dict))
{
this.weird.addAlignment(rec);
continue;
}
for(CigarElement ce:rec.getCigar().getCigarElements())
{
if(ce.getOperator().equals(CigarOperator.N))
{
scanRead(rec,dict);
break;
}
}
}
iter.close();
progress.finish();
}
示例15: scanFile
import htsjdk.samtools.SAMRecordIterator; //导入方法依赖的package包/类
private void scanFile(SamReader r) {
final SAMSequenceDictionaryProgress progess= new SAMSequenceDictionaryProgress(r.getFileHeader());
final SAMRecordIterator iter = r.iterator();
while(iter.hasNext())
{
analyseSamRecord(progess.watch(iter.next()));
}
progess.finish();
iter.close();
}