本文整理汇总了Java中htsjdk.samtools.util.SortingCollection.add方法的典型用法代码示例。如果您正苦于以下问题:Java SortingCollection.add方法的具体用法?Java SortingCollection.add怎么用?Java SortingCollection.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.samtools.util.SortingCollection
的用法示例。
在下文中一共展示了SortingCollection.add方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addRecord
import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
private synchronized void addRecord(final String barcode, final CLUSTER_OUTPUT_RECORD record) {
// Grab the existing collection, or initialize it if it doesn't yet exist
SortingCollection<CLUSTER_OUTPUT_RECORD> recordCollection = this.barcodeToRecordCollection.get(barcode);
if (recordCollection == null) {
// TODO: The implementation here for supporting ignoreUnexpectedBarcodes is not efficient,
// but the alternative is an extensive rewrite. We are living with the inefficiency for
// this special case for the time being.
if (!barcodeRecordWriterMap.containsKey(barcode)) {
if (ignoreUnexpectedBarcodes) {
return;
}
throw new PicardException(String.format("Read records with barcode %s, but this barcode was not expected. (Is it referenced in the parameters file?)", barcode));
}
recordCollection = newSortingCollection();
this.barcodeToRecordCollection.put(barcode, recordCollection);
}
recordCollection.add(record);
}
示例2: addRecord
import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
/**
* Adds the provided record to this tile.
*/
public synchronized void addRecord(final String barcode, final CLUSTER_OUTPUT_RECORD record) {
this.recordCount += 1;
// Grab the existing collection, or initialize it if it doesn't yet exist
SortingCollection<CLUSTER_OUTPUT_RECORD> recordCollection = this.barcodeToRecordCollection.get(barcode);
if (recordCollection == null) {
// TODO: The implementation here for supporting ignoreUnexpectedBarcodes is not efficient,
// but the alternative is an extensive rewrite. We are living with the inefficiency for
// this special case for the time being.
if (!barcodeRecordWriterMap.containsKey(barcode)) {
if (ignoreUnexpectedBarcodes) {
return;
}
throw new PicardException(String.format("Read records with barcode %s, but this barcode was not expected. (Is it referenced in the parameters file?)", barcode));
}
recordCollection = this.newSortingCollection();
this.barcodeToRecordCollection.put(barcode, recordCollection);
this.barcodeToProcessingState.put(barcode, null);
}
recordCollection.add(record);
}
示例3: 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;
}
示例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(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();
}
}
示例5: 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();
}
}
示例6: add
import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
void add(final SAMRecord rec) {
final SortingCollection<SAMRecord> sorter;
if (outputByReadGroup) {
sorter = sorterMap.get(rec.getReadGroup().getId());
} else {
sorter = singleSorter;
}
sorter.add(rec);
}
示例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();
}
示例8: 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();
}
}
示例9: 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();
}
}
}
示例10: 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();
}
}
}
示例11: 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;
}
示例12: 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);
}
}
示例13: 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();
}
}
示例14: put
import htsjdk.samtools.util.SortingCollection; //导入方法依赖的package包/类
/** insert all variant of vcfUri into the sorting collection */
protected Input put(final SortingCollection<LineAndFile> variants, String vcfUri)
throws IOException
{
LOG.info("begin inserting "+vcfUri);
LineIterator iter=null;
if(vcfUri==null)
{
vcfUri="stdin";
iter=IOUtils.openStreamForLineIterator(stdin());
}
else
{
iter=IOUtils.openFileForLineIterator(new File(vcfUri));
}
final List<String> headerLines=new ArrayList<String>();
while(iter.hasNext() && iter.peek().startsWith("#"))
{
headerLines.add(iter.next());
}
if(headerLines.isEmpty()) throw new IOException("Not header found in "+vcfUri);
final Input input=createInput(vcfUri, headerLines);
input.file_id=this.inputs.size();
this.inputs.add(input);
final SAMSequenceDictionaryProgress progress=new SAMSequenceDictionaryProgress(input.codecAndHeader.header.getSequenceDictionary());
while(iter.hasNext())
{
final String line=iter.next();
final LineAndFile laf=new LineAndFile();
laf.fileIdx=input.file_id;
laf.line=simplify(line,laf.fileIdx);
if(laf.line==null) continue;
progress.watch(laf.getChrom(), laf.getStart());
variants.add(laf);
input.count++;
}
progress.finish();
LOG.info("end inserting "+vcfUri+" N="+input.count);
CloserUtil.close(iter);
return input;
}