本文整理汇总了Java中htsjdk.samtools.SAMReadGroupRecord类的典型用法代码示例。如果您正苦于以下问题:Java SAMReadGroupRecord类的具体用法?Java SAMReadGroupRecord怎么用?Java SAMReadGroupRecord使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SAMReadGroupRecord类属于htsjdk.samtools包,在下文中一共展示了SAMReadGroupRecord类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transfer
import htsjdk.samtools.SAMReadGroupRecord; //导入依赖的package包/类
public static SAMFileHeader transfer(SamHeaderInfo samHeaderInfo){
SAMFileHeader header = new SAMFileHeader();
// read groups
List<ReadGroupInfo> readGroupInfoList = CollectionConverter.asJavaList(samHeaderInfo.getReadGroupInfos());
List<SAMReadGroupRecord> samReadGroupRecords = readGroupInfoList.stream()
.map(SAMReadGroupRecordTransfer::transfer)
.collect(Collectors.toList());
header.setReadGroups(samReadGroupRecords);
// Sequence records
// TODO 获取id的方法不通用 fix me
int contigCount = samHeaderInfo.getRefContigInfo().getContigIds().size();
for(int id = 0; id < contigCount; id ++) {
header.addSequence(new SAMSequenceRecord(
samHeaderInfo.getRefContigInfo().getName(id),
samHeaderInfo.getRefContigInfo().getLength(id)));
}
if(samHeaderInfo.sorted()) {
header.setAttribute("SO", "coordinate");
}
return header;
}
示例2: getReadGroup
import htsjdk.samtools.SAMReadGroupRecord; //导入依赖的package包/类
/**
* Get the GATKSAMReadGroupRecord of this read
* @return a non-null GATKSAMReadGroupRecord
*/
@Override
public GATKSAMReadGroupRecord getReadGroup() {
if ( ! retrievedReadGroup ) {
final SAMReadGroupRecord rg = super.getReadGroup();
// three cases: rg may be null (no rg, rg may already be a GATKSAMReadGroupRecord, or it may be
// a regular SAMReadGroupRecord in which case we have to make it a GATKSAMReadGroupRecord
if ( rg == null )
mReadGroup = null;
else if ( rg instanceof GATKSAMReadGroupRecord )
mReadGroup = (GATKSAMReadGroupRecord)rg;
else
mReadGroup = new GATKSAMReadGroupRecord(rg);
retrievedReadGroup = true;
}
return mReadGroup;
}
示例3: createEnumeratedReadGroups
import htsjdk.samtools.SAMReadGroupRecord; //导入依赖的package包/类
/**
* setup read groups for the specified read groups and sample names
*
* @param header the header to set
* @param readGroupIDs the read group ID tags
* @param sampleNames the sample names
* @return the adjusted SAMFileHeader
*/
public static SAMFileHeader createEnumeratedReadGroups(SAMFileHeader header, List<String> readGroupIDs, List<String> sampleNames) {
if (readGroupIDs.size() != sampleNames.size()) {
throw new ReviewedGATKException("read group count and sample name count must be the same");
}
List<SAMReadGroupRecord> readGroups = new ArrayList<SAMReadGroupRecord>();
int x = 0;
for (; x < readGroupIDs.size(); x++) {
SAMReadGroupRecord rec = new SAMReadGroupRecord(readGroupIDs.get(x));
rec.setSample(sampleNames.get(x));
readGroups.add(rec);
}
header.setReadGroups(readGroups);
return header;
}
示例4: getStaticDataInstance
import htsjdk.samtools.SAMReadGroupRecord; //导入依赖的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;
}
示例5: filter
import htsjdk.samtools.SAMReadGroupRecord; //导入依赖的package包/类
public boolean filter(ReferenceContext ref, GATKSAMRecord read) {
// check that the read belongs to an RG that we need to keep
if (!readGroupsToKeep.isEmpty()) {
final SAMReadGroupRecord readGroup = read.getReadGroup();
if (!readGroupsToKeep.contains(readGroup.getReadGroupId()))
return false;
}
// check if we've reached the output limit
if (nReadsToPrint == 0) {
return false; // n == 0 means we've printed all we needed.
} else if (nReadsToPrint > 0) {
nReadsToPrint--; // n > 0 means there are still reads to be printed.
}
return true;
}
示例6: VariantCallingEngine
import htsjdk.samtools.SAMReadGroupRecord; //导入依赖的package包/类
/**
* constructor
* @param options
* @param samFileHeader
*/
public VariantCallingEngine(GenotyperOptions options, SAMFileHeader samFileHeader) {
this.options = options;
genomeLocationParser = new GenomeLocationParser(samFileHeader.getSequenceDictionary());
samples = new HashSet<>();
for(SAMReadGroupRecord rg : samFileHeader.getReadGroups()) {
samples.add(rg.getSample());
}
GenotypeLikelihoodCalculator.getGenotypeLikelihoodsCalculatorObject(options);
GenotypeLikelihoodCalculator.getCalculators(options);
this.N = samples.size() * options.getSamplePloidy();
log10AlleleFrequencyPriorsSNPs = new double[N+1];
log10AlleleFrequencyPriorsIndels = new double[N+1];
computeAlleleFrequencyPriors(N, log10AlleleFrequencyPriorsSNPs, options.getHeterozygosity());
computeAlleleFrequencyPriors(N, log10AlleleFrequencyPriorsIndels, options.getIndelHeterozygosity());
filter.add(LOW_QUAL_FILTER_NAME);
tracker = new VariantDataTracker();
annotationEngine = new VariantAnnotatorEngine(options.getAnnotationGroups(), options.getAnnotations(), null);
}
示例7: getPlatforms
import htsjdk.samtools.SAMReadGroupRecord; //导入依赖的package包/类
/**
* @param header
* @return Return the set of platforms, uppercase. Will be null iff header is null
*/
public static Set<String> getPlatforms(SAMFileHeader header) {
Set<String> platforms = null;
if (header != null) {
List<SAMReadGroupRecord> readGroups = header.getReadGroups();
if (readGroups != null) {
platforms = new HashSet<String>();
for (SAMReadGroupRecord rg : readGroups) {
String platform = rg.getPlatform();
if (platform != null) {
platforms.add(platform.toUpperCase());
}
}
}
}
return platforms;
}
示例8: createReadGroupRecord
import htsjdk.samtools.SAMReadGroupRecord; //导入依赖的package包/类
protected SAMReadGroupRecord createReadGroupRecord(
String RGID, String RGLB, String RGPL,
String RGPU, String RGSM, String RGCN,
String RGDS, Iso8601Date RGDT, Integer RGPI) {
SAMReadGroupRecord rg = new SAMReadGroupRecord(RGID);
rg.setLibrary(RGLB);
rg.setPlatform(RGPL);
rg.setSample(RGSM);
rg.setPlatformUnit(RGPU);
if(RGCN != null)
rg.setSequencingCenter(RGCN);
if(RGDS != null)
rg.setDescription(RGDS);
if(RGDT != null)
rg.setRunDate(RGDT);
if(RGPI != null)
rg.setPredictedMedianInsertSize(RGPI);
return rg;
}
示例9: buildSamFileWriter
import htsjdk.samtools.SAMReadGroupRecord; //导入依赖的package包/类
/**
* Build a SamFileWriter that will write its contents to the output file.
*
* @param output The file to which to write
* @param sampleAlias The sample alias set in the read group header
* @param libraryName The name of the library to which this read group belongs
* @param headerParameters Header parameters that will be added to the RG header for this SamFile
* @return A SAMFileWriter
*/
private SAMFileWriterWrapper buildSamFileWriter(final File output, final String sampleAlias,
final String libraryName, final Map<String, String> headerParameters,
final boolean presorted) {
IOUtil.assertFileIsWritable(output);
final SAMReadGroupRecord rg = new SAMReadGroupRecord(READ_GROUP_ID);
rg.setSample(sampleAlias);
if (libraryName != null) rg.setLibrary(libraryName);
for (final Map.Entry<String, String> tagNameToValue : headerParameters.entrySet()) {
if (tagNameToValue.getValue() != null) {
rg.setAttribute(tagNameToValue.getKey(), tagNameToValue.getValue());
}
}
final SAMFileHeader header = new SAMFileHeader();
header.setSortOrder(SAMFileHeader.SortOrder.queryname);
header.addReadGroup(rg);
return new SAMFileWriterWrapper(new SAMFileWriterFactory().makeSAMOrBAMWriter(header, presorted, output));
}
示例10: createSamFileHeader
import htsjdk.samtools.SAMReadGroupRecord; //导入依赖的package包/类
/** Creates a simple header with the values provided on the command line. */
public SAMFileHeader createSamFileHeader() {
final SAMReadGroupRecord rgroup = new SAMReadGroupRecord(this.READ_GROUP_NAME);
rgroup.setSample(this.SAMPLE_NAME);
if (this.LIBRARY_NAME != null) rgroup.setLibrary(this.LIBRARY_NAME);
if (this.PLATFORM != null) rgroup.setPlatform(this.PLATFORM);
if (this.PLATFORM_UNIT != null) rgroup.setPlatformUnit(this.PLATFORM_UNIT);
if (this.SEQUENCING_CENTER != null) rgroup.setSequencingCenter(SEQUENCING_CENTER);
if (this.PREDICTED_INSERT_SIZE != null) rgroup.setPredictedMedianInsertSize(PREDICTED_INSERT_SIZE);
if (this.DESCRIPTION != null) rgroup.setDescription(this.DESCRIPTION);
if (this.RUN_DATE != null) rgroup.setRunDate(this.RUN_DATE);
if (this.PLATFORM_MODEL != null) rgroup.setPlatformModel(this.PLATFORM_MODEL);
if (this.PROGRAM_GROUP != null) rgroup.setProgramGroup(this.PROGRAM_GROUP);
final SAMFileHeader header = new SAMFileHeader();
header.addReadGroup(rgroup);
for (final String comment : COMMENT) {
header.addComment(comment);
}
header.setSortOrder(this.SORT_ORDER);
return header ;
}
示例11: makeReadGroupFile
import htsjdk.samtools.SAMReadGroupRecord; //导入依赖的package包/类
private File makeReadGroupFile(final SAMReadGroupRecord readGroup, final String preExtSuffix) {
String fileName = null;
if (RG_TAG.equalsIgnoreCase("PU")){
fileName = readGroup.getPlatformUnit();
} else if (RG_TAG.equalsIgnoreCase("ID")){
fileName = readGroup.getReadGroupId();
}
if (fileName == null) {
throw new PicardException("The selected RG_TAG: "+RG_TAG+" is not present in the bam header.");
}
fileName = IOUtil.makeFileNameSafe(fileName);
if (preExtSuffix != null) fileName += preExtSuffix;
fileName += COMPRESS_OUTPUTS_PER_RG ? ".fastq.gz" : ".fastq";
final File result = (OUTPUT_DIR != null)
? new File(OUTPUT_DIR, fileName)
: new File(fileName);
IOUtil.assertFileIsWritable(result);
return result;
}
示例12: splitByLibrary
import htsjdk.samtools.SAMReadGroupRecord; //导入依赖的package包/类
/**
* Takes a list of PairedReadSequence objects and splits them into lists by library.
*/
Map<String, List<PairedReadSequence>> splitByLibrary(final List<PairedReadSequence> input,
final List<SAMReadGroupRecord> rgs) {
final Map<String, List<PairedReadSequence>> out = new HashMap<>();
for (final PairedReadSequence seq : input) {
String library = null;
if (seq.getReadGroup() != -1) {
library = rgs.get(seq.getReadGroup()).getLibrary();
if (library == null) library = "Unknown";
} else {
library = "Unknown";
}
List<PairedReadSequence> librarySeqs = out.get(library);
if (librarySeqs == null) {
librarySeqs = new ArrayList<>();
out.put(library, librarySeqs);
}
librarySeqs.add(seq);
}
return out;
}
示例13: saveResults
import htsjdk.samtools.SAMReadGroupRecord; //导入依赖的package包/类
private void saveResults(final MetricsFile<?, Integer> metrics, final SAMFileHeader readsHeader, final String inputFileName){
MetricsUtils.saveMetrics(metrics, out);
if (metrics.getAllHistograms().isEmpty()) {
logger.warn("No valid bases found in input file.");
} else if (chartOutput != null){
// Now run R to generate a chart
// If we're working with a single library, assign that library's name
// as a suffix to the plot title
final List<SAMReadGroupRecord> readGroups = readsHeader.getReadGroups();
/*
* A subtitle for the plot, usually corresponding to a library.
*/
String plotSubtitle = "";
if (readGroups.size() == 1) {
plotSubtitle = StringUtil.asEmptyIfNull(readGroups.get(0).getLibrary());
}
final RScriptExecutor executor = new RScriptExecutor();
executor.addScript(getMeanQualityByCycleRScriptResource());
executor.addArgs(out, chartOutput.getAbsolutePath(), inputFileName, plotSubtitle);
executor.exec();
}
}
示例14: acceptRecord
import htsjdk.samtools.SAMReadGroupRecord; //导入依赖的package包/类
/** Call acceptRecord(args) on the record collector identified by getKey */
public void acceptRecord(final ARGTYPE args, final SAMReadGroupRecord rg) {
String key = UNKNOWN;
if(rg != null) {
final String computedKey = getKey(rg);
if(computedKey != null) {
key = computedKey;
}
}
PerUnitMetricCollector<METRIC_TYPE, Histogram_KEY, ARGTYPE> collector = collectors.get(key);
if (collector == null) {
if (!UNKNOWN.equals(key)) {
throw new PicardException("Could not find collector for " + key);
}
collector = makeUnknownCollector();
collectors.put(key, collector);
}
collector.acceptRecord(args);
}
示例15: HaplotypeBAMDestination
import htsjdk.samtools.SAMReadGroupRecord; //导入依赖的package包/类
/**
* Create a new HaplotypeBAMDestination
*
* @param sourceHeader SAMFileHeader used to seed the output SAMFileHeader for this destination.
* @param haplotypeReadGroupID read group ID used when writing haplotypes as reads
*/
protected HaplotypeBAMDestination(SAMFileHeader sourceHeader, final String haplotypeReadGroupID) {
Utils.nonNull(sourceHeader, "sourceHeader cannot be null");
Utils.nonNull(haplotypeReadGroupID, "haplotypeReadGroupID cannot be null");
this.haplotypeReadGroupID = haplotypeReadGroupID;
bamOutputHeader = new SAMFileHeader();
bamOutputHeader.setSequenceDictionary(sourceHeader.getSequenceDictionary());
bamOutputHeader.setSortOrder(SAMFileHeader.SortOrder.coordinate);
final List<SAMReadGroupRecord> readGroups = new ArrayList<>();
readGroups.addAll(sourceHeader.getReadGroups()); // include the original read groups
// plus an artificial read group for the haplotypes
final SAMReadGroupRecord rgRec = new SAMReadGroupRecord(getHaplotypeReadGroupID());
rgRec.setSample(haplotypeSampleTag);
rgRec.setSequencingCenter("BI");
readGroups.add(rgRec);
bamOutputHeader.setReadGroups(readGroups);
bamOutputHeader.addProgramRecord(new SAMProgramRecord("HalpotypeBAMWriter"));
}