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


Java SortOrder类代码示例

本文整理汇总了Java中htsjdk.samtools.SAMFileHeader.SortOrder的典型用法代码示例。如果您正苦于以下问题:Java SortOrder类的具体用法?Java SortOrder怎么用?Java SortOrder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: sortBamFile

import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
public static void sortBamFile(File inputBamFile, File outputBamFile, File tempDirectory, final Comparator<SAMRecord> comparator) {
	try (SamReader currentReader = SamReaderFactory.makeDefault().open(inputBamFile)) {
		SAMFileHeader header = currentReader.getFileHeader();
		Iterator<SAMRecord> iter = currentReader.iterator();
		try (CloseableAndIterableIterator<SAMRecord> sortedIter = getSortedBamIterator(iter, header, tempDirectory, comparator)) {

			if (comparator.getClass().equals(SAMRecordCoordinateComparator.class)) {
				header.setSortOrder(SortOrder.coordinate);
			} else if (comparator.getClass().equals(SAMRecordQueryNameComparator.class)) {
				header.setSortOrder(SortOrder.queryname);
			} else if (comparator.getClass().equals(SAMRecordDuplicateComparator.class)) {
				header.setSortOrder(SortOrder.duplicate);
			}
			try (SAMFileWriter writer = new SAMFileWriterFactory().makeBAMWriter(header, true, outputBamFile, BAM_COMPRESSION_LEVEL)) {
				while (sortedIter.hasNext()) {
					SAMRecord nextRecord = sortedIter.next();
					writer.addAlignment(nextRecord);
				}
			}
		}
	} catch (IOException e) {
		throw new PicardException(e.getMessage(), e);
	}

}
 
开发者ID:NimbleGen,项目名称:bioinformatics,代码行数:26,代码来源:BamSorter.java

示例2: shouldFlushContainer

import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
/**
 * Decide if the current container should be completed and flushed. The
 * decision is based on a) number of records and b) if the reference
 * sequence id has changed.
 *
 * @param nextRecord
 *            the record to be added into the current or next container
 * @return true if the current container should be flushed and the following
 *         records should go into a new container; false otherwise.
 */
protected boolean shouldFlushContainer(final SAMRecord nextRecord) {
	if (refIdSet.isEmpty()) {
		return false;
	}

	if (samFileHeader.getSortOrder() != SAMFileHeader.SortOrder.coordinate) {
		return samRecords.size() >= containerSize;
	}

	boolean newRef = !refIdSet.contains(nextRecord.getReferenceIndex());
	int seenRefs = refIdSet.size();

	if (newRef && nextRecord.getReferenceIndex() == SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX) {
		// separate unsorted reads
		return true;
	}

	if (newRef && seenRefs == 1) {
		return samRecords.size() >= minSingeRefRecords;
	}

	return samRecords.size() >= containerSize;
}
 
开发者ID:enasequence,项目名称:cramtools,代码行数:34,代码来源:CRAMContainerStreamWriter.java

示例3: outputFinal

import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
public void outputFinal(int sampleIdx, String inputBam) throws IOException {
	
	Logger.info("Finishing: " + outputFiles[sampleIdx]);
	
	SAMRecord[] readsByNameArray = null;
	SAMRecord[] readsByCoordArray = null;

	if (shouldSort) {
		
		// Initialize internal read buffers used by SortingCollection2
		// These are initialized once per thread and re-used each time
		// a SortingCollection2 is initialized.
		readsByNameArray = new SAMRecord[maxRecordsInRam];
		readsByCoordArray = new SAMRecord[maxRecordsInRam];
		
		// Only allow buffering if sorting
		writerFactory.setUseAsyncIo(true);
		writerFactory.setAsyncOutputBufferSize(ASYNC_READ_CACHE_SIZE);
		writerFactory.setCreateIndex(shouldCreateIndex);
	} else {
		writerFactory.setUseAsyncIo(false);
	}
	
	writerFactory.setCompressionLevel(finalCompressionLevel);
	if (shouldSort) {
		samHeaders[sampleIdx].setSortOrder(SortOrder.coordinate);
	} else {
		samHeaders[sampleIdx].setSortOrder(SortOrder.unsorted);
	}
	SAMFileWriter output = writerFactory.makeBAMWriter(samHeaders[sampleIdx], true, new File(outputFiles[sampleIdx]), finalCompressionLevel);
	
	for (String chromosome : chromosomeChunker.getChromosomes()) {
		processChromosome(output, sampleIdx, chromosome, readsByNameArray, readsByCoordArray);
	}
	
	processUnmapped(output, inputBam);
	
	output.close();
}
 
