本文整理汇总了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()));
}
}
示例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;
}
示例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());
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
}
示例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());
}
}
示例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());
}
示例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());
}