当前位置: 首页>>代码示例>>Java>>正文


Java SamReader.iterator方法代码示例

本文整理汇总了Java中htsjdk.samtools.SamReader.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java SamReader.iterator方法的具体用法?Java SamReader.iterator怎么用?Java SamReader.iterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在htsjdk.samtools.SamReader的用法示例。


在下文中一共展示了SamReader.iterator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
public static void main(String args[]) throws IOException, ParseException {
      Options options = new Options();
      options.addOption("u","uniquehits",false,"only output hits with a single mapping");
      options.addOption("s","nosuboptimal",false,"do not include hits whose score is not equal to the best score for the read");
      options.addOption("p","pairedend",false,"output paired-end hits");
      options.addOption("j","junctions",false,"output junction mapping reads (reads with gaps)");
      CommandLineParser parser = new GnuParser();
      CommandLine cl = parser.parse( options, args, false );            
  	uniqueOnly = cl.hasOption("uniquehits");
  	filterSubOpt = cl.hasOption("nosuboptimal");
  	inclPairedEnd = cl.hasOption("pairedend");
  	inclJunction = cl.hasOption("junctions");
  	SamReaderFactory factory =
          SamReaderFactory.makeDefault()
              .enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS)
              .validationStringency(ValidationStringency.SILENT);
SamReader reader = factory.open(SamInputResource.of(System.in));
      CloseableIterator<SAMRecord> iter = reader.iterator();
      while (iter.hasNext()) {
          SAMRecord record = iter.next();
          if (record.getReadUnmappedFlag()) {continue; }
          processRecord(record);
      }
      iter.close();
      reader.close();
  }
 
开发者ID:seqcode,项目名称:seqcode-core,代码行数:27,代码来源:TophatSAMToReadDB.java

示例2: convertFileAndVerifyRecordCount

import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
private void convertFileAndVerifyRecordCount(final int expectedCount,
                   final String fastqFilename1,
                   final String fastqFilename2,
                   final FastqQualityFormat version,
                   final boolean permissiveFormat,
                   final boolean useSequentialFastqs) throws IOException {
    final File samFile = convertFile(fastqFilename1, fastqFilename2, version, permissiveFormat, useSequentialFastqs);
    final SamReader samReader = SamReaderFactory.makeDefault().open(samFile);
    final SAMRecordIterator iterator = samReader.iterator();
    int actualCount = 0;
    while (iterator.hasNext()) {
        iterator.next();
        actualCount++;
    }
    samReader.close();
    Assert.assertEquals(actualCount, expectedCount);
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:18,代码来源:FastqToSamTest.java

示例3: openFile

import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
void openFile() throws IOException {
  LOG.info("Processing shard " + shard);
  final SamReader reader = BAMIO.openBAM(storageClient, shard.file,
      options.getStringency());
  iterator = null;
  if (reader.hasIndex() && reader.indexing() != null) {
    if (filter == Filter.UNMAPPED_ONLY) {
      LOG.info("Processing unmapped");
      iterator = reader.queryUnmapped();
    } else if (shard.span != null) {
      LOG.info("Processing span for " + shard.contig);
      iterator = reader.indexing().iterator(shard.span);
    } else if (shard.contig.referenceName != null && !shard.contig.referenceName.isEmpty()) {
      LOG.info("Processing all bases for " + shard.contig);
      iterator = reader.query(shard.contig.referenceName, (int) shard.contig.start,
          (int) shard.contig.end, false);
    }
  }
  if (iterator == null) {
    LOG.info("Processing all reads");
    iterator = reader.iterator();
  }
}
 
开发者ID:googlegenomics,项目名称:dataflow-java,代码行数:24,代码来源:Reader.java

示例4: SAMStats

import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
public SAMStats(boolean bowtie1, boolean bowtie2){
this.bowtie1 = bowtie1;
this.bowtie2 = bowtie2;
histo = new RealValuedHistogram(0, 1000, 100);
SamReaderFactory factory =
          SamReaderFactory.makeDefault()
              .enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS)
              .validationStringency(ValidationStringency.SILENT);
SamReader reader = factory.open(SamInputResource.of(System.in));
CloseableIterator<SAMRecord> iter = reader.iterator();
      while (iter.hasNext()) {
          SAMRecord record = iter.next();
          if(readLen==-1)
          	readLen = record.getReadLength();
          if(bowtie1)
          	processBT1SAMRecord(record);
          else if(bowtie2)
          	processBT2SAMRecord(record);
          else
          	processSAMRecord(record);
      }
      iter.close();
      try {
	reader.close();
} catch (IOException e) {
	e.printStackTrace();
}        
  }
 
