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


Java SortingCollection.newInstance方法代码示例

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


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

示例1: RevertSamSorter

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
RevertSamSorter(
        final boolean outputByReadGroup,
        final Map<String, SAMFileHeader> headerMap,
        final SAMFileHeader singleOutHeader,
        final int maxRecordsInRam) {

    this.outputByReadGroup = outputByReadGroup;
    if (outputByReadGroup) {
        for (final Map.Entry<String, SAMFileHeader> entry : headerMap.entrySet()) {
            final String readGroupId = entry.getKey();
            final SAMFileHeader outHeader = entry.getValue();
            final SortingCollection<SAMRecord> sorter = SortingCollection.newInstance(SAMRecord.class, new BAMRecordCodec(outHeader), new SAMRecordQueryNameComparator(), maxRecordsInRam);
            sorterMap.put(readGroupId, sorter);
        }
        singleSorter = null;
    } else {
        singleSorter = SortingCollection.newInstance(SAMRecord.class, new BAMRecordCodec(singleOutHeader), new SAMRecordQueryNameComparator(), maxRecordsInRam);
    }
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:20,代码来源:RevertSam.java

示例2: sortInputs

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
/**
 * Merge the inputs and sort them by adding each input's content to a single SortingCollection.
 * <p/>
 * NB: It would be better to have a merging iterator as in MergeSamFiles, as this would perform better for pre-sorted inputs.
 * Here, we are assuming inputs are unsorted, and so adding their VariantContexts iteratively is fine for now.
 * MergeVcfs exists for simple merging of presorted inputs.
 *
 * @param readers      - a list of VCFFileReaders, one for each input VCF
 * @param outputHeader - The merged header whose information we intend to use in the final output file
 */
private SortingCollection<VariantContext> sortInputs(final List<VCFFileReader> readers, final VCFHeader outputHeader) {
    final ProgressLogger readProgress = new ProgressLogger(log, 25000, "read", "records");

    // NB: The default MAX_RECORDS_IN_RAM may not be appropriate here. VariantContexts are smaller than SamRecords
    // We would have to play around empirically to find an appropriate value. We are not performing this optimization at this time.
    final SortingCollection<VariantContext> sorter =
            SortingCollection.newInstance(
                    VariantContext.class,
                    new VCFRecordCodec(outputHeader, VALIDATION_STRINGENCY != ValidationStringency.STRICT),
                    outputHeader.getVCFRecordComparator(),
                    MAX_RECORDS_IN_RAM,
                    TMP_DIR);
    int readerCount = 1;
    for (final VCFFileReader reader : readers) {
        log.info("Reading entries from input file " + readerCount);
        for (final VariantContext variantContext : reader) {
            sorter.add(variantContext);
            readProgress.record(variantContext.getContig(), variantContext.getStart());
        }
        reader.close();
        readerCount++;
    }
    return sorter;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:35,代码来源:SortVcf.java

示例3: run

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
/**
 * @param maxMemory - in megabytes
 * @throws IOException
 *
 */
public void run(int maxMemory) throws IOException {
    try (
            PrintWriter writer = NgbFileUtils.isGzCompressed(outputFile.getName()) ?
                    new PrintWriter(new OutputStreamWriter(new BlockCompressedOutputStream(outputFile), UTF_8)) :
                    new PrintWriter(outputFile, UTF_8);
            AsciiLineReader reader = NgbFileUtils.isGzCompressed(outputFile.getName()) ?
                    new AsciiLineReader(new BlockCompressedInputStream(inputFile)) :
                    new AsciiLineReader(new FileInputStream(inputFile))
    ) {

        SortableRecordCodec codec = new SortableRecordCodec();

        SortingCollection cltn = SortingCollection.newInstance(
                SortableRecord.class, codec, comparator, maxMemory * 1024 * 1024 / ESTIMATED_RECORD_SIZE, tmpDir);

        Parser parser = getParser();

        String firstDataRow = writeHeader(reader, writer);
        if (firstDataRow != null && !firstDataRow.isEmpty()) {
            cltn.add(parser.createRecord(firstDataRow));
        }

        SortableRecord next;
        while ((next = parser.readNextRecord(reader)) != null) {
            cltn.add(next);
        }

        CloseableIterator<SortableRecord> iter = cltn.iterator();
        while (iter.hasNext()) {
            SortableRecord al = iter.next();
            writer.println(al.getText());

        }
        iter.close();
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:42,代码来源:AbstractFeatureSorter.java

示例4: run

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
/**
 * @param maxMemory - in megabytes
 * @throws IOException
 *
 */
public void run(int maxMemory) throws IOException {
    try (
            PrintWriter writer = NgbFileUtils.isGzCompressed(outputFile.getName()) ?
                    new PrintWriter(new OutputStreamWriter(new BlockCompressedOutputStream(outputFile), UTF_8)) :
                    new PrintWriter(outputFile, UTF_8);
            AsciiLineReader reader = NgbFileUtils.isGzCompressed(inputFile.getName()) ?
                    new AsciiLineReader(new BlockCompressedInputStream(inputFile)) :
                    new AsciiLineReader(new FileInputStream(inputFile))
    ) {

        SortableRecordCodec codec = new SortableRecordCodec();

        SortingCollection cltn = SortingCollection.newInstance(
                SortableRecord.class, codec, comparator, maxMemory * 1024 * 1024 / ESTIMATED_RECORD_SIZE, tmpDir);

        Parser parser = getParser();

        String firstDataRow = writeHeader(reader, writer);
        if (firstDataRow != null && !firstDataRow.isEmpty()) {
            cltn.add(parser.createRecord(firstDataRow));
        }

        SortableRecord next;
        while ((next = parser.readNextRecord(reader)) != null) {
            cltn.add(next);
        }

        CloseableIterator<SortableRecord> iter = cltn.iterator();
        while (iter.hasNext()) {
            SortableRecord al = iter.next();
            writer.println(al.getText());

        }
        iter.close();
    }
}
 
开发者ID:epam,项目名称:NGB,代码行数:42,代码来源:AbstractFeatureSorter.java

示例5: newSortingCollection

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
private synchronized SortingCollection<CLUSTER_OUTPUT_RECORD> newSortingCollection() {
    final int maxRecordsInRam =
            Math.max(1, maxReadsInRamPerTile /
                    barcodeRecordWriterMap.size());
    return SortingCollection.newInstance(
            outputRecordClass,
            codecPrototype.clone(),
            outputRecordComparator,
            maxRecordsInRam,
            tmpDirs);
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:12,代码来源:NewIlluminaBasecallsConverter.java

示例6: makeSortingCollection

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
private SortingCollection<String> makeSortingCollection() {
    final String name = getClass().getSimpleName();
    final File tmpDir = IOUtil.createTempDir(name, null);
    tmpDir.deleteOnExit();
    // 256 byte for one name, and 1/10 part of all memory for this, rough estimate
    long maxNamesInRam = Runtime.getRuntime().maxMemory() / 256 / 10;
    return SortingCollection.newInstance(
            String.class,
            new StringCodec(),
            String::compareTo,
            (int) Math.min(maxNamesInRam, Integer.MAX_VALUE),
            tmpDir
    );
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:15,代码来源:CreateSequenceDictionary.java

示例7: runSingle

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
private void runSingle(final FastqReader r1,final FastqWriter w1) throws IOException
{
long nReads=0;
final  SortingCollection<OneRead> sorting= SortingCollection.newInstance(
		OneRead.class,
		new OneReadCodec(),
		new OneReadCompare(),
		this.writingSortingCollection.getMaxRecordsInRam(),
		this.writingSortingCollection.getTmpPaths()
		);
sorting.setDestructiveIteration(true);
while(r1.hasNext())
	{
	final OneRead r=new OneRead();
	r.random=this.random.nextLong();
	r.index=nReads;
	r.first=r1.next();
	
	if((++nReads)%this.writingSortingCollection.getMaxRecordsInRam()==0)
		{
		LOG.info("Read "+nReads+" reads");
		}

	
	sorting.add(r);
	}
sorting.doneAdding();

final CloseableIterator<OneRead> iter=sorting.iterator();
while(iter.hasNext())
	{
	final OneRead p=iter.next();
	w1.write(p.first);
	}

	
CloserUtil.close(iter);
sorting.cleanup();
}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:40,代码来源:FastqShuffle.java

示例8: writeHeader

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
@Override
public void writeHeader(VCFHeader header) {
	this.delegate.writeHeader(header);			
	this.sorter =
               SortingCollection.newInstance(
                       VariantContext.class,
                       new VCFRecordCodec(header),
                       header.getVCFRecordComparator(),
                       VcfIndexTabix.this.writingSortingCollection.getMaxRecordsInRam(),
                       VcfIndexTabix.this.writingSortingCollection.getTmpPaths()
                       );
	
	}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:14,代码来源:VcfIndexTabix.java

示例9: newInstance

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
public static SortingCollection<VcfLine> newInstance(int maxRecords, String tempDir) {
	return SortingCollection.newInstance(VcfLine.class, new VcfLineCodec(), new VcfLineComparator(), maxRecords,
			new File(tempDir));
}
 
开发者ID:genepi,项目名称:imputationserver,代码行数:5,代码来源:VcfLineSortingCollection.java

示例10: run

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
public void run() throws IOException {

        FileInputStream fis = null;
        PrintWriter writer = null;

        try {
            fis = new FileInputStream(inputFile);
            Writer rawWriter;
            if (writeStdOut) {
                rawWriter = new OutputStreamWriter(System.out);
            } else {
                rawWriter = new FileWriter(this.outputFile);
            }
            writer = new PrintWriter(new BufferedWriter(rawWriter));

            SortableRecordCodec codec = new SortableRecordCodec();

            SortingCollection cltn = SortingCollection.newInstance(SortableRecord.class, codec, comparator, maxRecords, tmpDir);

            Parser parser = getParser();
            AsciiLineReader reader = new AsciiLineReader(fis);

            String firstDataRow = writeHeader(reader, writer);
            if (firstDataRow != null) {
                cltn.add(parser.createRecord(firstDataRow));
            }

            SortableRecord next = null;
            while ((next = parser.readNextRecord(reader)) != null) {
                cltn.add(next);
            }


            CloseableIterator<SortableRecord> iter = cltn.iterator();
            while (iter.hasNext()) {
                SortableRecord al = iter.next();
                writer.println(al.getText());

            }
            iter.close();
        } finally {
            if (fis != null) fis.close();
            if (writer != null) writer.close();
        }
    }
 
开发者ID:hyounesy,项目名称:ALEA,代码行数:46,代码来源:AsciiSorter.java

示例11: add

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
@Override
public void add(final VariantContext ctx) {
	if(prev_contig==null || !ctx.getContig().equals(prev_contig)) {
		dump();
		prev_contig=ctx.getContig();
		}
	if(ctx.isFiltered() && !this.acceptFiltered)
		{
		//add to delegate without registering the SPLIT name
		super.add(ctx);
		return;
		}
	
	final Set<String> splitNames = getSplitNamesFor(ctx);
	if(splitNames.isEmpty())
		{
		super.add(ctx);
		return;
		}
	if(this.sortingcollection==null) {
		/* create sorting collection for new contig */
		this.sortingcollection = SortingCollection.newInstance(
				Interval.class,
				new IntervalCodec(),
				new IntervalComparator(),
				this.maxRecordsInRam,
				this.tmpDir.toPath()
				);
		this.sortingcollection.setDestructiveIteration(true);
		}
	for(final String spltiName:splitNames)
		{
		this.sortingcollection.add(
				new Interval(ctx.getContig(), ctx.getStart(), ctx.getEnd(),false,spltiName));
		}
	
	
	super.add(new VariantContextBuilder(ctx).attribute(
			this.splitInfoKey,
			new ArrayList<>(splitNames)).
			make());
	}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:43,代码来源:VcfBurdenSplitter2.java

示例12: doWork

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
@Override
public int doWork(final List<String> args) {
	if(this.count<-1L) // -1 == infinite
		{
		LOG.error("Bad count:"+count);
		return -1;
		}
	SamReader samReader=null;
	SAMRecordIterator iter=null;
	SAMFileWriter samWriter=null;
	Random random=new Random();
	CloseableIterator<RandSamRecord> iter2=null;
	try
		{
		
		samReader = super.openSamReader(oneFileOrNull(args));
		
		final SAMFileHeader header=samReader.getFileHeader().clone();
					
		header.setSortOrder(SortOrder.unsorted);
		header.addComment("Processed with "+getProgramName()+" : "+getProgramCommandLine());
		
		samWriter = writingBamArgs.openSAMFileWriter(outputFile, header, true);
		
		iter=samReader.iterator();
		SAMSequenceDictionaryProgress progress=new SAMSequenceDictionaryProgress(samReader.getFileHeader().getSequenceDictionary());
		
		SortingCollection<RandSamRecord> sorter=SortingCollection.newInstance(
				RandSamRecord.class,
				new RandSamRecordCodec(header),
				new RandSamRecordComparator(), 
				this.writingSortingCollection.getMaxRecordsInRam(),
				this.writingSortingCollection.getTmpPaths()
				);
		sorter.setDestructiveIteration(true);
		while(iter.hasNext())
			{
			RandSamRecord r=new RandSamRecord();
			r.rand_index  = random.nextInt();
			r.samRecord =  progress.watch(iter.next());

			sorter.add(r);
			}
		iter.close();iter=null;
		
		sorter.doneAdding();
		iter2=sorter.iterator();
		if(count==-1)
			{
			while(iter2.hasNext())
				{
				samWriter.addAlignment(iter2.next().samRecord);
				}
			}
		else
			{
			while(iter2.hasNext() && count>0)
				{
				samWriter.addAlignment(iter2.next().samRecord);
				count--;
				}
			}
		iter2.close();iter2=null;
		sorter.cleanup();
		progress.finish();
		}
	catch (Exception e)
		{
		LOG.error(e);
		return -1;
		}
	finally
		{
		CloserUtil.close(iter);
		CloserUtil.close(iter2);
		CloserUtil.close(samReader);
		CloserUtil.close(samWriter);
		}
	return 0;
	}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:81,代码来源:Biostar145820.java

示例13: doWork

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
@Override
public int doWork(List<String> args) {
	SamReader in=null;
	SAMFileWriter out=null;
	SAMRecordIterator iter=null;
	CloseableIterator<SAMRecord> iter2=null;
	SortingCollection<SAMRecord> sorter=null;
	try
		{
		in  = openSamReader(oneFileOrNull(args));
		final SAMFileHeader header= in.getFileHeader();
		
		final BAMRecordCodec bamRecordCodec=new BAMRecordCodec(header);
		final RefNameComparator refNameComparator=new RefNameComparator();
		sorter =SortingCollection.newInstance(
				SAMRecord.class,
				bamRecordCodec,
				refNameComparator,
				this.writingSortingCollection.getMaxRecordsInRam(),
				this.writingSortingCollection.getTmpPaths()
				);
		sorter.setDestructiveIteration(true);
		
		final SAMSequenceDictionaryProgress progress=new SAMSequenceDictionaryProgress(header);
		iter = in.iterator();
		while(iter.hasNext())
			{
			sorter.add( progress.watch(iter.next()));
			}
		in.close();in=null;
		sorter.doneAdding();
		
		final SAMFileHeader header2=header.clone();
		header2.addComment(getProgramName()+" "+getVersion()+" "+getProgramCommandLine());
		header2.setSortOrder(SortOrder.unsorted);
		out = this.writingBamArgs.openSAMFileWriter(outputFile,header2, true);
		iter2 = sorter.iterator();
		while(iter2.hasNext())
			{
			out.addAlignment(iter2.next());
			}
		out.close();out=null;
		sorter.cleanup();
		progress.finish();
		LOG.info("done");
		return RETURN_OK;
		}
	catch(Exception err)
		{
		LOG.error(err);
		return -1;
		}
	finally
		{
		CloserUtil.close(iter2);
		CloserUtil.close(iter);
		CloserUtil.close(out);
		CloserUtil.close(in);
		}
	}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:61,代码来源:SortSamRefName.java

示例14: sortvcf

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
protected int sortvcf(BufferedReader in) throws IOException 
  	{
if(this.refdict!=null) {
	LOG.info("load dict from "+this.refdict);
	this.dict = SAMSequenceDictionaryExtractor.extractDictionary(this.refdict);
	if(this.dict==null) {
		LOG.error("cannot find sam sequence dictionary from "+refdict);
	}
}

final VCFUtils.CodecAndHeader cah =VCFUtils.parseHeader(in);
  	final VCFHeader h2=new  VCFHeader(cah.header);
  	if(this.dict!=null)
  		{
  		h2.setSequenceDictionary(this.dict);
  		}
  	else
  		{
  		this.dict= h2.getSequenceDictionary();
  		if(this.dict==null)
  			{
  			LOG.error("No internal sequence dictionay found in input");
  			return -1;
  			}
  		}
  	
  	addMetaData(h2);

if(this.dict.isEmpty())
	{
	LOG.warn("SEQUENCE DICTIONARY IS EMPTY/NULL");
	}

  	CloseableIterator<ChromPosLine> iter=null;
  	SortingCollection<ChromPosLine> array=null;
  	VariantContextWriter w =null;
  	try {
	array= SortingCollection.newInstance(
			ChromPosLine.class,
			new VariantCodec(),
			new VariantComparator(),
			this.writingSortingCollection.getMaxRecordsInRam(),
			this.writingSortingCollection.getTmpPaths()
			);
	array.setDestructiveIteration(true);
	final SAMSequenceDictionaryProgress progress=new SAMSequenceDictionaryProgress(this.dict);
	String line;
	while((line=in.readLine())!=null)
		{
		final ChromPosLine cpl=new ChromPosLine(line);
		progress.watch(cpl.tid,cpl.pos);
		array.add(cpl);
		}
	array.doneAdding();
	progress.finish();
	
	w = super.openVariantContextWriter(outputFile);
	w.writeHeader(h2);
	
	iter=array.iterator();
	while(iter.hasNext())
		{
		w.add(cah.codec.decode(iter.next().line));
		if(w.checkError()) break;
		}
	return RETURN_OK;
	}
  	catch (Exception e)
  		{
	LOG.error(e);
	return -1;
	}
  	finally
   	{
  		CloserUtil.close(w);
   	CloserUtil.close(iter);
   	if(array!=null) array.cleanup();
   	}
  	
  	}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:81,代码来源:SortVcfOnRef2.java


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