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


Java SAMFileWriter.addAlignment方法代码示例

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


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

示例1: writeToSlice

import htsjdk.samtools.SAMFileWriter; //导入方法依赖的package包/类
private static void writeToSlice(@NotNull final String path, @NotNull final SAMFileHeader header,
        @NotNull final CloseableIterator<SAMRecord> iterator) {
    final File outputBAM = new File(path);
    final SAMFileWriter writer = new SAMFileWriterFactory().setCreateIndex(true).makeBAMWriter(header, true, outputBAM);
    String contig = "";
    while (iterator.hasNext()) {
        final SAMRecord record = iterator.next();
        if (record.getContig() != null && !contig.equals(record.getContig())) {
            contig = record.getContig();
            LOGGER.info("Reading contig: {}", contig);
        }
        writer.addAlignment(record);
    }
    iterator.close();
    writer.close();
}
 
开发者ID:hartwigmedical,项目名称:hmftools,代码行数:17,代码来源:BamSlicerApplication.java

示例2: queryNameSortedBAM

import htsjdk.samtools.SAMFileWriter; //导入方法依赖的package包/类
private static File queryNameSortedBAM(final SamReader reader, final QueryInterval[] intervals, final String name) throws IOException {

        final SAMFileHeader header = reader.getFileHeader().clone();
        header.setSortOrder(SAMFileHeader.SortOrder.queryname);

        final File file = File.createTempFile(name, ".bam");
        final SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(header, false, file);

        final SAMRecordIterator iterator = reader.queryOverlapping(intervals);
        while (iterator.hasNext()) {
            writer.addAlignment(iterator.next());
        }

        iterator.close();
        writer.close();

        return file;
    }
 
开发者ID:hartwigmedical,项目名称:hmftools,代码行数:19,代码来源:Analysis.java

示例3: callElPrep

import htsjdk.samtools.SAMFileWriter; //导入方法依赖的package包/类
public int callElPrep(String input, String output, String rg, int threads, 
        SAMRecordIterator SAMit,
        SAMFileHeader header, String dictFile, boolean updateRG, boolean keepDups, String RGID) throws InterruptedException, QualityException {
    
    SAMRecord sam;
    SAMFileWriterFactory factory = new SAMFileWriterFactory();
    SAMFileWriter Swriter = factory.makeSAMWriter(header, true, new File(input));
    
    int reads = 0;
    while(SAMit.hasNext()) {
        sam = SAMit.next();
        if(updateRG)
            sam.setAttribute(SAMTag.RG.name(), RGID);
        Swriter.addAlignment(sam);
        reads++;
    }
    Swriter.close();
    
    String customArgs = HalvadeConf.getCustomArgs(context.getConfiguration(), "elprep", "");  
    String[] command = CommandGenerator.elPrep(bin, input, output, threads, true, rg, null, !keepDups, customArgs);
    long estimatedTime = runProcessAndWait("elPrep", command);
    if(context != null)
        context.getCounter(HalvadeCounters.TIME_ELPREP).increment(estimatedTime);
    
    return reads;
}
 
开发者ID:biointec,项目名称:halvade,代码行数:27,代码来源:PreprocessingTools.java

示例4: gatherNormally

import htsjdk.samtools.SAMFileWriter; //导入方法依赖的package包/类
/**
 * Simple implementation of a gather operations that uses SAMFileReaders and Writers in order to concatenate
 * multiple BAM files.
 */
