本文整理汇总了Java中htsjdk.samtools.SAMSequenceDictionary类的典型用法代码示例。如果您正苦于以下问题:Java SAMSequenceDictionary类的具体用法?Java SAMSequenceDictionary怎么用?Java SAMSequenceDictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SAMSequenceDictionary类属于htsjdk.samtools包,在下文中一共展示了SAMSequenceDictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStaticDataInstance
import htsjdk.samtools.SAMSequenceDictionary; //导入依赖的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;
}
示例2: getRecalTableLines
import htsjdk.samtools.SAMSequenceDictionary; //导入依赖的package包/类
public static List<String> getRecalTableLines(RefContigInfo refContigInfo,
SamRecordPartition samRecordPartition,
FastaPartition refPartition,
List<VcfRecordPartition> rodPartitions) {
SAMSequenceDictionary samSequenceDictionary = SAMSequenceDictTransfer.transfer(refContigInfo);
GenomeLocParser parser = new GenomeLocParser(samSequenceDictionary);
SamContentProvider samContentProvider = new SamContentProvider(samRecordPartition);
RefContentProvider refContentProvider = new RefContentProvider(samSequenceDictionary, refPartition);
List<RODContentProvider> rodContentProviders = new java.util.ArrayList<>();
rodPartitions.forEach(
rodPartition -> rodContentProviders.add(
new RODContentProvider(RODNames.KNOWN_ALLELES + rodPartition.key(), rodPartition, parser))
);
// 生成recal table
BaseRecalibrator baseRecalibrator = new BaseRecalibrator(
parser, refContentProvider, samContentProvider, rodContentProviders);
baseRecalibrator.run();
GATKReport bqsrTable = baseRecalibrator.getReport();
return GATKReportTransfer.report2Lines(bqsrTable);
}
示例3: compareLocatables
import htsjdk.samtools.SAMSequenceDictionary; //导入依赖的package包/类
public static final int compareLocatables(GenomeLocation first, GenomeLocation second, SAMSequenceDictionary dictionary) {
Utils.nonNull(first);
Utils.nonNull(second);
Utils.nonNull(dictionary);
int result = 0;
if(first != second) {
// compare the contigs
result = compareContigs(first, second, dictionary);
if (result == 0) {
// compare start position
result = Integer.compare(first.getStart(), second.getStart());
if (result == 0) {
// compare end position
result = Integer.compare(first.getStop(), second.getStop());
}
}
}
return result;
}
示例4: writeOutRecalibrationTable
import htsjdk.samtools.SAMSequenceDictionary; //导入依赖的package包/类
public void writeOutRecalibrationTable(final VariantContextWriter recalWriter,
final SAMSequenceDictionary seqDictionary) {
// we need to sort in coordinate order in order to produce a valid VCF
Collections.sort(data, VariantDatum.getComparator(seqDictionary));
// create dummy alleles to be used
List<Allele> alleles = Arrays.asList(Allele.create("N", true), Allele.create("<VQSR>", false));
for (final VariantDatum datum : data) {
if (VRAC.useASannotations)
alleles = Arrays.asList(datum.referenceAllele, datum.alternateAllele);
VariantContextBuilder builder = new VariantContextBuilder("VQSR", datum.loc.getContig(),
datum.loc.getStart(), datum.loc.getStop(), alleles);
builder.attribute(VCFConstants.END_KEY, datum.loc.getStop());
builder.attribute(GaeaVCFConstants.VQS_LOD_KEY, String.format("%.4f", datum.lod));
builder.attribute(GaeaVCFConstants.CULPRIT_KEY,
(datum.worstAnnotation != -1 ? annotationKeys.get(datum.worstAnnotation) : "NULL"));
if (datum.atTrainingSite)
builder.attribute(GaeaVCFConstants.POSITIVE_LABEL_KEY, true);
if (datum.atAntiTrainingSite)
builder.attribute(GaeaVCFConstants.NEGATIVE_LABEL_KEY, true);
recalWriter.add(builder.make());
}
}
示例5: createVCFWriter
import htsjdk.samtools.SAMSequenceDictionary; //导入依赖的package包/类
public static VariantContextWriter createVCFWriter(final File outFile,
final SAMSequenceDictionary referenceDictionary, final boolean createMD5, final Options... options) {
Utils.nonNull(outFile);
VariantContextWriterBuilder vcWriterBuilder = new VariantContextWriterBuilder().clearOptions()
.setOutputFile(outFile);
if (createMD5) {
vcWriterBuilder.setCreateMD5();
}
if (null != referenceDictionary) {
vcWriterBuilder = vcWriterBuilder.setReferenceDictionary(referenceDictionary);
}
for (Options opt : options) {
vcWriterBuilder = vcWriterBuilder.setOption(opt);
}
return vcWriterBuilder.build();
}
示例6: parseGFF
import htsjdk.samtools.SAMSequenceDictionary; //导入依赖的package包/类
static void parseGFF(File gffFile, File outfile, String genome, String genomeFile) {
try {
SAMSequenceDictionary dict = ReadDict(new File(genomeFile));
FileRead.readGFF(gffFile, outfile.getCanonicalPath(), dict);
}
catch(Exception e) {
e.printStackTrace();
}
/* Main.addGenome
Main.genomehash.get(genome).add(outfile);
JMenuItem additem = new JMenuItem(outfile.getName().substring(0,outfile.getName().indexOf(".gff")));
additem.setName(outfile.getName().substring(0,outfile.getName().indexOf(".gff")));
additem.addMouseListener(Main.frame);
Main.addMenu.add(additem);
break;
*/
}
示例7: addIntervalFeatureTrackFromVCF
import htsjdk.samtools.SAMSequenceDictionary; //导入依赖的package包/类
private void addIntervalFeatureTrackFromVCF(String sourceName, GenomicCoords gc, String trackTag) throws ClassNotFoundException, IOException, InvalidGenomicCoordsException, InvalidRecordException, SQLException {
int idForTrack= this.getNextTrackId();
// String trackId= new File(sourceName).getName() + "#" + idForTrack;
String trackId= sourceName + "#" + idForTrack;
// If this VCF file has sequence dictionary, check the coordinates in gc are compatible
// If they are not, throw an exception which force resetting the coords.
SAMSequenceDictionary seqDict = Utils.getVCFHeader(sourceName).getSequenceDictionary();
if(seqDict != null && seqDict.getSequence(gc.getChrom()) == null){
throw new InvalidGenomicCoordsException();
}
TrackIntervalFeature tif= new TrackIntervalFeature(sourceName, gc);
tif.setTrackTag(trackId);
this.trackList.add(tif);
}
示例8: setSamSeqDictFromBam
import htsjdk.samtools.SAMSequenceDictionary; //导入依赖的package包/类
private boolean setSamSeqDictFromBam(String bamfile) {
/* ------------------------------------------------------ */
/* This chunk prepares SamReader from local bam */
SamReaderFactory srf=SamReaderFactory.make();
srf.validationStringency(ValidationStringency.SILENT);
SamReader samReader;
samReader= srf.open(new File(bamfile));
/* ------------------------------------------------------ */
SAMSequenceDictionary seqDict = samReader.getFileHeader().getSequenceDictionary();
if(seqDict != null && !seqDict.isEmpty()){
this.setSamSeqDictSource(new File(bamfile).getAbsolutePath());
this.setSamSeqDict(seqDict);
return true;
}
return false;
}
示例9: isValidPosition
import htsjdk.samtools.SAMSequenceDictionary; //导入依赖的package包/类
/** Return true if the GenomicCoords object is valid given the SAMSequenceDictionary. I.e.
* gc contig and position is part of the dictionary.
* */
private boolean isValidPosition(GenomicCoords gc, SAMSequenceDictionary samSeqDict){
if(samSeqDict == null || gc == null){
return true;
}
HashMap<String, Integer> chromLen= new HashMap<String, Integer>();
for(SAMSequenceRecord x : gc.getSamSeqDict().getSequences()){
chromLen.put(x.getSequenceName(), x.getSequenceLength());
}
boolean isValid= false;
if( chromLen.containsKey(gc.getChrom()) ){
int len= chromLen.get(gc.getChrom());
if(gc.getTo() <= len){
isValid= true;
}
}
return isValid;
}
示例10: encodeAll
import htsjdk.samtools.SAMSequenceDictionary; //导入依赖的package包/类
@Override
public Map<String, Object> encodeAll(OutputStream outputStream, Iterator<? extends VCFVariant> features) throws IOException {
SAMSequenceDictionary seqDict = new SAMSequenceDictionary();
EnumSet<Options> options = VariantContextWriterFactory.DEFAULT_OPTIONS;
options.add(Options.ALLOW_MISSING_FIELDS_IN_HEADER);
options.remove(Options.INDEX_ON_THE_FLY);
VariantContextWriter writer = VariantContextWriterFactory.create(outputStream, seqDict, options);
writer.writeHeader(this.header);
while(features.hasNext()){
writer.add(features.next().getVariantContext());
}
return null;
}
示例11: setupPipeline
import htsjdk.samtools.SAMSequenceDictionary; //导入依赖的package包/类
@Override
protected void setupPipeline(final Pipeline pipeline) {
final ReadsDataflowSource readsSource = new ReadsDataflowSource(bam, pipeline);
final SAMFileHeader header = readsSource.getHeader();
final SAMSequenceDictionary sequenceDictionary = header.getSequenceDictionary();
final List<SimpleInterval> intervals = intervalArgumentCollection.intervalsSpecified() ? intervalArgumentCollection.getIntervals(sequenceDictionary):
IntervalUtils.getAllIntervalsForReference(sequenceDictionary);
final PCollectionView<SAMFileHeader> headerPcolView = pipeline.apply(Create.of(header)).apply(View.<SAMFileHeader>asSingleton());
final PCollection<GATKRead> preads = readsSource.getReadPCollection(intervals);
final OpticalDuplicateFinder finder = opticalDuplicatesArgumentCollection.READ_NAME_REGEX != null ?
new OpticalDuplicateFinder(opticalDuplicatesArgumentCollection.READ_NAME_REGEX, opticalDuplicatesArgumentCollection.OPTICAL_DUPLICATE_PIXEL_DISTANCE, null) : null;
final PCollectionView<OpticalDuplicateFinder> finderPcolView = pipeline.apply(Create.of(finder)).apply(View.<OpticalDuplicateFinder>asSingleton());
final PCollection<GATKRead> results = preads.apply(new MarkDuplicates(headerPcolView, finderPcolView));
// TODO: support writing large output files (need a sharded BAM writer)
SmallBamWriter.writeToFile(pipeline, results, header, outputFile);
if (metricsFile != null) {
final PCollection<KV<String,DuplicationMetrics>> metrics = results.apply(new MarkDuplicatesDataflowUtils.GenerateMetricsTransform(headerPcolView));
MarkDuplicatesDataflowUtils.writeMetricsToFile(pipeline, metrics, header, metricsFile);
}
}
示例12: setupPipeline
import htsjdk.samtools.SAMSequenceDictionary; //导入依赖的package包/类
@Override
protected void setupPipeline(Pipeline pipeline) {
if (readArguments.getReadFilesNames().size()>1) {
throw new UserException("Sorry, we only support a single input file for now.");
}
final String filename = readArguments.getReadFilesNames().get(0);
final ReadsDataflowSource readsSource = new ReadsDataflowSource(filename, pipeline);
final SAMFileHeader header = readsSource.getHeader();
final PCollectionView<SAMFileHeader> headerView = pipeline.apply(Create.of(header)).apply(View.asSingleton());
final SAMSequenceDictionary sequenceDictionary = header.getSequenceDictionary();
final List<SimpleInterval> intervals = intervalArgumentCollection.intervalsSpecified() ? intervalArgumentCollection.getIntervals(sequenceDictionary)
: IntervalUtils.getAllIntervalsForReference(sequenceDictionary);
final PCollectionView<BaseRecalOutput> recalInfoSingletonView = BaseRecalOutputSource.loadFileOrRemote(pipeline, BQSR_RECAL_FILE_NAME).apply(View.asSingleton());
final PCollection<GATKRead> output = readsSource.getReadPCollection(intervals, ValidationStringency.SILENT, false)
.apply(new ApplyBQSRTransform(headerView, recalInfoSingletonView, bqsrOpts));
intermediateRemoteBam = OUTPUT;
if (needsIntermediateCopy()) {
// The user specified remote execution and provided a local file name. So we're going to have to save to remote storage as a go-between.
// Note that this may require more permissions
intermediateRemoteBam = BucketUtils.randomRemotePath(stagingLocation, "temp-applyBqsr-output-", ".bam");
logger.info("Staging results at " + intermediateRemoteBam);
}
SmallBamWriter.writeToFile(pipeline, output, header, intermediateRemoteBam);
}
示例13: resolveTargetCollection
import htsjdk.samtools.SAMSequenceDictionary; //导入依赖的package包/类
/**
* Builds the target collection given the values of user arguments.
*
* @throws UserException if there is some inconsistency in user arguments and inputs.
* @throws GATKException if there was any problem parsing the content of the targets file.
* @return never {@code null}.
*/
private TargetCollection<Target> resolveTargetCollection() {
final TargetCollection<Target> result;
if (targetsFile != null) {
result = resolveTargetsFromFile();
} else if (hasIntervals()) {
final SAMSequenceDictionary sequenceDictionary = getBestAvailableSequenceDictionary();
final List<SimpleInterval> intervals = intervalArgumentCollection.getIntervals(sequenceDictionary);
//this constructor automatically generates target names from the intervals
final List<Target> targets = intervals.stream().map(Target::new).collect(Collectors.toList());
result = new HashedListTargetCollection<>(targets);
} else {
throw new UserException(String.format("You must indicate the set of target as input intervals (e.g. -L target-intervals.list) or a target feature file (e.g. -%s my-targets.tsv) ", TARGET_FILE_SHORT_NAME));
}
if (targetOutInfo.requiresUniqueTargetName()) {
checkAllTargetsHaveName(result);
}
return result;
}
示例14: onTraversalStart
import htsjdk.samtools.SAMSequenceDictionary; //导入依赖的package包/类
@Override
public void onTraversalStart() {
ParamUtils.isPositive(scatterCount, "scatter count must be > 0.");
if (!outputDir.exists() && !outputDir.mkdir()) {
throw new RuntimeIOException("Unable to create directory: " + outputDir.getAbsolutePath());
}
// in general dictionary will be from the reference, but using -I reads.bam or -F variants.vcf
// to use the sequence dict from a bam or vcf is also supported
final SAMSequenceDictionary sequenceDictionary = getBestAvailableSequenceDictionary();
final List<SimpleInterval> intervals = hasIntervals() ? intervalArgumentCollection.getIntervals(sequenceDictionary)
: IntervalUtils.getAllIntervalsForReference(sequenceDictionary);
final IntervalList intervalList = new IntervalList(sequenceDictionary);
intervals.stream().map(si -> new Interval(si.getContig(), si.getStart(), si.getEnd())).forEach(intervalList::add);
final IntervalListScatterer scatterer = new IntervalListScatterer(subdivisionMode);
final List<IntervalList> scattered = scatterer.scatter(intervalList, scatterCount, false);
final DecimalFormat formatter = new DecimalFormat("0000");
IntStream.range(0, scattered.size()).forEach(n -> scattered.get(n).write(new File(outputDir, formatter.format(n) + "-scattered.intervals")));
}
示例15: makeVCFWriter
import htsjdk.samtools.SAMSequenceDictionary; //导入依赖的package包/类
/**
* Create a VCF or GVCF writer as appropriate, given our arguments
*
* @param outputVCF location to which the vcf should be written
* @param readsDictionary sequence dictionary for the reads
* @return a VCF or GVCF writer as appropriate, ready to use
*/
public VariantContextWriter makeVCFWriter( final String outputVCF, final SAMSequenceDictionary readsDictionary ) {
Utils.nonNull(outputVCF);
Utils.nonNull(readsDictionary);
VariantContextWriter writer = GATKVariantContextUtils.createVCFWriter(new File(outputVCF), readsDictionary, false);
if ( hcArgs.emitReferenceConfidence == ReferenceConfidenceMode.GVCF ) {
try {
writer = new GVCFWriter(writer, hcArgs.GVCFGQBands, hcArgs.genotypeArgs.samplePloidy);
} catch ( IllegalArgumentException e ) {
throw new CommandLineException.BadArgumentValue("GQBands", "are malformed: " + e.getMessage());
}
}
return writer;
}