本文整理汇总了Java中htsjdk.samtools.SamReader.close方法的典型用法代码示例。如果您正苦于以下问题:Java SamReader.close方法的具体用法?Java SamReader.close怎么用?Java SamReader.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.samtools.SamReader
的用法示例。
在下文中一共展示了SamReader.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
public static void main(String args[]) throws IOException, ParseException {
Options options = new Options();
options.addOption("u","uniquehits",false,"only output hits with a single mapping");
options.addOption("s","nosuboptimal",false,"do not include hits whose score is not equal to the best score for the read");
options.addOption("p","pairedend",false,"output paired-end hits");
options.addOption("j","junctions",false,"output junction mapping reads (reads with gaps)");
CommandLineParser parser = new GnuParser();
CommandLine cl = parser.parse( options, args, false );
uniqueOnly = cl.hasOption("uniquehits");
filterSubOpt = cl.hasOption("nosuboptimal");
inclPairedEnd = cl.hasOption("pairedend");
inclJunction = cl.hasOption("junctions");
SamReaderFactory factory =
SamReaderFactory.makeDefault()
.enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS)
.validationStringency(ValidationStringency.SILENT);
SamReader reader = factory.open(SamInputResource.of(System.in));
CloseableIterator<SAMRecord> iter = reader.iterator();
while (iter.hasNext()) {
SAMRecord record = iter.next();
if (record.getReadUnmappedFlag()) {continue; }
processRecord(record);
}
iter.close();
reader.close();
}
示例2: sliceFromS3
import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
private static void sliceFromS3(@NotNull final CommandLine cmd) throws IOException, EmptyFileException {
final OkHttpClient httpClient = SbpS3Client.create(Integer.parseInt(cmd.getOptionValue(MAX_CONCURRENT_REQUESTS)));
final URL bamUrl = SbpS3UrlGenerator.generateUrl(cmd.getOptionValue(BUCKET), cmd.getOptionValue(INPUT));
final URL indexUrl = SbpS3UrlGenerator.generateUrl(cmd.getOptionValue(BUCKET), cmd.getOptionValue(INDEX));
final String outputPath = cmd.getOptionValue(OUTPUT);
final String bedPath = cmd.getOptionValue(BED);
final int maxBufferSize = readMaxBufferSize(cmd);
final File indexFile = downloadIndex(indexUrl);
final SamReader reader = SamReaderFactory.makeDefault().open(SamInputResource.of(bamUrl).index(indexFile));
LOGGER.info("Generating query intervals from BED file: {}", bedPath);
final QueryInterval[] intervals = getIntervalsFromBED(bedPath, reader.getFileHeader());
final BAMFileSpan span = bamSpanForIntervals(indexFile, reader.getFileHeader(), intervals);
final List<Chunk> expandedChunks = expandChunks(span.getChunks());
LOGGER.info("Generated {} query intervals which map to {} bam chunks", intervals.length, expandedChunks.size());
final SamInputResource bamResource =
SamInputResource.of(new CachingSeekableHTTPStream(httpClient, bamUrl, expandedChunks, maxBufferSize)).index(indexFile);
final SamReader cachingReader = SamReaderFactory.makeDefault().open(bamResource);
LOGGER.info("Slicing bam...");
final CloseableIterator<SAMRecord> iterator = getIterator(cachingReader, intervals, span.toCoordinateArray());
writeToSlice(outputPath, cachingReader.getFileHeader(), iterator);
cachingReader.close();
reader.close();
indexFile.deleteOnExit();
}
示例3: parseContigFromBam
import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
private Map<String, Sequence> parseContigFromBam() {
// TODO Auto-generated method stub
final Map<String, Sequence> contig_list = new HashMap<String, Sequence>();
final SamReader in1 = factory.open(new File(this.bam_list[0]));
try {
List<SAMSequenceRecord> seqs =
in1.getFileHeader().getSequenceDictionary().getSequences();
for(SAMSequenceRecord seq : seqs)
contig_list.put( seq.getSequenceName(),
new Sequence(seq.getSequenceIndex(), seq.getSequenceLength()) );
in1.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return contig_list;
}
示例4: bamHasIndex
import htsjdk.samtools.SamReader; //导入方法依赖的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;
}
示例5: getAlignedReadCount
import htsjdk.samtools.SamReader; //导入方法依赖的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;
}
示例6: main
import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
SamReader reader = SamReaderFactory
.makeDefault()
.validationStringency(ValidationStringency.SILENT)
.open(new File(
"./data/miniCaviar_IDT_NEB.runA.NA12878.bwa.chrom1.bam"));
SAMFileHeader samFileHeader = reader.getFileHeader();
System.out.println(samFileHeader.getTextHeader());
int i = 0;
for (SAMRecord record : reader) {
if (i < 100)
System.out.println(record.getAlignmentStart());
i++;
}
reader.close();
}
示例7: main
import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
File bamFile = new File(
"./data/miniCaviar_IDT_NEB.runA.NA12878.bwa.bam");
File newBamFile = new File(
"./data/miniCaviar_IDT_NEB.runA.NA12878.bwa.chrom1.bam");
SAMFileWriter outputSam = null;
final SamReader reader = SamReaderFactory.makeDefault()
.validationStringency(ValidationStringency.SILENT)
.open(bamFile);
outputSam = new SAMFileWriterFactory().makeBAMWriter(
reader.getFileHeader(), true, newBamFile);
int currentReads = 0;
for (final SAMRecord samRecord : reader) {
if (samRecord.getReferenceIndex() == 0)
writeBam(samRecord, outputSam);
}
reader.close();
outputSam.close();
}
示例8: createSamMatePairsMap
import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
private Map<String,MatePair> createSamMatePairsMap(final File samFile) throws IOException {
IOUtil.assertFileIsReadable(samFile);
final SamReader reader = SamReaderFactory.makeDefault().open(samFile);
final Map<String,MatePair> map = new LinkedHashMap<String,MatePair>();
for (final SAMRecord record : reader ) {
MatePair mpair = map.get(record.getReadName());
if (mpair == null) {
mpair = new MatePair();
map.put(record.getReadName(), mpair);
}
mpair.add(record);
}
reader.close();
return map;
}
示例9: createPUPairsMap
import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
private Map<String, Map<String, MatePair>> createPUPairsMap(final File samFile) throws IOException {
IOUtil.assertFileIsReadable(samFile);
final SamReader reader = SamReaderFactory.makeDefault().open(samFile);
final Map<String, Map<String, MatePair>> map = new LinkedHashMap<String, Map<String,MatePair>>();
Map<String,MatePair> curFileMap;
for (final SAMRecord record : reader ) {
final String platformUnit = record.getReadGroup().getPlatformUnit();
curFileMap = map.get(platformUnit);
if(curFileMap == null)
{
curFileMap = new LinkedHashMap<String, MatePair>();
map.put(platformUnit, curFileMap);
}
MatePair mpair = curFileMap.get(record.getReadName());
if (mpair == null) {
mpair = new MatePair();
curFileMap.put(record.getReadName(), mpair);
}
mpair.add(record);
}
reader.close();
return map;
}
示例10: convertFileAndVerifyRecordCount
import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
private void convertFileAndVerifyRecordCount(final int expectedCount,
final String fastqFilename1,
final String fastqFilename2,
final FastqQualityFormat version,
final boolean permissiveFormat,
final boolean useSequentialFastqs) throws IOException {
final File samFile = convertFile(fastqFilename1, fastqFilename2, version, permissiveFormat, useSequentialFastqs);
final SamReader samReader = SamReaderFactory.makeDefault().open(samFile);
final SAMRecordIterator iterator = samReader.iterator();
int actualCount = 0;
while (iterator.hasNext()) {
iterator.next();
actualCount++;
}
samReader.close();
Assert.assertEquals(actualCount, expectedCount);
}
示例11: testCleanSam
import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
@Test(dataProvider = "testCleanSamDataProvider")
public void testCleanSam(final String samFile, final String expectedCigar) throws IOException {
final File cleanedFile = File.createTempFile(samFile + ".", ".sam");
cleanedFile.deleteOnExit();
final String[] args = new String[]{
"INPUT=" + new File(TEST_DATA_DIR, samFile).getAbsolutePath(),
"OUTPUT=" + cleanedFile.getAbsolutePath()
};
Assert.assertEquals(runPicardCommandLine(args), 0);
final SamFileValidator validator = new SamFileValidator(new PrintWriter(System.out), 8000);
validator.setIgnoreWarnings(true);
validator.setVerbose(true, 1000);
validator.setErrorsToIgnore(Arrays.asList(SAMValidationError.Type.MISSING_READ_GROUP));
SamReader samReader = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.LENIENT).open(cleanedFile);
final SAMRecord rec = samReader.iterator().next();
samReader.close();
Assert.assertEquals(rec.getCigarString(), expectedCigar);
samReader = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.LENIENT).open(cleanedFile);
final boolean validated = validator.validateSamFileVerbose(samReader, null);
samReader.close();
Assert.assertTrue(validated, "ValidateSamFile failed");
}
示例12: createIndexedBam
import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
/**
* Useful test method. Creates a (temporary) indexed BAM so that we can store a sam in the testdata set.
*
* @param samFile the sam file to convert to bam and index
* @return File a (temporary) bam file (index file is created in same path).
*/
public static File createIndexedBam(final File samFile, final File tempFilePrefix) throws IOException {
final File output = File.createTempFile(tempFilePrefix.getAbsolutePath(), ".bam");
output.deleteOnExit();
final File indexFile = new File(output.getAbsolutePath() + ".bai");
indexFile.deleteOnExit();
final SamReader in = SamReaderFactory.makeDefault().open(samFile);
SAMFileWriter out = new SAMFileWriterFactory().setCreateIndex(true).makeBAMWriter(in.getFileHeader(), true, output);
in.iterator().stream().forEach(out::addAlignment);
out.close();
in.close();
return output;
}
示例13: testReader
import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
@Test
public void testReader() throws Exception {
int expectedCount = 0;
SamReader samReader = SamReaderFactory.makeDefault().open(new File(input));
for (SAMRecord r : samReader) {
expectedCount++;
}
samReader.close();
AnySAMInputFormat inputFormat = new AnySAMInputFormat();
List<InputSplit> splits = inputFormat.getSplits(jobContext);
assertEquals(1, splits.size());
RecordReader<LongWritable, SAMRecordWritable> reader = inputFormat
.createRecordReader(splits.get(0), taskAttemptContext);
reader.initialize(splits.get(0), taskAttemptContext);
int actualCount = 0;
while (reader.nextKeyValue()) {
actualCount++;
}
reader.close();
assertEquals(expectedCount, actualCount);
}
示例14: SAMStats
import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
public SAMStats(boolean bowtie1, boolean bowtie2){
this.bowtie1 = bowtie1;
this.bowtie2 = bowtie2;
histo = new RealValuedHistogram(0, 1000, 100);
SamReaderFactory factory =
SamReaderFactory.makeDefault()
.enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS)
.validationStringency(ValidationStringency.SILENT);
SamReader reader = factory.open(SamInputResource.of(System.in));
CloseableIterator<SAMRecord> iter = reader.iterator();
while (iter.hasNext()) {
SAMRecord record = iter.next();
if(readLen==-1)
readLen = record.getReadLength();
if(bowtie1)
processBT1SAMRecord(record);
else if(bowtie2)
processBT2SAMRecord(record);
else
processSAMRecord(record);
}
iter.close();
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例15: main
import htsjdk.samtools.SamReader; //导入方法依赖的package包/类
public static void main(String args[]) throws IOException, ParseException {
Options options = new Options();
options.addOption("l","left",true,"filename of left side of read");
options.addOption("r","right",true,"filename of right side of read");
options.addOption("u","uniquehits",false,"only output hits with a single mapping");
options.addOption("s","nosuboptimal",false,"do not include hits whose score is not equal to the best score for the read");
options.addOption("D","debug",false,"enable debugging spew?");
CommandLineParser parser = new GnuParser();
CommandLine cl = parser.parse( options, args, false );
uniqueOnly = cl.hasOption("uniquehits");
filterSubOpt = cl.hasOption("nosuboptimal");
debug = cl.hasOption("debug");
String leftfile = cl.getOptionValue("left");
String rightfile = cl.getOptionValue("right");
SamReaderFactory factory =
SamReaderFactory.makeDefault()
.enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS)
.validationStringency(ValidationStringency.SILENT);
SamReader leftreader = factory.open(SamInputResource.of(new FileInputStream(leftfile)));
SamReader rightreader = factory.open(SamInputResource.of(new FileInputStream(rightfile)));
leftiter = leftreader.iterator();
rightiter = rightreader.iterator();
leftbuffer = new ArrayList<SAMRecord>();
rightbuffer = new ArrayList<SAMRecord>();
makePairs();
leftreader.close();
rightreader.close();
}