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


Java SortingCollection.iterator方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: convert

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
/**
 * Parse the file and output in ".igv" format
 *
 * @return
 */
public static void convert(ResourceLocator resourceLocator, File outputFile, String probeResource,
                    int maxRecords, File tmpDir, Genome genome) throws IOException {

    ExpressionFileParser.FileType type = ExpressionFileParser.determineType(resourceLocator);

    GeneToLocusHelper locusHelper = new GeneToLocusHelper(probeResource);


    BufferedReader reader = null;
    PrintWriter writer = null;

    SortingCollection cltn = getSortingCollection(maxRecords, tmpDir);
    try {
        reader = new BufferedReader(new InputStreamReader(ParsingUtils.openInputStream(resourceLocator.getPath())));
        writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));

        ExpressionFileParser.FormatDescriptor formatDescriptor = ExpressionFileParser.parseHeader (reader, type, null);
        String [] dataHeadings = formatDescriptor.getDataHeaders();


        // Need a better way to determine type!
        String dataType = resourceLocator.getPath().contains("methylation") ? TrackType.DNA_METHYLATION.toString()
                : TrackType.GENE_EXPRESSION.toString();

        writer.println("#type=" + dataType);
        writer.print("Chr\tStart\tEnd\tProbe");
        for (String s : dataHeadings) {
            writer.print("\t" + s);
        }
        writer.println();

        String nextLine = null;
        while ((nextLine = reader.readLine()) != null) {

            // A gct row can map to multiple loci, normally this indicates a problem with the probe
            DataRow row = new DataRow(nextLine, formatDescriptor);
            String probe = row.getProbe();
            List<Locus> loci = locusHelper.getLoci(probe, row.getDescription(), genome.getId());
            if (loci == null || loci.isEmpty()) {
                log.warn("No locus found for: " + probe + "  " + row.getDescription());
            } else {
                for (Locus locus : loci) {
                    String igvLine = locus.getChr() + "\t" + locus.getStart() + "\t" + locus.getEnd() + "\t" + probe +
                            "\t" + row.getData();
                    cltn.add(new SortableRecord(locus.getChr(), locus.getStart(), igvLine));
                }
            }
        }


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

        }
    } finally {
        if (reader != null) {
            reader.close();
        }
        if (writer != null) {
            writer.close();
        }
    }

}
 
开发者ID:hyounesy,项目名称:ALEA,代码行数:73,代码来源:GCTtoIGVConverter.java

示例6: convert

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
/**
 * Parse the file and output in ".igv" format
 *
 * @return
 */
public static void convert(File inputFile, File outputFile, String probeResource,
                           int maxRecords, File tmpDir, Genome genome) throws IOException {

    GeneToLocusHelper locusHelper = new GeneToLocusHelper(probeResource);


    BufferedReader reader = null;
    PrintWriter writer = null;

    SortingCollection cltn = getSortingCollection(maxRecords, tmpDir);
    try {
        reader = new BufferedReader(new FileReader(inputFile));
        writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));

        // Parse the header line
        String headerLine = reader.readLine();
        String[] tokens = headerLine.split("\t");

        //The sample names in a GCT file start at column 2,
        int sampleStart = 2;


        String nextLine = null;
        TrackType dataType = TrackType.GENE_EXPRESSION;
        while ((nextLine = reader.readLine()) != null) {

            // A gct row can map to multiple loci, normally this indicates a problem with the probe
            DataRow row = new DataRow(nextLine);
            String probe = row.getProbe();
            if (probe.startsWith("cg")) {
                dataType = TrackType.DNA_METHYLATION;
            }

            List<Locus> loci = locusHelper.getLoci(probe, row.getDescription(), genome.getId());
            if (loci == null || loci.isEmpty()) {
                System.out.println("No locus found for: " + probe + "  " + row.getDescription());
            } else {
                for (Locus locus : loci) {
                    String igvLine = locus.getChr() + "\t" + locus.getStart() + "\t" + locus.getEnd() + "\t" + probe +
                            row.getData();
                    cltn.add(new SortableRecord(locus.getChr(), locus.getStart(), igvLine));
                }
            }
        }

        writer.println("#type=" + dataType.toString());
        writer.print("Chr\tStart\tEnd\tProbe");
        for (int i = sampleStart; i < tokens.length; i++) {
            writer.print("\t" + tokens[i]);
        }
        writer.println();
        // Ouputput the sorted file
        CloseableIterator<SortableRecord> iter = cltn.iterator();
        while (iter.hasNext()) {
            SortableRecord al = iter.next();
            writer.println(al.getText());

        }
    } finally {
        if (reader != null) {
            reader.close();
        }
        if (writer != null) {
            writer.close();
        }
    }

}
 
开发者ID:hyounesy,项目名称:ALEA,代码行数:74,代码来源:MageTabToIGVConverter.java

示例7: newBarcodeWorkInstance

import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
/**
         * Returns a PriorityRunnable that encapsulates the work involved with writing the provided tileRecord's data
         * for the given barcode to disk.
         *
         * @param tile       The tile from which the record was read
         * @param tileRecord The processing record associated with the tile
         * @param barcode    The barcode whose data within the tileRecord is to be written
         * @return The runnable that upon invocation writes the barcode's data from the tileRecord to disk
         */
        private PriorityRunnable newBarcodeWorkInstance(final Tile tile, final TileProcessingRecord tileRecord, final String barcode) {
            return new PriorityRunnable() {
                @Override
                public void run() {
                    try {
                        final SortingCollection<CLUSTER_OUTPUT_RECORD> records = tileRecord.getBarcodeRecords().get(barcode);
                        final ConvertedClusterDataWriter<CLUSTER_OUTPUT_RECORD> writer = barcodeRecordWriterMap.get(barcode);

                        log.debug(String.format("Writing records from tile %s with barcode %s ...", tile.getNumber(), barcode));

                        final PeekIterator<CLUSTER_OUTPUT_RECORD> it = new PeekIterator<>(records.iterator());
                        while (it.hasNext()) {
                            final CLUSTER_OUTPUT_RECORD rec = it.next();

                            /*
                             * PIC-330 Sometimes there are two reads with the same cluster coordinates, and thus
                             * the same read name.  Discard both of them.  This code assumes that the two first of pairs
                             * will come before the two second of pairs, so it isn't necessary to look ahead a different
                             * distance for paired end.  It also assumes that for paired ends there will be duplicates
                             * for both ends, so there is no need to be PE-aware.
                             */
                            if (it.hasNext()) {
                                final CLUSTER_OUTPUT_RECORD lookAhead = it.peek();

/* TODO: Put this in SAMFileWriter wrapper
                                if (!rec.getReadUnmappedFlag() || !lookAhead.getReadUnmappedFlag()) {
                                    throw new IllegalStateException("Should not have mapped reads.");
                                }
*/

                                if (outputRecordComparator.compare(rec, lookAhead) == 0) {
                                    it.next();
                                    log.info("Skipping reads with identical read names: " + rec.toString());
                                    continue;
                                }
                            }

                            writer.write(rec);
                            writeProgressLogger.record(null, 0);
                        }

                        tileRecord.setBarcodeState(barcode, TileBarcodeProcessingState.WRITTEN);
                        findAndEnqueueWorkOrSignalCompletion();

                    } catch (final RuntimeException | Error e) {
                        /*
                         * In the event of an internal failure, signal to the parent thread that something has gone
                         * wrong.  This is necessary because if an item of work fails to complete, the aggregator will
                         * will never reach its completed state, and it will never terminate.
                         */
                        parentThread.interrupt();
                        throw e;
                    }
                }

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

示例8: 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

示例9: 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

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