开发者ID:mozack,项目名称:abra2,代码行数:40,代码来源:SortedSAMWriter.java

示例4: sortAndIndexSamOrBam

import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
/** Sort and index input sam or bam.
 * @throws IOException 
 * */
public static void sortAndIndexSamOrBam(String inSamOrBam, String sortedBam, boolean deleteOnExit) throws IOException {

	/*  ------------------------------------------------------ */
	/* This chunk prepares SamReader from local bam or URL bam */
	UrlValidator urlValidator = new UrlValidator();
	SamReaderFactory srf=SamReaderFactory.make();
	srf.validationStringency(ValidationStringency.SILENT);
	SamReader samReader;
	if(urlValidator.isValid(inSamOrBam)){
		samReader = SamReaderFactory.makeDefault().open(SamInputResource.of(new URL(inSamOrBam)));
	} else {
		samReader= srf.open(new File(inSamOrBam));
	}
	/*  ------------------------------------------------------ */
	
	samReader.getFileHeader().setSortOrder(SortOrder.coordinate);
	
	File out= new File(sortedBam);
	if(deleteOnExit){
		out.deleteOnExit();
		File idx= new File(out.getAbsolutePath().replaceAll("\\.bam$", "") + ".bai");
		idx.deleteOnExit();
	}
	
	SAMFileWriter outputSam= new SAMFileWriterFactory()
			.setCreateIndex(true)
			.makeSAMOrBAMWriter(samReader.getFileHeader(), false, out);

	for (final SAMRecord samRecord : samReader) {
		outputSam.addAlignment(samRecord);
       }
	samReader.close();
	outputSam.close();
}
 
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:38,代码来源:Utils.java

示例5: SamAlignmentMerger

import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
/**
 *  Constructor with a default value for unmappingReadStrategy
 *
 */