开发者ID:seqcode,项目名称:seqcode-core,代码行数:29,代码来源:SAMStats.java

示例5: main

import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
public static void main(String args[]) throws IOException, ParseException {
      Options options = new Options();
      options.addOption("l","left",true,"filename of left side of read");
      options.addOption("r","right",true,"filename of right side of read");
      options.addOption("u","uniquehits",false,"only output hits with a single mapping");
      options.addOption("s","nosuboptimal",false,"do not include hits whose score is not equal to the best score for the read");
      options.addOption("D","debug",false,"enable debugging spew?");
      CommandLineParser parser = new GnuParser();
      CommandLine cl = parser.parse( options, args, false );            
  	uniqueOnly = cl.hasOption("uniquehits");
  	filterSubOpt = cl.hasOption("nosuboptimal");
      debug = cl.hasOption("debug");
      String leftfile = cl.getOptionValue("left");
      String rightfile = cl.getOptionValue("right");
      SamReaderFactory factory =
          SamReaderFactory.makeDefault()
              .enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS)
              .validationStringency(ValidationStringency.SILENT);
SamReader leftreader = factory.open(SamInputResource.of(new FileInputStream(leftfile)));
SamReader rightreader = factory.open(SamInputResource.of(new FileInputStream(rightfile)));
      leftiter = leftreader.iterator();
      rightiter = rightreader.iterator();

      leftbuffer = new ArrayList<SAMRecord>();
      rightbuffer = new ArrayList<SAMRecord>();

      makePairs();
      
      leftreader.close();
      rightreader.close();
  }
 
开发者ID:seqcode,项目名称:seqcode-core,代码行数:32,代码来源:PairedSAMToReadDB.java

示例6: ReadLocusIterator

import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
public ReadLocusIterator(SamReader samReader, Feature region) {
       	  
	if (region != null) {
		samIter = new ForwardShiftInsertIterator(samReader.queryOverlapping(region.getSeqname(), (int) region.getStart(), (int) region.getEnd()));
	} else {
		samIter = new ForwardShiftInsertIterator(samReader.iterator());
	}
}
 
开发者ID:mozack,项目名称:abra2,代码行数:9,代码来源:ReadLocusReader.java

示例7: testBAMMatch

import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
public static void testBAMMatch(String bam1, String bam2) {
	SamReader file = SamReaderFactory.makeDefault()
			.validationStringency(ValidationStringency.SILENT)
			.open(new File(bam1));
	SamReader file2 = SamReaderFactory.makeDefault()
			.validationStringency(ValidationStringency.SILENT)
			.open(new File(bam2));
	Iterator<SAMRecord> iter = file2.iterator();

	int i = 0;
	int j = 0;

	boolean start = false;

	for (SAMRecord r : file) {
		if (r.getReadUnmappedFlag())
			continue;
		SAMRecord r2 = iter.next();
		if (!r.equals(r2)) {
			r.equals(r2);
			System.out.println(r);
			System.out.println("-----------------------------");
			System.out.println(r2);
			System.out.println("-----------------------------");
			System.out.println("-----------------------------");
			start = true;

			System.out.println(r.getAlignmentStart() - 1);
		}
		if (start && i++ > 100)
			return;
		++j;
	}

	System.out.println(j);
}
 
开发者ID:acs6610987,项目名称:secram,代码行数:37,代码来源:ConverterTest.java

