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


Java VCFCodec类代码示例

本文整理汇总了Java中htsjdk.variant.vcf.VCFCodec的典型用法代码示例。如果您正苦于以下问题:Java VCFCodec类的具体用法?Java VCFCodec怎么用?Java VCFCodec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: RODContentProvider

import htsjdk.variant.vcf.VCFCodec; //导入依赖的package包/类
public RODContentProvider(String name, VcfRecordPartition partition, GenomeLocParser genomeLocParser) {
    this.name = name;
    VCFCodec codec = new VCFCodec();
    VCFHeaderLineIterable headerLineIterable = new VCFHeaderLineIterable(partition.vcfHeader());
    vcfFileHeader = (VCFHeader) codec.readActualHeader(headerLineIterable);

    ArrayList<VariantContext> vcfRecords = new ArrayList<>();
    CollectionConverter.asJavaList(partition.records())
            .forEach(record -> vcfRecords.add(codec.decode(record.toString())));

    //为vcfRecord进行排序
    Collections.sort(vcfRecords,
            (record1, record2) -> record1.getStart() - record2.getStart());

    vcfRecords.forEach(context ->
            features.add(new GATKFeature.TribbleGATKFeature(genomeLocParser, context, name)));
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:18,代码来源:RODContentProvider.java

示例2: getStaticDataInstance

import htsjdk.variant.vcf.VCFCodec; //导入依赖的package包/类
public static StaticData getStaticDataInstance(RefContigInfo refContigInfo,
                                               boolean useGVCF,
                                               SamHeaderInfo samHeaderInfo,
                                               VcfHeaderInfo vcfHeaderInfo) {
    StaticData data = new StaticData();
    SAMSequenceDictionary samSequenceDictionary = SAMSequenceDictTransfer.transfer(refContigInfo);
    data.genomeLocParser = new GenomeLocParser(samSequenceDictionary);
    samHeaderInfo.addReadGroupInfo(ReadGroupInfo.apply("rg1", "sample1"));
    SAMFileHeader header = SAMHeaderTransfer.transfer(samHeaderInfo);
    List<SAMReadGroupRecord> readGroupInfos = header.getReadGroups();
    List<String> samples = new ArrayList<>();
    for (SAMReadGroupRecord readGroup : readGroupInfos) {
        samples.add(readGroup.getSample());
    }
    data.haplotypeCaller = new HaplotypeCaller(data.genomeLocParser, samples, useGVCF);
    data.basic2SAMRecordTransfer = new Basic2SAMRecordTransfer(header);

    VCFCodec codec = new VCFCodec();
    VCFHeaderLineIterable headerLineIterable = new VCFHeaderLineIterable(vcfHeaderInfo);
    data.vcfFileHeader = (VCFHeader) codec.readActualHeader(headerLineIterable);
    data.codec = codec;
    return data;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:24,代码来源:HaplotypeCallerAdapter.java

示例3: toActiveRegionMapData

import htsjdk.variant.vcf.VCFCodec; //导入依赖的package包/类
public ActiveRegionMapData toActiveRegionMapData(GenomeLocParser parser,
                                                 Basic2SAMRecordTransfer samTransfer,
                                                 VCFHeader vcfFileHeader,
                                                 VCFCodec codec) {
    List<GATKSAMRecord> gatksamRecords = new ArrayList<>(reads.size());
    for (BasicSamRecord record : reads) {
        gatksamRecords.add(new GATKSAMRecord(samTransfer.transfer(record)));
    }
    this.activeRegion.setReads(gatksamRecords);
    this.activeRegion.setGenomeLocParser(parser);

    List<VariantContext> vcs = new ArrayList<>(rods.size());
    for (VcfRecord vcfRecord : rods) {
        vcs.add(codec.decode(vcfRecord.toString()));
    }
    RODContentProvider dbsnpProvider = new RODContentProvider(RODNames.DBSNP, vcfFileHeader, vcs, parser);
    RODTraverser traverser = new RODTraverser(dbsnpProvider);
    final List<RODRecordList> bindings = new ArrayList<>(1);
    bindings.add(traverser.getOverlap(activeRegion.getExtendedLoc()));
    RefMetaDataTracker tracker = new RefMetaDataTracker(bindings);

    return new ActiveRegionMapData(activeRegion, tracker, fullReferenceWithPadding, refBases);
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:24,代码来源:SerializableActiveRegionMapData.java

示例4: readVariations

import htsjdk.variant.vcf.VCFCodec; //导入依赖的package包/类
/**
 * Reads the variations data from the VCF file and loads it into a track
 * @param vcfFile data source
 * @param track for loading data
 * @param chromosome reference sequence
 * @param sampleIndex determines fro which sample from the file variations are loaded
 * @param loadInfo if true data from the INFO fields from VCF file will be loaded into the track,
 *                 otherwise it will be ignored
 * @return {@code Track} filled with variations from a specified {@code VcfFile}
 * @throws VcfReadingException
 */
@Override
public Track<Variation> readVariations(VcfFile vcfFile, final Track<Variation> track, Chromosome chromosome,
                                       final Integer sampleIndex, final boolean loadInfo, final boolean collapse)
        throws VcfReadingException {
    try (FeatureReader<VariantContext> reader = AbstractFeatureReader.getFeatureReader(vcfFile.getPath(),
            vcfFile.getIndex().getPath(), new VCFCodec(), true)) {
        if (checkBounds(vcfFile, track, chromosome, loadInfo)) {
            return track;
        }
        try (CloseableIterator<VariantContext> iterator = Utils.query(reader, chromosome.getName(), track
                .getStartIndex(), track.getEndIndex())) {
            VCFHeader header = (VCFHeader) reader.getHeader();
            track.setBlocks(doReadVariations(iterator, track, header, vcfFile, sampleIndex, loadInfo, collapse));
        }
    } catch (IOException e) {
        throw new VcfReadingException(vcfFile, e);
    }
    return track;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:31,代码来源:VcfFileReader.java

示例5: makeVcfReader

import htsjdk.variant.vcf.VCFCodec; //导入依赖的package包/类
/**
 * Create a VCFFile reader for given reference and fileName in application's file system, optionally uses index.
 *
 * @param vcfFile  {@code VcfFile} a VcfFile object, representing a file in the system with set id, name and
 *                 compressed options.
 * @return {@code VCFFileReader} a reader to work with VCF file
 */
public FeatureReader<VariantContext> makeVcfReader(VcfFile vcfFile) {
    File file = new File(vcfFile.getPath());
    Assert.isTrue(file.exists(), getMessage(MessagesConstants.ERROR_FILE_NOT_FOUND, vcfFile.getPath()));

    FeatureReader<VariantContext> reader;
    double time1;
    double time2;
    if (vcfFile.getIndex() != null && StringUtils.isNotBlank(vcfFile.getIndex().getPath())) {
        Assert.notNull(vcfFile.getIndex(), "VCF file should have an index");
        File indexFile = new File(vcfFile.getIndex().getPath());
        Assert.isTrue(indexFile.exists(), getMessage(MessagesConstants.ERROR_FILE_NOT_FOUND,
                                                     vcfFile.getIndex().getPath()));
        time1 = Utils.getSystemTimeMilliseconds();
        reader = AbstractFeatureReader.getFeatureReader(vcfFile.getPath(), vcfFile.getIndex().getPath(),
                                                        new VCFCodec(), true);
        time2 = Utils.getSystemTimeMilliseconds();
    } else {
        time1 = Utils.getSystemTimeMilliseconds();
        reader = AbstractFeatureReader.getFeatureReader(vcfFile.getPath(), new VCFCodec(), false);
        time2 = Utils.getSystemTimeMilliseconds();
    }
    LOGGER.debug(getMessage(MessagesConstants.DEBUG_FILE_OPENING, vcfFile.getPath(), time2 - time1));
    return reader;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:32,代码来源:FileManager.java

示例6: readSingleHeader

import htsjdk.variant.vcf.VCFCodec; //导入依赖的package包/类
public void readSingleHeader(Path vcfPath, Configuration conf) throws IOException {
	FileSystem fs = vcfPath.getFileSystem(conf);
	if(!fs.exists(vcfPath))
		throw new RuntimeException(vcfPath.toString() + " don't exists.");
	if(!fs.isFile(vcfPath)) {
		throw new RuntimeException(vcfPath.toString() + " is not a file. GaeaSingleVcfHeader parser only support one vcf file.");
	}
	FSDataInputStream in = fs.open(vcfPath);
	AsciiLineReaderIterator it = new AsciiLineReaderIterator(new AsciiLineReader(in));
    VCFCodec codec = new VCFCodec();
    Object header = codec.readHeader(it);
	vcfHeader = (VCFHeader)(((FeatureCodecHeader)header).getHeaderValue());
	sampleNames.addAll(vcfHeader.getGenotypeSamples());
	buildHeaderInfo();
	it.close();
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:17,代码来源:SingleVCFHeader.java

示例7: processSV

import htsjdk.variant.vcf.VCFCodec; //导入依赖的package包/类
private static Collection<EligibilityReport> processSV(final String patient, final File vcf, final BachelorEligibility eligibility) {
    LOGGER.info("process sv: {}", vcf.getPath());

    final StructuralVariantFactory factory = new StructuralVariantFactory();
    try {
        try (final AbstractFeatureReader<VariantContext, LineIterator> reader = AbstractFeatureReader.getFeatureReader(vcf.getPath(),
                new VCFCodec(), false)) {
            reader.iterator().forEach(factory::addVariantContext);
        }
    } catch (IOException e) {
        LOGGER.error("error with SV file {}: {}", vcf.getPath(), e.getMessage());
        return Collections.emptyList();
    }

    return eligibility.processStructuralVariants(patient, factory.results());
}
 
开发者ID:hartwigmedical,项目名称:hmftools,代码行数:17,代码来源:BachelorApplication.java

示例8: fromVCFFile

import htsjdk.variant.vcf.VCFCodec; //导入依赖的package包/类
@NotNull
public List<SomaticVariant> fromVCFFile(@NotNull final String sample, @NotNull final String vcfFile) throws IOException {
    final List<SomaticVariant> variants = Lists.newArrayList();

    try (final AbstractFeatureReader<VariantContext, LineIterator> reader = getFeatureReader(vcfFile, new VCFCodec(), false)) {

        final VCFHeader header = (VCFHeader) reader.getHeader();
        if (!sampleInFile(sample, header)) {
            throw new IllegalArgumentException("Sample " + sample + " not found in vcf file " + vcfFile);
        }

        if (!header.hasFormatLine("AD")) {
            throw new IllegalArgumentException("Allelic depths is a required format field in vcf file " + vcfFile);
        }

        for (final VariantContext context : reader.iterator()) {
            createVariant(sample, context).ifPresent(variants::add);
        }
    }

    return variants;
}
 
开发者ID:hartwigmedical,项目名称:hmftools,代码行数:23,代码来源:SomaticVariantFactory.java

示例9: addLineToIndex

import htsjdk.variant.vcf.VCFCodec; //导入依赖的package包/类
/** Set vcfHeader and vcfCodec to null if reading non-vcf line.
 * */
private void addLineToIndex(String line, TabixIndexCreator indexCreator, long filePosition, TabixFormat fmt, VCFHeader vcfHeader, VCFCodec vcfCodec) throws InvalidRecordException {

	if(fmt.equals(TabixFormat.BED)){
		
		BedLineCodec bedCodec= new BedLineCodec();
		BedLine bed = bedCodec.decode(line);
		indexCreator.addFeature(bed, filePosition);
	
	} else if(fmt.equals(TabixFormat.GFF)){
		GtfLine gtf= new GtfLine(line.split("\t"));
		indexCreator.addFeature(gtf, filePosition);
	
	} else if(fmt.equals(TabixFormat.VCF)) {

		VariantContext vcf = vcfCodec.decode(line);
		indexCreator.addFeature(vcf, filePosition);
		
	} else {
		System.err.println("Unexpected TabixFormat: " + fmt.sequenceColumn + " " + fmt.startPositionColumn);
		throw new InvalidRecordException();
	}	
}
 
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:25,代码来源:MakeTabixIndex.java

示例10: IntervalFeature

import htsjdk.variant.vcf.VCFCodec; //导入依赖的package包/类
/**
 * Create an IntervalFeature from a String. Typically this is a line read from file.
 * vcfHeader can be null if trackformat is not VCF.
 */
public IntervalFeature(String line, TrackFormat format, VCFCodec vcfCodec) throws InvalidGenomicCoordsException{
	if(format.equals(TrackFormat.BED) || format.equals(TrackFormat.BEDGRAPH) || format.equals(TrackFormat.BIGBED)){
		this.intervalFeatureFromBedLine(line);
		this.trackFormat= TrackFormat.BED;
	
	} else if(format.equals(TrackFormat.GFF) || format.equals(TrackFormat.GTF)){
		this.intervalFeatureFromGtfLine(line);
		this.trackFormat= TrackFormat.GFF;
				
	} else if(format.equals(TrackFormat.VCF)) {
		this.variantContext= vcfCodec.decode(line);
		this.setRaw(line);
		this.trackFormat= TrackFormat.VCF;
		this.chrom= this.variantContext.getContig();
		this.from= this.setFromForVCF();
		this.to= this.setToForVCF();
		this.name= this.variantContext.getID();

	} else {
		System.err.println("Format " + format + " not supported");
		throw new RuntimeException();
	}
}
 
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:28,代码来源:IntervalFeature.java

示例11: canFormatVCFLineStructVar

import htsjdk.variant.vcf.VCFCodec; //导入依赖的package包/类
@Test
public void canFormatVCFLineStructVar() throws InvalidGenomicCoordsException, InvalidColourException, IOException, InvalidConfigException{
	
	List<Double> rulerMap= new ArrayList<Double>();
	for(int i= 1; i < 100; i++){
		rulerMap.add((double)i);
	}
	
	// Prepare header
	VCFFileReader reader = new VCFFileReader(new File("test_data/ALL.wgs.mergedSV.v8.20130502.svs.genotypes.vcf.gz"));
	VCFHeader vcfHeader= reader.getFileHeader();
	reader.close();
	VCFCodec vcfCodec= new VCFCodec();
	vcfCodec.setVCFHeader(vcfHeader, Utils.getVCFHeaderVersion(vcfHeader));

	String vcfLine= "1 668630 DUP_delly_DUP20532 G <CN2> . PASS AC=64;AF=0.0127795;AFR_AF=0.0015;AMR_AF=0;AN=5008;CIEND=-150,150;CIPOS=-150,150;CS=DUP_delly;EAS_AF=0.0595;END=850204;EUR_AF=0.001;IMPRECISE;NS=2504;SAS_AF=0.001;SITEPOST=1;SVTYPE=DUP GT 0|0 0|0 0|0".replaceAll(" ", "\t");
	IntervalFeature ift= new IntervalFeature(vcfLine, TrackFormat.VCF, vcfCodec);
	ift.mapToScreen(rulerMap);
	assertEquals(850204, ift.getTo());
	assertEquals("|", ift.getIdeogram(true, true).get(0).format(true));
}
 
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:22,代码来源:IntervalFeatureTest.java

示例12: reindexVcfFile

import htsjdk.variant.vcf.VCFCodec; //导入依赖的package包/类
/**
 * Creates a feature index for {@link VcfFile}. If an index already exists, it will be deleted and created
 * from scratch
 * @param vcfFileId an ID of VCF file to reindex.
 * @throws FeatureIndexException if an error occurred while writing index
 */
public VcfFile reindexVcfFile(long vcfFileId) throws FeatureIndexException {
    VcfFile vcfFile = vcfFileManager.loadVcfFile(vcfFileId);
    Reference reference = referenceGenomeManager.loadReferenceGenome(vcfFile.getReferenceId());
    Map<String, Chromosome> chromosomeMap = reference.getChromosomes().stream().collect(
        Collectors.toMap(BaseEntity::getName, chromosome -> chromosome));
    List<GeneFile> geneFiles = reference.getGeneFile() != null ?
                               Collections.singletonList(reference.getGeneFile()) :
                               Collections.emptyList();

    try {
        fileManager.deleteFileFeatureIndex(vcfFile);

        try (FeatureReader<VariantContext> reader = AbstractFeatureReader.getFeatureReader(vcfFile.getPath(),
                                                                                           new VCFCodec(), false)) {
            VcfFilterInfo info = getFiltersInfo(reader);
            featureIndexManager.makeIndexForVcfReader(vcfFile, reader, geneFiles, chromosomeMap, info);
        }
    } catch (IOException e) {
        throw new FeatureIndexException(vcfFile, e);
    }

    return vcfFile;
}
 
开发者ID:epam,项目名称:NGB,代码行数:30,代码来源:VcfManager.java

示例13: createVcfFromUrl

import htsjdk.variant.vcf.VCFCodec; //导入依赖的package包/类
private VcfFile createVcfFromUrl(final IndexedFileRegistrationRequest request,
                                  final Map<String, Chromosome> chromosomeMap, Reference reference) {
    final VcfFile vcfFile;
    try (FeatureReader<VariantContext> reader = AbstractFeatureReader.getFeatureReader(request.getPath(),
                                       request.getIndexPath(), new VCFCodec(), true)) {
        vcfFile = createVcfFile(request, reader);
        boolean hasVariations = false;
        for (Map.Entry<String, Chromosome> chrEntry : chromosomeMap.entrySet()) {
            CloseableIterator<VariantContext> iterator = Utils.query(reader, chrEntry.getKey(), 1,
                                                                     chrEntry.getValue().getSize());
            if (iterator.hasNext()) {
                hasVariations = true;
                break;
            }
        }

        Assert.isTrue(hasVariations, getMessage(MessagesConstants.ERROR_FILE_CORRUPTED_OR_EMPTY, request.getPath(),
                                                reference.getName()));
    }  catch (IOException e) {
        throw new RegistrationException(getMessage(ERROR_REGISTER_FILE, request.getName()), e);
    }
    biologicalDataItemManager.createBiologicalDataItem(vcfFile.getIndex());
    vcfFileManager.createVcfFile(vcfFile);
    return vcfFile;
}
 
开发者ID:epam,项目名称:NGB,代码行数:26,代码来源:VcfManager.java

示例14: serialisationTest

import htsjdk.variant.vcf.VCFCodec; //导入依赖的package包/类
@Test
public void serialisationTest() throws IOException, ClassNotFoundException {
    Resource resource = context.getResource("classpath:templates/samples.vcf");
    List<VcfIndexEntry> writtenEntries = new ArrayList<>();
    List<VcfIndexEntry> diskBasedList = new DiskBasedList<VcfIndexEntry>(MAX_IN_MEMORY_ITEMS_COUNT).adaptToList();

    try (FeatureReader<VariantContext> reader = AbstractFeatureReader
            .getFeatureReader(resource.getFile().getAbsolutePath(), new VCFCodec(), false)
    ) {

        for (VariantContext variantContext : reader.iterator()) {

            VcfIndexEntry vcfIndexEntry = createTestEntry(variantContext);

            writtenEntries.add(vcfIndexEntry);
            diskBasedList.add(vcfIndexEntry);
        }
    }

    for (int i = 0; i < 3; i++) {
        assertLists(writtenEntries, diskBasedList);
    }

}
 
开发者ID:epam,项目名称:NGB,代码行数:25,代码来源:DiskBasedListTest.java

示例15: testVariantAdapter

import htsjdk.variant.vcf.VCFCodec; //导入依赖的package包/类
@Test(dataProvider = "VariantDataProvider")
public void testVariantAdapter(final List<Variant> expectedVariantList) {
    // The test suite for reading in VCF files is FeatureDataSourceUnitTest.
    try (FeatureDataSource<VariantContext> featureSource = new FeatureDataSource<>(QUERY_TEST_VCF, new VCFCodec())) {
        List<Variant> variantList = new ArrayList<>();
        for (VariantContext feature : featureSource) {
            VariantContextVariantAdapter va = new VariantContextVariantAdapter(feature);
            variantList.add(va);
        }
        // Now, test to see that every variant is in in the expected set.
        Assert.assertEquals(variantList.size(), expectedVariantList.size());
        for (Variant v : variantList) {
            boolean matchFound = false;
            for (Variant vv : expectedVariantList) {
                if (VariantUtils.variantsAreEqual(v, vv)) {
                    matchFound = true;
                }
            }
            Assert.assertTrue(matchFound, v.toString());
        }
    }
}
 
开发者ID:broadinstitute,项目名称:gatk-dataflow,代码行数:23,代码来源:VariantSourceUnitTest.java


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