public SamAlignmentMerger(final File unmappedBamFile, final File targetBamFile, final File referenceFasta,
                          final SAMProgramRecord programRecord, final boolean clipAdapters, final boolean bisulfiteSequence,
                          final boolean alignedReadsOnly,
                          final List<File> alignedSamFile, final int maxGaps, final List<String> attributesToRetain,
                          final List<String> attributesToRemove,
                          final Integer read1BasesTrimmed, final Integer read2BasesTrimmed,
                          final List<File> read1AlignedSamFile, final List<File> read2AlignedSamFile,
                          final List<SamPairUtil.PairOrientation> expectedOrientations,
                          final SortOrder sortOrder,
                          final PrimaryAlignmentSelectionStrategy primaryAlignmentSelectionStrategy,
                          final boolean addMateCigar,
                          final boolean unmapContaminantReads,
                          final int minUnclippedBases) {
    this(unmappedBamFile,
            targetBamFile,
            referenceFasta,
            programRecord,
            clipAdapters,
            bisulfiteSequence,
            alignedReadsOnly,
            alignedSamFile,
            maxGaps,
            attributesToRetain,
            attributesToRemove,
            read1BasesTrimmed,
            read2BasesTrimmed,
            read1AlignedSamFile,
            read2AlignedSamFile,
            expectedOrientations,
            sortOrder,
            primaryAlignmentSelectionStrategy,
            addMateCigar,
            unmapContaminantReads,
            minUnclippedBases,
            UnmappingReadStrategy.DO_NOT_CHANGE,
            SAMSequenceDictionary.DEFAULT_DICTIONARY_EQUAL_TAG
            );
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:43,代码来源:SamAlignmentMerger.java

示例6: createHeaderMap

import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
private Map<String, SAMFileHeader> createHeaderMap(
        final SAMFileHeader inHeader,
        final SortOrder sortOrder,
        final boolean removeAlignmentInformation) {

    final Map<String, SAMFileHeader> headerMap = new HashMap<>();
    for (final SAMReadGroupRecord readGroup : inHeader.getReadGroups()) {
        final SAMFileHeader header = createOutHeader(inHeader, sortOrder, removeAlignmentInformation);
        header.addReadGroup(readGroup);
        headerMap.put(readGroup.getId(), header);
    }
    return headerMap;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:14,代码来源:RevertSam.java

示例7: createOutHeader

import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
private SAMFileHeader createOutHeader(
        final SAMFileHeader inHeader,
        final SAMFileHeader.SortOrder sortOrder,
        final boolean removeAlignmentInformation) {

    final SAMFileHeader outHeader = new SAMFileHeader();
    outHeader.setSortOrder(sortOrder);
    if (!removeAlignmentInformation) {
        outHeader.setSequenceDictionary(inHeader.getSequenceDictionary());
        outHeader.setProgramRecords(inHeader.getProgramRecords());
    }
    return outHeader;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:14,代码来源:RevertSam.java

示例8: AbstractAlignmentMerger

import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
/** constructor with a default setting for unmappingReadsStrategy.
 *
 * see full constructor for parameters
 *
 *
 */
public AbstractAlignmentMerger(final File unmappedBamFile, final File targetBamFile,
                               final File referenceFasta, final boolean clipAdapters,
                               final boolean bisulfiteSequence, final boolean alignedReadsOnly,
                               final SAMProgramRecord programRecord, final List<String> attributesToRetain,
                               final List<String> attributesToRemove,
                               final Integer read1BasesTrimmed, final Integer read2BasesTrimmed,
                               final List<SamPairUtil.PairOrientation> expectedOrientations,
                               final SortOrder sortOrder,
                               final PrimaryAlignmentSelectionStrategy primaryAlignmentSelectionStrategy,
                               final boolean addMateCigar,
                               final boolean unmapContaminantReads) {
    this(unmappedBamFile,
         targetBamFile,
         referenceFasta,
         clipAdapters,
         bisulfiteSequence,
         alignedReadsOnly,
         programRecord,
         attributesToRetain,
         attributesToRemove,
         read1BasesTrimmed,
         read2BasesTrimmed,
         expectedOrientations,
         sortOrder,
         primaryAlignmentSelectionStrategy,
         addMateCigar,
         unmapContaminantReads,
         UnmappingReadStrategy.DO_NOT_CHANGE);
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:36,代码来源:AbstractAlignmentMerger.java

示例9: convert

import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
/**
 * Convert BAM file to sorted SAM with Picard
 * @param bamDataFile input SAM file
 * @param samDataFile output SAM file
 * @param reporter reporter
 * @param tmpDir temporary directory
 * @throws IOException if an error occurs
 */

// private static final void convert(final File in, final File out)
private static void convert(final DataFile bamDataFile,
    final DataFile samDataFile, final Reporter reporter, final File tmpDir)
    throws IOException {

  InputStream in = bamDataFile.open();
  OutputStream out = samDataFile.create();

  // Open bam file
  final SamReader bamReader =
      SamReaderFactory.makeDefault().open(SamInputResource.of(in));

  // Force sort
  bamReader.getFileHeader().setSortOrder(SortOrder.unsorted);

  // Open sam file
  final SAMFileWriter samWriter = new SAMFileWriterFactory()
      .setCreateIndex(false).setTempDirectory(tmpDir)
      .makeSAMWriter(bamReader.getFileHeader(), false, out);

  for (final SAMRecord samRecord : bamReader) {
    samWriter.addAlignment(samRecord);
    reporter.incrCounter(COUNTER_GROUP, "converted records", 1);
  }
  samWriter.close();
  bamReader.close();

}
 
开发者ID:GenomicParisCentre,项目名称:eoulsan,代码行数:38,代码来源:BAM2SAMLocalModule.java

示例10: createBamFile

import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
public static void createBamFile(SAMFileHeader header, File outputFile, List<SAMRecordPair> records) {
	// Make an output BAM file sorted by coordinates and as compressed as possible
	header.setSortOrder(SortOrder.coordinate);
	SAMFileWriter samWriter = new SAMFileWriterFactory().makeBAMWriter(header, false, outputFile, 9);
	for (SAMRecordPair pair : records) {
		samWriter.addAlignment(pair.getFirstOfPairRecord());
		samWriter.addAlignment(pair.getSecondOfPairRecord());
	}
	samWriter.close();
}
 
开发者ID:NimbleGen,项目名称:bioinformatics,代码行数:11,代码来源:SAMRecordUtil.java

示例11: picardSortAndCompress

import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
/**
 * Use picard to sort and compress the provided input file
 * 
 * @param input
 * @param output
 * @param sortOrder
 * @return
 */
private static File picardSortAndCompress(boolean outputAsBam, File input, File output, SortOrder sortOrder, Set<String> readNamesToExclude) {
	IOUtil.assertFileIsReadable(input);
	IOUtil.assertFileIsWritable(output);

	try (SamReader reader = SamReaderFactory.makeDefault().open(input)) {

		SAMFileHeader header = reader.getFileHeader();
		header.setSortOrder(sortOrder);

		SAMFileWriter writer = null;

		if (outputAsBam) {
			writer = new SAMFileWriterFactory().makeBAMWriter(header, false, output, 9);
		} else {
			writer = new SAMFileWriterFactory().makeSAMWriter(header, false, output);
		}

		for (final SAMRecord record : reader) {
			boolean shouldInclude = true;
			if (readNamesToExclude != null) {
				String readName = IlluminaFastQReadNameUtil.getUniqueIdForReadHeader(record.getReadName());
				shouldInclude = !readNamesToExclude.contains(readName);
			}

			if (shouldInclude) {
				writer.addAlignment(record);
			}
		}
		writer.close();
	} catch (IOException e) {
		throw new PicardException(e.getMessage(), e);
	}

	return output;
}
 
开发者ID:NimbleGen,项目名称:bioinformatics,代码行数:44,代码来源:BamFileUtil.java

示例12: isSortedBasedOnHeader

import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
public static boolean isSortedBasedOnHeader(File bamFile, SortOrder sortOrder) {
	IOUtil.assertFileIsReadable(bamFile);
	boolean isSorted = false;
	try (SamReader reader = SamReaderFactory.makeDefault().open(bamFile)) {
		SAMFileHeader header = reader.getFileHeader();
		isSorted = header.getSortOrder().equals(SortOrder.coordinate);
	} catch (IOException e) {
		throw new PicardException(e.getMessage(), e);
	}
	return isSorted;
}
 
开发者ID:NimbleGen,项目名称:bioinformatics,代码行数:12,代码来源:BamFileUtil.java

示例13: doWork

import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
@Override
public int doWork(List<String> args)
	{
	SamReader sfr=null;
	try
		{
		sfr = super.openSamReader(oneFileOrNull(args));
		
		if(sfr.getFileHeader().getSortOrder()!=SortOrder.coordinate)
			{
			LOG.error("BAM file is not sorted.");
			return -1;
			}
		
		run(sfr);
		return 0;
		}
	catch(Exception err)
		{
		LOG.error(err);
		return -1;
		}
	finally
		{
		CloserUtil.close(sfr);
		}

	}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:29,代码来源:CoverageNormalizer.java

示例14: open

import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
public void open(final SAMFileHeader src)
{
SAMFileWriterFactory samFileWriterFactory=writingBamArgs.createSAMFileWriterFactory();
samFileWriterFactory.setMaxRecordsInRam(writingSortingCollection.getMaxRecordsInRam());
samFileWriterFactory.setTempDirectory(writingSortingCollection.getTmpDirectories().get(0));


final File fileout=getFile();
LOG.info("opening BAM file "+fileout);
final File parent=fileout.getParentFile();
if(parent!=null) {
	parent.mkdirs();
	samFileWriterFactory.setTempDirectory(writingSortingCollection.getTmpDirectories().get(0));
}


this.header= src.clone();
this.header.addComment(
		"Processed with "+getProgramCommandLine()+
		" version:"+getVersion()+
		"CommandLine:"+getProgramCommandLine()
		);

this.header.setSortOrder(SortOrder.coordinate);
samFileWriterFactory.setCreateIndex(true);
	

this._writer = samFileWriterFactory.makeBAMWriter(
	this.header,
	true,
	fileout
	);
}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:34,代码来源:SplitBam3.java

示例15: run

import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
@Override
public void run() {
	// TODO Auto-generated method stub
	final SamReaderFactory factory =
			SamReaderFactory.makeDefault()
			.enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, 
					SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS)
			.validationStringency(ValidationStringency.SILENT);
	final SamReader inputSam = factory.open(new File(mySamFile));
	
	samHeader = inputSam.getFileHeader();
	samHeader.setSortOrder(SortOrder.unsorted);
	SAMRecordIterator iter=inputSam.iterator();
	Set<Entry<String, String>> attr = samHeader.getAttributes();
	
	List<SAMReadGroupRecord> rgs = samHeader.getReadGroups();
	
	SAMReadGroupRecord rg = new SAMReadGroupRecord("cz1");
	rg.setSample("cz1");
	samHeader.addReadGroup(rg);
	
	
	//samHeader.setAttribute("RG", "cz1");
	final SAMFileWriter outSam = new SAMFileWriterFactory().
			makeSAMOrBAMWriter(samHeader,
					true, new File(myOutput));
	
	for(int i=0; i<100; i++) {
		SAMRecord record = iter.next();
		List<SAMTagAndValue> tags = record.getAttributes();
		record.setAttribute("RG", "cz1");
		List<SAMTagAndValue> tags2 = record.getAttributes();
		outSam.addAlignment(record);
	}
	myLogger.info("exit...");
	
	try {
		inputSam.close();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	outSam.close();
}
 
开发者ID:c-zhou,项目名称:polyGembler,代码行数:45,代码来源:SAMtools.java


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