本文整理汇总了Java中htsjdk.samtools.SAMFileHeader.SortOrder类的典型用法代码示例。如果您正苦于以下问题:Java SortOrder类的具体用法?Java SortOrder怎么用?Java SortOrder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SortOrder类属于htsjdk.samtools.SAMFileHeader包,在下文中一共展示了SortOrder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: initChromosomeChunk
import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
private void initChromosomeChunk(int sampleIdx, int chromosomeChunkIdx) {
Logger.debug("Writer init: %d, %d", sampleIdx, chromosomeChunkIdx);
samHeaders[sampleIdx].setSortOrder(SortOrder.unsorted);
writers[sampleIdx][chromosomeChunkIdx] = writerFactory.makeBAMWriter(samHeaders[sampleIdx], false, new File(getTempFilename(sampleIdx, chromosomeChunkIdx)), TEMP_COMPRESSION_LEVEL);
}
开发者ID:mozack,项目名称:abra2,代码行数:6,代码来源:SortedSAMWriter.java
示例17: getQuerynameSortedAlignedRecords
import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
/**
* Reads the aligned SAM records into a SortingCollection and returns an iterator over that collection
*/
protected CloseableIterator<SAMRecord> getQuerynameSortedAlignedRecords() {
final CloseableIterator<SAMRecord> mergingIterator;
final SAMFileHeader header;
// When the alignment records, including both ends of a pair, are in SAM files
if (alignedSamFile != null && !alignedSamFile.isEmpty()) {
final List<SAMFileHeader> headers = new ArrayList<>(alignedSamFile.size());
final List<SamReader> readers = new ArrayList<>(alignedSamFile.size());
for (final File f : this.alignedSamFile) {
final SamReader r = SamReaderFactory.makeDefault().referenceSequence(referenceFasta).open(f);
headers.add(r.getFileHeader());
readers.add(r);
// As we're going through and opening the aligned files, if we don't have a @PG yet
// and there is only a single one in the input file, use that!
if (getProgramRecord() == null && r.getFileHeader().getProgramRecords().size() == 1) {
setProgramRecord(r.getFileHeader().getProgramRecords().iterator().next());
}
}
// assert that all the dictionaries are the same before merging the headers.
alignedSamDictionary = headers.get(0).getSequenceDictionary();
headers.stream()
.map(SAMFileHeader::getSequenceDictionary)
.forEach(alignedSamDictionary::assertSameDictionary);
final SamFileHeaderMerger headerMerger = new SamFileHeaderMerger(SortOrder.queryname, headers, false);
mergingIterator = new MergingSamRecordIterator(headerMerger, readers, true);
header = headerMerger.getMergedHeader();
}
// When the ends are aligned separately and don't have firstOfPair information correctly
// set we use this branch.
else {
// this merging iterator already asserts that all the headers are the same
mergingIterator = new SeparateEndAlignmentIterator(this.read1AlignedSamFile, this.read2AlignedSamFile, referenceFasta);
header = ((SeparateEndAlignmentIterator) mergingIterator).getHeader();
alignedSamDictionary = header.getSequenceDictionary();
// As we're going through and opening the aligned files, if we don't have a @PG yet
// and there is only a single one in the input file, use that!
if (getProgramRecord() == null && header.getProgramRecords().size() == 1) {
setProgramRecord(header.getProgramRecords().iterator().next());
}
}
if (!forceSort) {
return mergingIterator;
}
final SortingCollection<SAMRecord> alignmentSorter = SortingCollection.newInstance(SAMRecord.class,
new BAMRecordCodec(header), new SAMRecordQueryNameComparator(), MAX_RECORDS_IN_RAM);
int count = 0;
while (mergingIterator.hasNext()) {
alignmentSorter.add(mergingIterator.next());
count++;
if (count > 0 && count % 1000000 == 0) {
log.info("Read " + count + " records from alignment SAM/BAM.");
}
}
log.info("Finished reading " + count + " total records from alignment SAM/BAM.");
mergingIterator.close();
return new DelegatingIterator<SAMRecord>(alignmentSorter.iterator()) {
@Override
public void close() {
super.close();
alignmentSorter.cleanup();
}
};
}
开发者ID:broadinstitute,项目名称:picard,代码行数:79,代码来源:SamAlignmentMerger.java
示例18: isPresorted
import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
private boolean isPresorted(final SAMFileHeader inHeader, final SortOrder sortOrder, final boolean sanitizing) {
return (inHeader.getSortOrder() == sortOrder) || (sortOrder == SortOrder.queryname && sanitizing);
}
开发者ID:broadinstitute,项目名称:picard,代码行数:4,代码来源:RevertSam.java
示例19: validateSanitizeSortOrder
import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
static void validateSanitizeSortOrder(final boolean sanitize, final SAMFileHeader.SortOrder sortOrder, final List<String> errors) {
if (sanitize && sortOrder != SAMFileHeader.SortOrder.queryname) {
errors.add("SORT_ORDER must be queryname when sanitization is enabled with SANITIZE=true.");
}
}
开发者ID:broadinstitute,项目名称:picard,代码行数:6,代码来源:RevertSam.java
示例20: createSamFileWriter
import htsjdk.samtools.SAMFileHeader.SortOrder; //导入依赖的package包/类
protected void createSamFileWriter(final SAMFileHeader header) {
out = new SAMFileWriterFactory().makeSAMOrBAMWriter(header,
header.getSortOrder() == SortOrder.queryname, OUTPUT);
}
开发者ID:broadinstitute,项目名称:picard,代码行数:6,代码来源:FixMateInformation.java
注:本文中的htsjdk.samtools.SAMFileHeader.SortOrder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论