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


Java ReferenceSequenceFileFactory类代码示例

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


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

示例1: nibFileAndFastaFileIdenticalTest

import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
@Test @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void nibFileAndFastaFileIdenticalTest() throws ReferenceReadingException, IOException {
    ReferenceSequenceFile referenceSequenceFile =
            ReferenceSequenceFileFactory.getReferenceSequenceFile(resource.getFile());
    //Go through all chromosomes if FASTA-file
    Track<Sequence> track = new Track<>();
    track.setType(TrackType.REF);
    track.setScaleFactor(SCALE_FACTOR_4_BASE);
    track.setId(reference.getId());

    byte[] arrayOfNucleicAcids;

    //Nucleicide frome FASTA-file
    arrayOfNucleicAcids = referenceSequenceFile.nextSequence().getBases();
    Chromosome chromosome = reference.getChromosomes().get(0);
    track.setChromosome(chromosome);
    track.setStartIndex(START_INDEX);
    track.setEndIndex(END_INDEX);
    //Nucleicide frome nib-file
    track = referenceManager.getNucleotidesResultFromNib(track);
    for (Sequence sequence : track.getBlocks()) {
        assertTrue(String.valueOf((char) (arrayOfNucleicAcids[sequence.getStartIndex() - 1]))
                .equals(sequence.getText()));
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:26,代码来源:ReferenceManagerTest.java

示例2: findReferenceFile

import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
public static ReferenceSequenceFile findReferenceFile(String fileName)
		throws FileNotFoundException {
	ReferenceSequenceFile rsf;

	File refFile = new File(fileName);

	try {
		rsf = ReferenceSequenceFileFactory
				.getReferenceSequenceFile(refFile);
	} catch (SAMException ex) {
		System.err.println("Could not load reference sequence file \""
				+ refFile + "\".");
		throw new FileNotFoundException(refFile.toString());
	}
	return rsf;
}
 
开发者ID:acs6610987,项目名称:secram,代码行数:17,代码来源:ReferenceUtils.java

示例3: main

import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
public static void main(String[] args) {
	String bam = "./data/HG00115.chrom11.ILLUMINA.bwa.GBR.exome.20130415.bam";
	SamReader reader = SamReaderFactory.makeDefault()
			.validationStringency(ValidationStringency.SILENT)
			.open(new File(bam));
	int length = 0;
	for (final SAMRecord record : reader) {
		if (record.getReadUnmappedFlag())
			continue;
		length += record.getReadLength();
	}

	ReferenceSequenceFile rsf = ReferenceSequenceFileFactory
			.getReferenceSequenceFile(new File("data/hs37d5.fa"));
	ReferenceSequence rs = rsf.getSequence("11");

	System.out.println(length * 1.0 / rs.length());
}
 
开发者ID:acs6610987,项目名称:secram,代码行数:19,代码来源:BAMAvgCoverage.java

示例4: makeSequenceDictionary

import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
/**
 * Read all the sequences from the given reference file, and convert into SAMSequenceRecords
 * @param referenceFile fasta or fasta.gz
 * @return SAMSequenceRecords containing info from the fasta, plus from cmd-line arguments.
 */
@Deprecated
public SAMSequenceDictionary makeSequenceDictionary(final File referenceFile) {
    final ReferenceSequenceFile refSeqFile =
            ReferenceSequenceFileFactory.getReferenceSequenceFile(referenceFile, TRUNCATE_NAMES_AT_WHITESPACE);
    ReferenceSequence refSeq;
    final List<SAMSequenceRecord> ret = new ArrayList<>();
    final Set<String> sequenceNames = new HashSet<>();
    for (int numSequences = 0; numSequences < NUM_SEQUENCES && (refSeq = refSeqFile.nextSequence()) != null; ++numSequences) {
        if (sequenceNames.contains(refSeq.getName())) {
            throw new PicardException("Sequence name appears more than once in reference: " + refSeq.getName());
        }
        sequenceNames.add(refSeq.getName());
        ret.add(makeSequenceRecord(refSeq));
    }
    return new SAMSequenceDictionary(ret);
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:22,代码来源:CreateSequenceDictionary.java

示例5: calculateRefWindowsByGc

import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
public static int[] calculateRefWindowsByGc(final int windows, final File referenceSequence, final int windowSize) {
    final ReferenceSequenceFile refFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(referenceSequence);
    ReferenceSequence ref;

    final int [] windowsByGc = new int [windows];

    while ((ref = refFile.nextSequence()) != null) {
        final byte[] refBases = ref.getBases();
        StringUtil.toUpperCase(refBases);
        final int refLength = refBases.length;
        final int lastWindowStart = refLength - windowSize;

        final CalculateGcState state = new GcBiasUtils().new CalculateGcState();

        for (int i = 1; i < lastWindowStart; ++i) {
            final int windowEnd = i + windowSize;
            final int gcBin = calculateGc(refBases, i, windowEnd, state);
            if (gcBin != -1) windowsByGc[gcBin]++;
        }
    }

    return windowsByGc;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:24,代码来源:GcBiasUtils.java

示例6: call

import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
@Override
public List<Entry> call() throws Exception {
	List<Entry> list = new ArrayList<RefRepo.Entry>();

	ReferenceSequenceFile rsFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(file);

	ReferenceSequence sequence = null;
	while ((sequence = rsFile.nextSequence()) != null) {
		sequence.getBases();

		Entry e = new Entry();
		e.md5 = Utils.calculateMD5String(sequence.getBases());
		e.file = "file://" + file.getAbsolutePath();
		e.name = sequence.getName();
		e.length = sequence.length();
		log.info(String.format("New entry: %s", e.toString()));
		list.add(e);
	}
	return list;
}
 
开发者ID:enasequence,项目名称:cramtools,代码行数:21,代码来源:RefRepo.java

示例7: customCommandLineValidation

import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
/**
 * Use reference filename to create URI to go into header if URI was not passed on cmd line.
 */
protected String[] customCommandLineValidation() {
    if (URI == null) {
        URI = "file:" + referenceSequence.getReferenceFile().getAbsolutePath();
    }
    if (OUTPUT == null) {
        OUTPUT = ReferenceSequenceFileFactory.getDefaultDictionaryForReferenceSequence(referenceSequence.getReferenceFile());
        logger.info("Output dictionary will be written in ", OUTPUT);
    }
    return super.customCommandLineValidation();
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:14,代码来源:CreateSequenceDictionary.java

示例8: doWork

import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
@Override
protected int doWork() {
    IOUtil.assertFileIsReadable(REFERENCE_SEQUENCE);
    IOUtil.assertFileIsWritable(OUTPUT);

    final ReferenceSequenceFile refFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(REFERENCE_SEQUENCE, true);
    if (!refFile.isIndexed()) {
        throw new IllegalStateException("Reference file must be indexed, but no index file was found");
    }
    if (refFile.getSequenceDictionary() == null) {
        throw new IllegalStateException("Reference file must include a dictionary, but no dictionary file was found");
    }

    // get the intervals
    final IntervalList intervals = segregateReference(refFile, MAX_TO_MERGE);

    log.info(String.format("Found %d intervals in %d loci during %s seconds", intervalProgress.getCount(), locusProgress.getCount(), locusProgress.getElapsedSeconds()));

    /**********************************
     * Now output regions for calling *
     **********************************/

    final IntervalList outputIntervals = new IntervalList(intervals.getHeader().clone());
    log.info(String.format("Collecting requested type of intervals (%s)", OUTPUT_TYPE));

    intervals.getIntervals().stream().filter(i -> OUTPUT_TYPE.accepts(i.getName())).forEach(outputIntervals::add);

    log.info("Writing Intervals.");
    outputIntervals.write(OUTPUT);

    log.info(String.format("Execution ending. Total time %d seconds", locusProgress.getElapsedSeconds()));

    return 0;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:35,代码来源:ScatterIntervalsByNs.java

示例9: doWork

import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
@Override
protected int doWork() {
    IOUtil.assertFileIsReadable(INTERVAL_LIST);
    IOUtil.assertFileIsReadable(REFERENCE_SEQUENCE);
    IOUtil.assertFileIsWritable(OUTPUT);

    final IntervalList intervals = IntervalList.fromFile(INTERVAL_LIST);
    final ReferenceSequenceFile ref = ReferenceSequenceFileFactory.getReferenceSequenceFile(REFERENCE_SEQUENCE);
    SequenceUtil.assertSequenceDictionariesEqual(intervals.getHeader().getSequenceDictionary(), ref.getSequenceDictionary());

    final BufferedWriter out = IOUtil.openFileForBufferedWriting(OUTPUT);

    for (final Interval interval : intervals) {
        final ReferenceSequence seq = ref.getSubsequenceAt(interval.getContig(), interval.getStart(), interval.getEnd());
        final byte[] bases = seq.getBases();
        if (interval.isNegativeStrand()) SequenceUtil.reverseComplement(bases);

        try {
            out.write(">");
            out.write(interval.getName());
            out.write("\n");

            for (int i=0; i<bases.length; ++i) {
                if (i > 0 && i % LINE_LENGTH == 0) out.write("\n");
                out.write(bases[i]);
            }

            out.write("\n");
        }
        catch (IOException ioe) {
            throw new PicardException("Error writing to file " + OUTPUT.getAbsolutePath(), ioe);

        }
    }

    CloserUtil.close(out);

    return 0;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:40,代码来源:ExtractSequences.java

示例10: isFasta

import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
private static boolean isFasta(String reference) {
    for (final String ext : ReferenceSequenceFileFactory.FASTA_EXTENSIONS) {
        if (reference.endsWith(ext)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:9,代码来源:ReferenceMultiSource.java

示例11: getReferenceBases

import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
@Override
public ReferenceBases getReferenceBases(final SimpleInterval interval) throws IOException {
    try ( ReferenceSequenceFile referenceSequenceFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(getReferencePath()) ) {
        ReferenceSequence sequence = referenceSequenceFile.getSubsequenceAt(interval.getContig(), interval.getStart(), interval.getEnd());
        return new ReferenceBases(sequence.getBases(), interval);
    }
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:8,代码来源:ReferenceFileSource.java

示例12: getAllReferenceBases

import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
public Map<String, ReferenceBases> getAllReferenceBases() throws IOException {
    try ( ReferenceSequenceFile referenceSequenceFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(getReferencePath()) ) {
        Map<String, ReferenceBases> bases = new LinkedHashMap<>();
        ReferenceSequence seq;
        while ( (seq = referenceSequenceFile.nextSequence()) != null ) {
            String name = seq.getName();
            bases.put(name, new ReferenceBases(seq.getBases(), new SimpleInterval(name, 1, seq.length())));
        }
        return bases;
    }
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:12,代码来源:ReferenceFileSource.java

示例13: testBadDefaultBasesPerLine

import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
@Test(dataProvider = "invalidBplData", expectedExceptions = IllegalArgumentException.class)
public void testBadDefaultBasesPerLine(final int invalidBpl) throws IOException {
    final File testOutput = createTempFile("fwr-test", ".fasta");
    final File testIndexOutput = ReferenceSequenceFileFactory.getFastaIndexFileName(testOutput.toPath()).toFile();
    final File testDictOutput = ReferenceSequenceFileFactory.getDefaultDictionaryForReferenceSequence(testOutput);
    Assert.assertTrue(testOutput.delete());
    try {
        new FastaReferenceWriter(testOutput.toPath(), invalidBpl, true, true);
    } finally {
        // make sure that no output file was created:
        Assert.assertFalse(testOutput.delete());
        Assert.assertFalse(testIndexOutput.delete());
        Assert.assertFalse(testDictOutput.delete());
    }
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:16,代码来源:FastaReferenceWriterUnitTest.java

示例14: testSingleSequenceStaticWithBpl

import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
@Test
public void testSingleSequenceStaticWithBpl() throws IOException, GeneralSecurityException, URISyntaxException {
    final File testOutputFile = createTempFile("fwr-test", ".random0.fasta");
    final Map<String, byte[]> seqs = Collections.singletonMap("seqA", new RandomDNA(1341).nextBases(100));
    final Map<String, Integer> bpls = Collections.singletonMap("seqA", 42);
    final SAMSequenceDictionary dictionary = new SAMSequenceDictionary(
            Collections.singletonList(new SAMSequenceRecord("seqA", 100))
    );
    FastaReferenceWriter.writeSingleSequenceReference(testOutputFile.toPath(), 42,
            true, true, "seqA", null, seqs.get("seqA"));
    assertOutput(testOutputFile.toPath(), true, true, false, dictionary, 42, seqs, bpls);
    Assert.assertTrue(testOutputFile.delete());
    Assert.assertTrue(ReferenceSequenceFileFactory.getDefaultDictionaryForReferenceSequence(testOutputFile).delete());
    Assert.assertTrue(ReferenceSequenceFileFactory.getFastaIndexFileName(testOutputFile.toPath()).toFile().delete());
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:16,代码来源:FastaReferenceWriterUnitTest.java

示例15: testSingleSequenceStatic

import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
@Test
public void testSingleSequenceStatic() throws IOException, GeneralSecurityException, URISyntaxException {
    final File testOutputFile = createTempFile("fwr-test", ".random0.fasta");
    final Map<String, byte[]> seqs = Collections.singletonMap("seqA", new RandomDNA(1341).nextBases(100));
    final Map<String, Integer> bpls = Collections.singletonMap("seqA", FastaReferenceWriter.DEFAULT_BASES_PER_LINE);
    final SAMSequenceDictionary dictionary = new SAMSequenceDictionary(
            Collections.singletonList(new SAMSequenceRecord("seqA", 100))
    );
    FastaReferenceWriter.writeSingleSequenceReference(testOutputFile.toPath(),
            true, true, "seqA", null, seqs.get("seqA"));
    assertOutput(testOutputFile.toPath(), true, true, false, dictionary, FastaReferenceWriter.DEFAULT_BASES_PER_LINE, seqs, bpls);
    Assert.assertTrue(testOutputFile.delete());
    Assert.assertTrue(ReferenceSequenceFileFactory.getDefaultDictionaryForReferenceSequence(testOutputFile).delete());
    Assert.assertTrue(ReferenceSequenceFileFactory.getFastaIndexFileName(testOutputFile.toPath()).toFile().delete());
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:16,代码来源:FastaReferenceWriterUnitTest.java


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