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


Java SAMFileHeader.setReadGroups方法代码示例

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


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

示例1: transfer

import htsjdk.samtools.SAMFileHeader; //导入方法依赖的package包/类
public static SAMFileHeader transfer(SamHeaderInfo samHeaderInfo){
    SAMFileHeader header = new SAMFileHeader();
    // read groups
    List<ReadGroupInfo> readGroupInfoList = CollectionConverter.asJavaList(samHeaderInfo.getReadGroupInfos());
    List<SAMReadGroupRecord> samReadGroupRecords = readGroupInfoList.stream()
            .map(SAMReadGroupRecordTransfer::transfer)
            .collect(Collectors.toList());
    header.setReadGroups(samReadGroupRecords);
    // Sequence records
    // TODO 获取id的方法不通用 fix me
    int contigCount = samHeaderInfo.getRefContigInfo().getContigIds().size();
    for(int id = 0; id < contigCount; id ++) {
        header.addSequence(new SAMSequenceRecord(
                samHeaderInfo.getRefContigInfo().getName(id),
                samHeaderInfo.getRefContigInfo().getLength(id)));
    }
    if(samHeaderInfo.sorted()) {
        header.setAttribute("SO", "coordinate");
    }
    return header;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:22,代码来源:SAMHeaderTransfer.java

示例2: createEnumeratedReadGroups

import htsjdk.samtools.SAMFileHeader; //导入方法依赖的package包/类
/**
 * setup read groups for the specified read groups and sample names
 *
 * @param header       the header to set
 * @param readGroupIDs the read group ID tags
 * @param sampleNames  the sample names
 * @return the adjusted SAMFileHeader
 */
public static SAMFileHeader createEnumeratedReadGroups(SAMFileHeader header, List<String> readGroupIDs, List<String> sampleNames) {
    if (readGroupIDs.size() != sampleNames.size()) {
        throw new ReviewedGATKException("read group count and sample name count must be the same");
    }

    List<SAMReadGroupRecord> readGroups = new ArrayList<SAMReadGroupRecord>();

    int x = 0;
    for (; x < readGroupIDs.size(); x++) {
        SAMReadGroupRecord rec = new SAMReadGroupRecord(readGroupIDs.get(x));
        rec.setSample(sampleNames.get(x));
        readGroups.add(rec);
    }
    header.setReadGroups(readGroups);
    return header;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:25,代码来源:ArtificialSAMUtils.java

示例3: createDefaultReadGroup

import htsjdk.samtools.SAMFileHeader; //导入方法依赖的package包/类
/**
 * setup a default read group for a SAMFileHeader
 *
 * @param header      the header to set
 * @param readGroupID the read group ID tag
 * @param sampleName  the sample name
 * @return the adjusted SAMFileHeader
 */
public static SAMFileHeader createDefaultReadGroup(SAMFileHeader header, String readGroupID, String sampleName) {
    SAMReadGroupRecord rec = new SAMReadGroupRecord(readGroupID);
    rec.setSample(sampleName);
    List<SAMReadGroupRecord> readGroups = new ArrayList<SAMReadGroupRecord>();
    readGroups.add(rec);
    header.setReadGroups(readGroups);
    return header;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:17,代码来源:ArtificialSAMUtils.java

示例4: createHeaderFromSampleName

import htsjdk.samtools.SAMFileHeader; //导入方法依赖的package包/类
public static SAMFileHeader createHeaderFromSampleName(
		SAMFileHeader header, String sampleName) {
	SAMFileHeader newHeader = header.clone();
	List<SAMReadGroupRecord> groups = header.getReadGroups();
	List<SAMReadGroupRecord> rgroups = new ArrayList<SAMReadGroupRecord>(
			groups.size());

	for (SAMReadGroupRecord g : groups) {
		if (g.getSample().equals(sampleName))
			rgroups.add(g);
	}
	newHeader.setReadGroups(rgroups);
	return newHeader;
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:15,代码来源:SamFileHeader.java

示例5: onTraversalStart

import htsjdk.samtools.SAMFileHeader; //导入方法依赖的package包/类
/**
 * Initializes:
 * - The transformer for fix the barcodes in the name.
 * - Decoder to use for assign barcodes.
 * - Writers for output (including discarded).
 */
@Override
public void onTraversalStart() {
    // setting up the barcode decoder engine
    decoder = barcodeDetectorArgumentCollection.getBarcodeDecoder();

    // update with the read groups in the decoder and the unknown
    final SAMFileHeader headerForWriter = getHeaderForReads().clone();
    if (!headerForWriter.getReadGroups().isEmpty()) {
        logger.warn("Read group in the input file(s) will be removed in the output.");
    }
    headerForWriter.setReadGroups(decoder.getDictionary().getSampleReadGroups());

    // output the writer
    writer = outputBamArgumentCollection.outputWriter(headerForWriter,
            () -> getProgramRecord(headerForWriter), true, getReferenceFile()
    );

    // discarded writer
    discardedWriter = (keepDiscarded)
            ? discardedWriter = outputBamArgumentCollection.getWriterFactory()
            .setReferenceFile(getReferenceFile())
            .createWriter(outputBamArgumentCollection
                            .getOutputNameWithSuffix(RTDefaults.DISCARDED_OUTPUT_SUFFIX),
                    getHeaderForReads(), true)
            : new NullGATKWriter();
}
 
开发者ID:magicDGS,项目名称:ReadTools,代码行数:33,代码来源:AssignReadGroupByBarcode.java

示例6: testWriteAndReadSplitBySample

import htsjdk.samtools.SAMFileHeader; //导入方法依赖的package包/类
@Test
public void testWriteAndReadSplitBySample() throws Exception {
    final File testPrefix = new File(createTestTempDir("testNoNewOutputWhenRepeatedSplitBy"),
            "testNoNewOutputWhenRepeatedSplitBy");
    // set the read groups
    final List<SAMReadGroupRecord> readGroups = IntStream.range(0, 5).mapToObj(n -> {
        final SAMReadGroupRecord rg = new SAMReadGroupRecord(String.valueOf(n));
            rg.setSample((n == 0) ? "unique" : "multiple");
        return rg;
    }).collect(Collectors.toList());
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader();
    header.setReadGroups(readGroups);

    // expected files
    final File uniqueFile = new File(testPrefix + "_unique.sam");
    final File multipleFile = new File(testPrefix + "_multiple.sam");

    // they should not be there
    Assert.assertFalse(uniqueFile.exists());
    Assert.assertFalse(multipleFile.exists());

    // open the writer and create files
    final SplitGATKWriter writer = new SplitGATKWriter(testPrefix.getAbsolutePath(),
            ReadToolsIOFormat.BamFormat.SAM,
            Collections.singletonList(new SampleNameSplitter()),
            header, true, new ReadWriterFactory(), false);

    final List<GATKRead> multipleReads = readGroups.stream().map(rg -> {
        final GATKRead read = ArtificialReadUtils.createArtificialRead("1M");
        read.setReadGroup(rg.getReadGroupId());
        writer.addRead(read);
        return read;
    }).filter(read -> !read.getReadGroup().equals("0")).collect(Collectors.toList());
    writer.close();

    // assert files were created
    Assert.assertTrue(uniqueFile.exists());
    Assert.assertTrue(multipleFile.exists());

    // test the multiple
    try (final SamReader reader = new ReadReaderFactory().openSamReader(multipleFile)) {
        Assert.assertEquals(reader.getFileHeader(), header);
        final Iterator<SAMRecord> it = reader.iterator();
        multipleReads.forEach(r -> Assert.assertEquals(it.next(), r.convertToSAMRecord(header)));
        Assert.assertFalse(it.hasNext());
    }
}
 
开发者ID:magicDGS,项目名称:ReadTools,代码行数:48,代码来源:SplitGATKWriterUnitTest.java


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