本文整理汇总了Java中htsjdk.samtools.reference.ReferenceSequenceFileFactory类的典型用法代码示例。如果您正苦于以下问题:Java ReferenceSequenceFileFactory类的具体用法?Java ReferenceSequenceFileFactory怎么用?Java ReferenceSequenceFileFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReferenceSequenceFileFactory类属于htsjdk.samtools.reference包,在下文中一共展示了ReferenceSequenceFileFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: assertOutput
import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
private void assertOutput(final Path path, final boolean mustHaveIndex, final boolean mustHaveDictionary,
final boolean withDescriptions, final SAMSequenceDictionary dictionary, final int defaultBpl,
final Map<String, byte[]> bases, final Map<String, Integer> basesPerLine)
throws GeneralSecurityException, IOException, URISyntaxException {
assertFastaContent(path, withDescriptions, dictionary, defaultBpl, bases, basesPerLine);
if (mustHaveDictionary) {
assertFastaDictionaryContent(ReferenceSequenceFileFactory.getDefaultDictionaryForReferenceSequence(path), dictionary);
}
if (mustHaveIndex) {
assertFastaIndexContent(path, ReferenceSequenceFileFactory.getFastaIndexFileName(path), dictionary, bases);
}
}
开发者ID:broadinstitute,项目名称:gatk,代码行数:13,代码来源:FastaReferenceWriterUnitTest.java
示例17: ReferenceSource
import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
public ReferenceSource(File file) {
if (file != null) {
rsFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(file);
File indexFile = new File(file.getAbsoluteFile() + ".fai");
if (indexFile.exists())
fastaSequenceIndex = new FastaSequenceIndex(indexFile);
}
}
开发者ID:enasequence,项目名称:cramtools,代码行数:10,代码来源:ReferenceSource.java
示例18: getBasesFromReferenceFile
import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
public static byte[] getBasesFromReferenceFile(String referenceFilePath, String seqName, int from, int length) {
ReferenceSequenceFile referenceSequenceFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(new File(
referenceFilePath));
ReferenceSequence sequence = referenceSequenceFile.getSequence(seqName);
byte[] bases = referenceSequenceFile.getSubsequenceAt(sequence.getName(), from, from + length).getBases();
return bases;
}
开发者ID:enasequence,项目名称:cramtools,代码行数:8,代码来源:Utils.java
示例19: main
import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
public static void main(String[] args) {
ReferenceSequenceFile rsf = ReferenceSequenceFileFactory
.getReferenceSequenceFile(new File("data/hs37d5.fa"));
SAMSequenceDictionary dict = rsf.getSequenceDictionary();
ReferenceSequence rs1 = rsf.nextSequence(), rs2 = rsf.nextSequence();
ReferenceSequence rs = rsf.getSequence("1"); // get reference sequence
// by sequence name
System.out.println(rs.getName());
System.out.println(rs.getContigIndex());
System.out.println(rs.length());
System.out.println(rs.getBases().length);
System.out.println("===============");
byte[] bases = rs.getBases();
int count[] = new int[256];
for (int i = 0; i < bases.length; i++) {
count[bases[i]]++;
}
for (int i = 0; i < count.length; i++) {
System.out.println((char) i + " " + count[i]);
}
rs = rsf.getSequence("22");
System.out.println(rs.getName());
System.out.println(rs.getContigIndex());
System.out.println(rs.length());
System.out.println(rs.getBases().length);
System.out.println("===============");
rs = rsf.getSequence("X");
System.out.println(rs.getName());
System.out.println(rs.getContigIndex());
System.out.println(rs.length());
System.out.println(rs.getBases().length);
System.out.println(rs.getBases()[rs.length() - 1]);
rs = rsf.getSubsequenceAt("X", 0, 2);
System.out.println(rs.getName());
System.out.println(rs.getContigIndex());
System.out.println(rs.length());
System.out.println(rs.getBases().length);
System.out.println(String.format("%02x", rs.getBases()[0]));
// for (int i=0;i<bases.length;++i) {
// int unsigned = bases[i]&0xff;
//
// System.out.println("\""+(char)(unsigned)+"\" ("+unsigned+")");
// }
}
开发者ID:acs6610987,项目名称:secram,代码行数:49,代码来源:ExampleFastaRefUsage.java
示例20: doWork
import htsjdk.samtools.reference.ReferenceSequenceFileFactory; //导入依赖的package包/类
protected int doWork() {
IOUtil.assertFileIsReadable(INPUT);
IOUtil.assertFileIsReadable(REFERENCE_SEQUENCE);
IOUtil.assertFileIsWritable(OUTPUT);
final SamReader in = SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE).open(INPUT);
final ReferenceSequenceFile reference = ReferenceSequenceFileFactory.getReferenceSequenceFile(REFERENCE_SEQUENCE);
final SAMSequenceDictionary refDict = reference.getSequenceDictionary();
if (refDict == null) {
log.error("No reference sequence dictionary found. Aborting. You can create a sequence dictionary for the reference fasta using CreateSequenceDictionary.jar.");
CloserUtil.close(in);
return 1;
}
printDictionary("SAM/BAM file", in.getFileHeader().getSequenceDictionary());
printDictionary("Reference", refDict);
final Map<Integer, Integer> newOrder = buildSequenceDictionaryMap(refDict, in.getFileHeader().getSequenceDictionary());
// has to be after we create the newOrder
final SAMFileHeader outHeader = in.getFileHeader().clone();
outHeader.setSequenceDictionary(refDict);
log.info("Writing reads...");
if (in.hasIndex()) {
try( final SAMFileWriter out = new SAMFileWriterFactory().makeSAMOrBAMWriter(outHeader, true, OUTPUT)) {
// write the reads in contig order
for (final SAMSequenceRecord contig : refDict.getSequences()) {
final SAMRecordIterator it = in.query(contig.getSequenceName(), 0, 0, false);
writeReads(out, it, newOrder, contig.getSequenceName());
}
// don't forget the unmapped reads
writeReads(out, in.queryUnmapped(), newOrder, "unmapped");
}
} else {
try (final SAMFileWriter out = new SAMFileWriterFactory().makeSAMOrBAMWriter(outHeader, false, OUTPUT)) {
writeReads(out, in.iterator(), newOrder, "All reads");
}
}
// cleanup
CloserUtil.close(in);
return 0;
}
开发者ID:broadinstitute,项目名称:picard,代码行数:47,代码来源:ReorderSam.java
注:本文中的htsjdk.samtools.reference.ReferenceSequenceFileFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论