示例8: getSamReadLength

import htsjdk.samtools.SamReader; //导入方法依赖的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;
}
 
开发者ID:compgen-io,项目名称:ngsutilsj,代码行数:13,代码来源:ReadUtils.java

示例9: writeBfqFiles

import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
/**
 * Writes the binary fastq file(s) to the output directory
 */
public void writeBfqFiles() {

    final SamReader reader = SamReaderFactory.makeDefault().open(bamFile);
    final Iterator<SAMRecord> iterator = reader.iterator();

    // Filter out noise reads and reads that fail the quality filter
    final TagFilter tagFilter = new TagFilter(ReservedTagConstants.XN, 1);
    final FailsVendorReadQualityFilter qualityFilter = new FailsVendorReadQualityFilter();
    final WholeReadClippedFilter clippedFilter = new WholeReadClippedFilter();


    if (!pairedReads) {
        List<SamRecordFilter> filters = new ArrayList<SamRecordFilter>();
        filters.add(tagFilter);
        filters.add(clippedFilter);
        if (!this.includeNonPfReads) {
            filters.add(qualityFilter);
        }
        writeSingleEndBfqs(iterator, filters);
        codec1.close();
    }
    else {
        writePairedEndBfqs(iterator, tagFilter, qualityFilter, clippedFilter);
        codec1.close();
        codec2.close();
    }
    log.info("Wrote " + wrote + " bfq records.");
    CloserUtil.close(reader);
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:33,代码来源:BamToBfqWriter.java

示例10: doWork

import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
/**
 * Do the work after command line has been parsed.
 * RuntimeException may be thrown by this method, and are reported appropriately.
 *
 * @return program exit status.
 */
@Override
protected int doWork() {
    IOUtil.assertFileIsReadable(INPUT);
    IOUtil.assertFileIsWritable(OUTPUT);
    final SamReaderFactory factory = SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE);
    if (VALIDATION_STRINGENCY == ValidationStringency.STRICT) {
        factory.validationStringency(ValidationStringency.LENIENT);
    }
    final SamReader reader = factory.open(INPUT);
    final SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(reader.getFileHeader(), true, OUTPUT);
    final CloseableIterator<SAMRecord> it = reader.iterator();
    final ProgressLogger progress = new ProgressLogger(Log.getInstance(CleanSam.class));

    // If the read (or its mate) maps off the end of the alignment, clip it
    while (it.hasNext()) {
        final SAMRecord rec = it.next();

        // If the read (or its mate) maps off the end of the alignment, clip it
        AbstractAlignmentMerger.createNewCigarsIfMapsOffEndOfReference(rec);

        // check the read's mapping quality
        if (rec.getReadUnmappedFlag() && 0 != rec.getMappingQuality()) {
            rec.setMappingQuality(0);
        }

        writer.addAlignment(rec);
        progress.record(rec);
    }

    writer.close();
    it.close();
    CloserUtil.close(reader);
    return 0;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:41,代码来源:CleanSam.java

示例11: getOutieMode

import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
/**
 * Calculates the mode for outward-facing pairs, using the first SAMPLE_FOR_MODE
 * outward-facing pairs found in INPUT
 */
private double getOutieMode() {

    int samplePerFile = SAMPLE_FOR_MODE / INPUT.size();

    Histogram<Integer> histo = new Histogram<Integer>();

    for (File f : INPUT) {
        SamReader reader = SamReaderFactory.makeDefault().open(f);
        int sampled = 0;
        for (Iterator<SAMRecord> it = reader.iterator(); it.hasNext() && sampled < samplePerFile; ) {
            SAMRecord sam = it.next();
            if (!sam.getFirstOfPairFlag()) {
                continue;
            }
            // If we get here we've hit the end of the aligned reads
            if (sam.getReadUnmappedFlag() && sam.getReferenceIndex() == SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX) {
                break;
            } else if (sam.getReadUnmappedFlag() || sam.getMateUnmappedFlag()) {
                continue;
            } else if ((sam.getAttribute(SAMTag.MQ.name()) == null ||
                    sam.getIntegerAttribute(SAMTag.MQ.name()) >= MINIMUM_MAPPING_QUALITY) &&
                    sam.getMappingQuality() >= MINIMUM_MAPPING_QUALITY &&
                    sam.getMateNegativeStrandFlag() != sam.getReadNegativeStrandFlag() &&
                    sam.getMateReferenceIndex().equals(sam.getReferenceIndex()) &&
                    SamPairUtil.getPairOrientation(sam) == PairOrientation.RF) {
                histo.increment(Math.abs(sam.getInferredInsertSize()));
                sampled++;
            }
        }
        CloserUtil.close(reader);
    }

    return histo.size() > 0 ? histo.getMode() : 0;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:39,代码来源:CollectJumpingLibraryMetrics.java

示例12: countReads

import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
private int countReads(File samFile) {
    SamReader reader = SamReaderFactory.makeDefault().open(samFile);
    int count = 0;
    for (Iterator it = reader.iterator(); it.hasNext(); ) {
        it.next();
        count++;
    }
    CloserUtil.close(reader);
    return count;

}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:12,代码来源:SplitSamByLibraryTest.java

示例13: validateUq

import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
private void validateUq(final File input, final File reference) {
    final SamReader reader = SamReaderFactory.makeDefault().referenceSequence(reference).open(input);
    final SAMRecordIterator iterator = reader.iterator();
    while (iterator.hasNext()){
        SAMRecord rec = iterator.next();
        if (!rec.getReadUnmappedFlag())
            Assert.assertNotNull(rec.getAttribute("UQ"));
    }
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:10,代码来源:SetNmMdAndUqTagsTest.java

示例14: test

import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
protected void test() {
    try {
        final SamFileValidator validator = new SamFileValidator(new PrintWriter(System.out), 8000);

        // Validate it has the expected cigar
        validator.setIgnoreWarnings(true);
        validator.setVerbose(true, 1000);
        validator.setErrorsToIgnore(Arrays.asList(SAMValidationError.Type.MISSING_READ_GROUP));
        SamReaderFactory factory = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.LENIENT);
        SamReader samReader = factory.open(getOutput());
        final SAMRecordIterator iterator = samReader.iterator();
        while (iterator.hasNext()) {
            final SAMRecord rec = iterator.next();
            Assert.assertEquals(rec.getCigarString(), expectedCigar);
            if (SAMUtils.hasMateCigar(rec)) {
                Assert.assertEquals(SAMUtils.getMateCigarString(rec), expectedCigar);
            }
        }
        CloserUtil.close(samReader);

        // Run validation on the output file
        samReader = factory.open(getOutput());
        final boolean validated = validator.validateSamFileVerbose(samReader, null);
        CloserUtil.close(samReader);

        Assert.assertTrue(validated, "ValidateSamFile failed");
    } finally {
        TestUtil.recursiveDelete(getOutputDir());
    }
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:31,代码来源:CleanSamTester.java

示例15: isPairedData

import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
/**
 * Check if a SAM file contains paired-end data.
 * @param samIs the SAM file input stream
 * @return true if the SAM file contains paired-end data
 */
public static boolean isPairedData(final InputStream samIs) {

  if (samIs == null) {
    throw new NullPointerException("is argument cannot be null");
  }

  try {
    final SamReader input =
        SamReaderFactory.makeDefault().open(SamInputResource.of(samIs));

    SAMRecordIterator samIterator = input.iterator();

    boolean result = false;

    // Test if input is paired-end data
    if (samIterator.hasNext()) {
      if (samIterator.next().getReadPairedFlag()) {
        result = true;
      }
    }

    // Close input file
    input.close();

    return result;

  } catch (IOException e) {
    return false;
  }
}
 
开发者ID:GenomicParisCentre,项目名称:eoulsan,代码行数:36,代码来源:HTSeqCounter.java


注:本文中的htsjdk.samtools.SamReader.iterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。