private static void gatherNormally(final List<File> inputs, final File output, final boolean createIndex, final boolean createMd5,
                                   final File referenceFasta) {
    final SAMFileHeader header;
    {
        header = SamReaderFactory.makeDefault().referenceSequence(referenceFasta).getFileHeader(inputs.get(0));
    }

    final SAMFileWriter out = new SAMFileWriterFactory().setCreateIndex(createIndex).setCreateMd5File(createMd5).makeSAMOrBAMWriter(header, true, output);

    for (final File f : inputs) {
        log.info("Gathering " + f.getAbsolutePath());
        final SamReader in = SamReaderFactory.makeDefault().referenceSequence(referenceFasta).open(f);
        for (final SAMRecord rec : in) out.addAlignment(rec);
        CloserUtil.close(in);
    }

    out.close();
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:23,代码来源:GatherBamFiles.java

示例5: doWork

import htsjdk.samtools.SAMFileWriter; //导入方法依赖的package包/类
protected int doWork() {
    IOUtil.assertFileIsReadable(INPUT);
    IOUtil.assertFileIsWritable(OUTPUT);
    final SamReader reader = SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE).open(INPUT);
    ;
    reader.getFileHeader().setSortOrder(SORT_ORDER.getSortOrder());
    final SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(reader.getFileHeader(), false, OUTPUT);
    writer.setProgressLogger(
            new ProgressLogger(log, (int) 1e7, "Wrote", "records from a sorting collection"));

    final ProgressLogger progress = new ProgressLogger(log, (int) 1e7, "Read");
    for (final SAMRecord rec : reader) {
        writer.addAlignment(rec);
        progress.record(rec);
    }

    log.info("Finished reading inputs, merging and writing to output now.");

    CloserUtil.close(reader);
    writer.close();
    return 0;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:23,代码来源:SortSam.java

示例6: standardReheader

import htsjdk.samtools.SAMFileWriter; //导入方法依赖的package包/类
private void standardReheader(final SAMFileHeader replacementHeader) {
    final SamReader recordReader = SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE).validationStringency(ValidationStringency.SILENT).open(INPUT);
    if (replacementHeader.getSortOrder() != recordReader.getFileHeader().getSortOrder()) {
        throw new PicardException("Sort orders of INPUT (" + recordReader.getFileHeader().getSortOrder().name() +
                ") and HEADER (" + replacementHeader.getSortOrder().name() + ") do not agree.");
    }
    final SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(replacementHeader, true, OUTPUT);

    final ProgressLogger progress = new ProgressLogger(Log.getInstance(ReplaceSamHeader.class));
    for (final SAMRecord rec : recordReader) {
        rec.setHeader(replacementHeader);
        writer.addAlignment(rec);
        progress.record(rec);
    }
    writer.close();
    CloserUtil.close(recordReader);
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:18,代码来源:ReplaceSamHeader.java

示例7: sortSamBam

import htsjdk.samtools.SAMFileWriter; //导入方法依赖的package包/类
public static void sortSamBam(File samBamFile, File sortedBamFile) {
	
	SAMFileReader.setDefaultValidationStringency(ValidationStringency.SILENT);
	SAMFileReader reader = new SAMFileReader(IOUtil.openFileForReading(samBamFile));
	SAMFileWriter writer = null;
	try {
		
		reader.getFileHeader().setSortOrder(SAMFileHeader.SortOrder.coordinate);
		writer = new SAMFileWriterFactory().makeBAMWriter(reader.getFileHeader(), false, sortedBamFile);
		Iterator<SAMRecord> iterator = reader.iterator();
		while (iterator.hasNext()) {
			writer.addAlignment(iterator.next());
		}
		
	} finally {
		closeIfPossible(reader);
		closeIfPossible(writer);
	}
}
 
开发者ID:chipster,项目名称:chipster,代码行数:20,代码来源:SamBamUtils.java

示例8: printSamBam

import htsjdk.samtools.SAMFileWriter; //导入方法依赖的package包/类
public String printSamBam(InputStream samBamStream, int maxRecords) throws IOException {
	SAMFileReader.setDefaultValidationStringency(ValidationStringency.SILENT);
	SAMFileReader in = new SAMFileReader(samBamStream);
	SAMFileHeader header = in.getFileHeader();
	ByteArrayOutputStream buffer = new ByteArrayOutputStream();
	SAMFileWriter out = new SAMFileWriterFactory().makeSAMWriter(header, true, buffer);
	int i = 0;
	try {
		for (final SAMRecord rec : in) {
			if (i > maxRecords) {
				break;
			}
			out.addAlignment(rec);
			i++;
		}
	} finally {
		closeIfPossible(out);
	}

	if (i > maxRecords) {
		buffer.write("SAM/BAM too long for viewing, truncated here!\n".getBytes());
	}
	
	return buffer.toString();
}
 
开发者ID:chipster,项目名称:chipster,代码行数:26,代码来源:SamBamUtils.java

示例9: createArtificialBamFile

import htsjdk.samtools.SAMFileWriter; //导入方法依赖的package包/类
/**
 * create an artificial sam file
 *
 * @param filename            the filename to write to
 * @param numberOfChromosomes the number of chromosomes
 * @param startingChromosome  where to start counting
 * @param chromosomeSize      how large each chromosome is
 * @param readsPerChomosome   how many reads to make in each chromosome.  They'll be aligned from position 1 to x (which is the number of reads)
 */
public static void createArtificialBamFile(String filename, int numberOfChromosomes, int startingChromosome, int chromosomeSize, int readsPerChomosome) {
    SAMFileHeader header = createArtificialSamHeader(numberOfChromosomes, startingChromosome, chromosomeSize);
    File outFile = new File(filename);

    SAMFileWriter out = new SAMFileWriterFactory().makeBAMWriter(header, true, outFile);

    for (int x = startingChromosome; x < startingChromosome + numberOfChromosomes; x++) {
        for (int readNumber = 1; readNumber < readsPerChomosome; readNumber++) {
            out.addAlignment(createArtificialRead(header, "Read_" + readNumber, x - startingChromosome, readNumber, DEFAULT_READ_LENGTH));
        }
    }

    out.close();
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:24,代码来源:ArtificialSAMUtils.java

示例10: createArtificialSamFile

import htsjdk.samtools.SAMFileWriter; //导入方法依赖的package包/类
/**
 * create an artificial sam file
 *
 * @param filename            the filename to write to
 * @param numberOfChromosomes the number of chromosomes
 * @param startingChromosome  where to start counting
 * @param chromosomeSize      how large each chromosome is
 * @param readsPerChomosome   how many reads to make in each chromosome.  They'll be aligned from position 1 to x (which is the number of reads)
 */
public static void createArtificialSamFile(String filename, int numberOfChromosomes, int startingChromosome, int chromosomeSize, int readsPerChomosome) {
    SAMFileHeader header = createArtificialSamHeader(numberOfChromosomes, startingChromosome, chromosomeSize);
    File outFile = new File(filename);

    SAMFileWriter out = new SAMFileWriterFactory().makeSAMWriter(header, false, outFile);

    for (int x = startingChromosome; x < startingChromosome + numberOfChromosomes; x++) {
        for (int readNumber = 1; readNumber <= readsPerChomosome; readNumber++) {
            out.addAlignment(createArtificialRead(header, "Read_" + readNumber, x - startingChromosome, readNumber, 100));
        }
    }

    out.close();
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:24,代码来源:ArtificialSAMUtils.java

示例11: writeToSlice

import htsjdk.samtools.SAMFileWriter; //导入方法依赖的package包/类
private static void writeToSlice(final String path, final SamReader reader, final QueryInterval[] intervals) {
    final File outputBAM = new File(path);
    final SAMFileWriter writer = new SAMFileWriterFactory().makeBAMWriter(reader.getFileHeader(), true, outputBAM);
    final SAMRecordIterator iterator = reader.queryOverlapping(intervals);
    while (iterator.hasNext()) {
        writer.addAlignment(iterator.next());
    }
    iterator.close();
    writer.close();
}
 
开发者ID:hartwigmedical,项目名称:hmftools,代码行数:11,代码来源:BreakPointInspectorApplication.java

示例12: sortAndIndexSamOrBam

import htsjdk.samtools.SAMFileWriter; //导入方法依赖的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

示例13: merge

import htsjdk.samtools.SAMFileWriter; //导入方法依赖的package包/类
@Override
public void merge(final Iterator<DataFile> inFileIterator,
    final DataFile outFile) throws IOException {

  // Get temporary directory
  final File tmpDir = EoulsanRuntime.getRuntime().getTempDirectory();

  SAMFileWriter outputSam = null;

  while (inFileIterator.hasNext()) {

    // Get input file
    final DataFile inFile = inFileIterator.next();

    EoulsanLogger.getLogger()
        .info("Merge " + inFile.getName() + " to " + outFile.getName());

    // Get reader
    final SamReader inputSam = SamReaderFactory.makeDefault()
        .open(SamInputResource.of(inFile.open()));

    // Get Writer
    if (outputSam == null) {

      outputSam = new SAMFileWriterFactory().setTempDirectory(tmpDir)
          .makeSAMWriter(inputSam.getFileHeader(), false, outFile.create());
    }

    // Write all the entries of the input file to the output file
    for (SAMRecord samRecord : inputSam) {
      outputSam.addAlignment(samRecord);
    }

    inputSam.close();
  }

  outputSam.close();
}
 
开发者ID:GenomicParisCentre,项目名称:eoulsan,代码行数:39,代码来源:SAMMerger.java

示例14: addAlignment

import htsjdk.samtools.SAMFileWriter; //导入方法依赖的package包/类
void addAlignment(final SAMRecord rec) {
    final SAMFileWriter writer;
    if (outputByReadGroup) {
        writer = writerMap.get(rec.getReadGroup().getId());
    } else {
        writer = singleWriter;
    }
    writer.addAlignment(rec);
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:10,代码来源:RevertSam.java

示例15: doUnpaired

import htsjdk.samtools.SAMFileWriter; //导入方法依赖的package包/类
/** Creates a simple SAM file from a single fastq file. */
protected int doUnpaired(final FastqReader freader, final SAMFileWriter writer) {
    int readCount = 0;
    final ProgressLogger progress = new ProgressLogger(LOG);
    for ( ; freader.hasNext()  ; readCount++) {
        final FastqRecord frec = freader.next();
        final SAMRecord srec = createSamRecord(writer.getFileHeader(), SequenceUtil.getSamReadNameFromFastqHeader(frec.getReadHeader()) , frec, false) ;
        srec.setReadPairedFlag(false);
        writer.addAlignment(srec);
        progress.record(srec);
    }

    return readCount;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:15,代码来源:FastqToSam.java


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