本文整理汇总了Java中htsjdk.samtools.SamReaderFactory.validationStringency方法的典型用法代码示例。如果您正苦于以下问题:Java SamReaderFactory.validationStringency方法的具体用法?Java SamReaderFactory.validationStringency怎么用?Java SamReaderFactory.validationStringency使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.samtools.SamReaderFactory
的用法示例。
在下文中一共展示了SamReaderFactory.validationStringency方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setSamSeqDictFromBam
import htsjdk.samtools.SamReaderFactory; //导入方法依赖的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;
}
示例2: getAlignedReadCount
import htsjdk.samtools.SamReaderFactory; //导入方法依赖的package包/类
public static long getAlignedReadCount(String bam) throws IOException{
/* ------------------------------------------------------ */
/* This chunk prepares SamReader from local bam or URL bam */
UrlValidator urlValidator = new UrlValidator();
SamReaderFactory srf=SamReaderFactory.make();
srf.validationStringency(ValidationStringency.SILENT);
SamReader samReader;
if(urlValidator.isValid(bam)){
samReader = SamReaderFactory.makeDefault().open(
SamInputResource.of(new URL(bam)).index(new URL(bam + ".bai"))
);
} else {
samReader= srf.open(new File(bam));
}
/* ------------------------------------------------------ */
List<SAMSequenceRecord> sequences = samReader.getFileHeader().getSequenceDictionary().getSequences();
long alnCount= 0;
for(SAMSequenceRecord x : sequences){
alnCount += samReader.indexing().getIndex().getMetaData(x.getSequenceIndex()).getAlignedRecordCount();
}
samReader.close();
return alnCount;
}
示例3: bamHasIndex
import htsjdk.samtools.SamReaderFactory; //导入方法依赖的package包/类
public static boolean bamHasIndex(String bam) throws IOException{
/* ------------------------------------------------------ */
/* This chunk prepares SamReader from local bam or URL bam */
UrlValidator urlValidator = new UrlValidator();
SamReaderFactory srf=SamReaderFactory.make();
srf.validationStringency(ValidationStringency.SILENT);
SamReader samReader;
if(urlValidator.isValid(bam)){
samReader = SamReaderFactory.makeDefault().open(
SamInputResource.of(new URL(bam)).index(new URL(bam + ".bai"))
);
} else {
samReader= srf.open(new File(bam));
}
/* ------------------------------------------------------ */
// SamReaderFactory srf=SamReaderFactory.make();
// srf.validationStringency(ValidationStringency.SILENT);
// SamReader samReader = srf.open(new File(bam));
boolean hasIndex= samReader.hasIndex();
samReader.close();
return hasIndex;
}
示例4: readSAMHeaderFrom
import htsjdk.samtools.SamReaderFactory; //导入方法依赖的package包/类
/** Does not close the stream. */
public static SAMFileHeader readSAMHeaderFrom(
final InputStream in, final Configuration conf)
{
final ValidationStringency
stringency = getValidationStringency(conf);
SamReaderFactory readerFactory = SamReaderFactory.makeDefault()
.setOption(SamReaderFactory.Option.EAGERLY_DECODE, false)
.setUseAsyncIo(false);
if (stringency != null) {
readerFactory.validationStringency(stringency);
}
final ReferenceSource refSource = getReferenceSource(conf);
if (null != refSource) {
readerFactory.referenceSource(refSource);
}
return readerFactory.open(SamInputResource.of(in)).getFileHeader();
}
示例5: reOpen
import htsjdk.samtools.SamReaderFactory; //导入方法依赖的package包/类
@Override
public BamFile reOpen() throws IOException {
final String url=this.getSource();
final SamReaderFactory srf = SamReaderFactory.makeDefault();
srf.validationStringency(ValidationStringency.LENIENT);
final SamInputResource sir;
if(IOUtil.isUrl(url))
{
sir = SamInputResource.of(new URL(url));
if(!this.indexFile.isPresent()) throw new IOException("Boum");
sir.index(this.indexFile.get());
}
else
{
sir = SamInputResource.of(new File(url));
}
final BamFile bf = new BamFile(url,srf.open(sir),this.indexFile);
bf.delete_index_on_close=false;
return bf;
}
示例6: countReadsInWindow
import htsjdk.samtools.SamReaderFactory; //导入方法依赖的package包/类
/**
* Count reads in interval using the given filters.
* @param bam
* @param gc
* @param filters List of filters to apply
* @return
* @throws MalformedURLException
*/
public static long countReadsInWindow(String bam, GenomicCoords gc, List<SamRecordFilter> filters) throws MalformedURLException {
/* ------------------------------------------------------ */
/* This chunk prepares SamReader from local bam or URL bam */
UrlValidator urlValidator = new UrlValidator();
SamReaderFactory srf=SamReaderFactory.make();
srf.validationStringency(ValidationStringency.SILENT);
SamReader samReader;
if(urlValidator.isValid(bam)){
samReader = srf.open(SamInputResource.of(new URL(bam)).index(new URL(bam + ".bai")));
} else {
samReader= srf.open(new File(bam));
}
/* ------------------------------------------------------ */
long cnt= 0;
Iterator<SAMRecord> sam= samReader.query(gc.getChrom(), gc.getFrom(), gc.getTo(), false);
AggregateFilter aggregateFilter= new AggregateFilter(filters);
while(sam.hasNext()){
SAMRecord rec= sam.next();
if( !aggregateFilter.filterOut(rec) ){
cnt++;
}
}
try {
samReader.close();
} catch (IOException e) {
e.printStackTrace();
}
return cnt;
}
示例7: getSamReader
import htsjdk.samtools.SamReaderFactory; //导入方法依赖的package包/类
/** Prepare SamReader from local bam or URL bam */
public static SamReader getSamReader(String workFilename) throws MalformedURLException {
UrlValidator urlValidator = new UrlValidator();
SamReaderFactory srf=SamReaderFactory.make();
srf.validationStringency(ValidationStringency.SILENT);
SamReader samReader;
if(urlValidator.isValid(workFilename)){
samReader = srf.open(SamInputResource.of(new URL(workFilename)).index(new URL(workFilename + ".bai")));
} else {
samReader= srf.open(new File(workFilename));
}
return samReader;
}
示例8: sortAndIndexSamOrBam
import htsjdk.samtools.SamReaderFactory; //导入方法依赖的package包/类
/** Sort and index input sam or bam.
* @throws IOException
* */
public static void sortAndIndexSamOrBam(String inSamOrBam, String sortedBam, boolean deleteOnExit) throws IOException {
/* ------------------------------------------------------ */
/* This chunk prepares SamReader from local bam or URL bam */
UrlValidator urlValidator = new UrlValidator();
SamReaderFactory srf=SamReaderFactory.make();
srf.validationStringency(ValidationStringency.SILENT);
SamReader samReader;
if(urlValidator.isValid(inSamOrBam)){
samReader = SamReaderFactory.makeDefault().open(SamInputResource.of(new URL(inSamOrBam)));
} else {
samReader= srf.open(new File(inSamOrBam));
}
/* ------------------------------------------------------ */
samReader.getFileHeader().setSortOrder(SortOrder.coordinate);
File out= new File(sortedBam);
if(deleteOnExit){
out.deleteOnExit();
File idx= new File(out.getAbsolutePath().replaceAll("\\.bam$", "") + ".bai");
idx.deleteOnExit();
}
SAMFileWriter outputSam= new SAMFileWriterFactory()
.setCreateIndex(true)
.makeSAMOrBAMWriter(samReader.getFileHeader(), false, out);
for (final SAMRecord samRecord : samReader) {
outputSam.addAlignment(samRecord);
}
samReader.close();
outputSam.close();
}
示例9: doWork
import htsjdk.samtools.SamReaderFactory; //导入方法依赖的package包/类
/**
* Do the work after command line has been parsed.
* RuntimeException may be thrown by this method, and are reported appropriately.
*
* @return program exit status.
*/
@Override
protected int doWork() {
IOUtil.assertFileIsReadable(INPUT);
IOUtil.assertFileIsWritable(OUTPUT);
final SamReaderFactory factory = SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE);
if (VALIDATION_STRINGENCY == ValidationStringency.STRICT) {
factory.validationStringency(ValidationStringency.LENIENT);
}
final SamReader reader = factory.open(INPUT);
final SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(reader.getFileHeader(), true, OUTPUT);
final CloseableIterator<SAMRecord> it = reader.iterator();
final ProgressLogger progress = new ProgressLogger(Log.getInstance(CleanSam.class));
// If the read (or its mate) maps off the end of the alignment, clip it
while (it.hasNext()) {
final SAMRecord rec = it.next();
// If the read (or its mate) maps off the end of the alignment, clip it
AbstractAlignmentMerger.createNewCigarsIfMapsOffEndOfReference(rec);
// check the read's mapping quality
if (rec.getReadUnmappedFlag() && 0 != rec.getMappingQuality()) {
rec.setMappingQuality(0);
}
writer.addAlignment(rec);
progress.record(rec);
}
writer.close();
it.close();
CloserUtil.close(reader);
return 0;
}
示例10: createSamReader
import htsjdk.samtools.SamReaderFactory; //导入方法依赖的package包/类
private SamReader createSamReader(SeekableStream in, SeekableStream inIndex,
ValidationStringency stringency) {
SamReaderFactory readerFactory = SamReaderFactory.makeDefault()
.setOption(SamReaderFactory.Option.CACHE_FILE_BASED_INDEXES, true)
.setOption(SamReaderFactory.Option.EAGERLY_DECODE, false)
.setUseAsyncIo(false);
if (stringency != null) {
readerFactory.validationStringency(stringency);
}
SamInputResource resource = SamInputResource.of(in);
if (inIndex != null) {
resource.index(inIndex);
}
return readerFactory.open(resource);
}
示例11: createSamReader
import htsjdk.samtools.SamReaderFactory; //导入方法依赖的package包/类
private SamReader createSamReader(InputStream in, ValidationStringency stringency) {
SamReaderFactory readerFactory = SamReaderFactory.makeDefault()
.setOption(SamReaderFactory.Option.EAGERLY_DECODE, false)
.setUseAsyncIo(false);
if (stringency != null) {
readerFactory.validationStringency(stringency);
}
return readerFactory.open(SamInputResource.of(in));
}
示例12: exec
import htsjdk.samtools.SamReaderFactory; //导入方法依赖的package包/类
@Exec
public void exec() throws IOException, CommandArgumentException {
if (filename == null) {
throw new CommandArgumentException("You must specify an input BAM filename!");
}
SamReaderFactory readerFactory = SamReaderFactory.makeDefault();
if (lenient) {
readerFactory.validationStringency(ValidationStringency.LENIENT);
} else if (silent) {
readerFactory.validationStringency(ValidationStringency.SILENT);
}
SamReader reader = null;
String name;
FileChannel channel = null;
if (filename.equals("-")) {
reader = readerFactory.open(SamInputResource.of(System.in));
name = "<stdin>";
} else {
File f = new File(filename);
FileInputStream fis = new FileInputStream(f);
channel = fis.getChannel();
reader = readerFactory.open(SamInputResource.of(fis));
name = f.getName();
}
Set<String> readNames = new HashSet<String>();
Iterator<SAMRecord> it = ProgressUtils.getIterator(name, reader.iterator(), (channel == null)? null : new FileChannelStats(channel), new ProgressMessage<SAMRecord>() {
long i = 0;
@Override
public String msg(SAMRecord current) {
i++;
return i+" "+current.getReadName();
}}, new CloseableFinalizer<SAMRecord>());
System.err.print("Reading file...");
while (it.hasNext()) {
readNames.add(it.next().getReadName());
}
System.err.println(" done");
reader.close();
List<String> readNameList = new ArrayList<String>(readNames);
readNames.clear();
for (int i=1; i<=numberOfSamplings; i++) {
System.err.println("Generating list #"+i+"...");
Random rdm = new Random();
Set<String> keptReads = new HashSet<String>();
int j=0;
while (j<sampleSize) {
int idx = rdm.nextInt(readNameList.size());
if (!keptReads.contains(readNameList.get(idx))) {
keptReads.add(readNameList.get(idx));
j++;
}
}
OutputStream os = new FileOutputStream(outputFilename+"."+i+".txt");
for (String readName: keptReads) {
os.write((readName+"\n").getBytes());
}
os.close();
}
}
示例13: newInstance
import htsjdk.samtools.SamReaderFactory; //导入方法依赖的package包/类
public static BamFile newInstance(final File f) throws IOException {
IOUtil.assertFileIsReadable(f);
final SamReaderFactory srf = SamReaderFactory.makeDefault();
srf.validationStringency(ValidationStringency.LENIENT);
return new BamFile(f.getAbsolutePath(),srf.open(f),Optional.empty());
}