本文整理汇总了Java中htsjdk.samtools.SAMFormatException类的典型用法代码示例。如果您正苦于以下问题:Java SAMFormatException类的具体用法?Java SAMFormatException怎么用?Java SAMFormatException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SAMFormatException类属于htsjdk.samtools包,在下文中一共展示了SAMFormatException类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: parseTag
import htsjdk.samtools.SAMFormatException; //导入依赖的package包/类
private void parseTag(final SAMRecord samRecord, final String tag) {
Map.Entry<String, Object> entry = null;
try {
entry = tagCodec.decode(tag);
} catch (SAMFormatException e) {
e.printStackTrace();
}
if (entry != null) {
if (entry.getValue() instanceof TagValueAndUnsignedArrayFlag) {
final TagValueAndUnsignedArrayFlag valueAndFlag =
(TagValueAndUnsignedArrayFlag) entry.getValue();
if (valueAndFlag.isUnsignedArray) {
samRecord.setUnsignedArrayAttribute(entry.getKey(),
valueAndFlag.value);
} else {
samRecord.setAttribute(entry.getKey(), valueAndFlag.value);
}
} else {
samRecord.setAttribute(entry.getKey(), entry.getValue());
}
}
}
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:23,代码来源:Basic2SAMRecordTransfer.java
示例2: testValidationStringency
import htsjdk.samtools.SAMFormatException; //导入依赖的package包/类
private void testValidationStringency(
final String bamFileName,
final String referenceFileName,
final String validationStringency, final int count) throws SAMFormatException
{
final TestGATKToolValidationStringency tool = new TestGATKToolValidationStringency();
final CommandLineParser clp = new CommandLineArgumentParser(tool);
final File bamFile = new File(NA12878_chr17_1k_CRAM);
final File refFile = new File(v37_chr17_1Mb_Reference);
final String[] args = {
"-I", bamFileName,
"-R", referenceFileName,
"-VS", validationStringency
};
clp.parseArguments(System.out, args);
tool.onStartup();
tool.doWork();
tool.onShutdown();
Assert.assertEquals(tool.getCount(), count);
}
开发者ID:broadinstitute,项目名称:gatk,代码行数:23,代码来源:GATKToolUnitTest.java
示例3: testBadFile
import htsjdk.samtools.SAMFormatException; //导入依赖的package包/类
@Test (dataProvider = "badFiles", expectedExceptions= SAMFormatException.class)
public void testBadFile(final String samFilename) throws IOException {
final File samFile = new File(TEST_DATA_DIR,samFilename);
final File pair1 = File.createTempFile("tt-pair1.", ".fastq");
final File pair2 = File.createTempFile("tt-pair2.", ".fastq");
pair1.deleteOnExit();
pair2.deleteOnExit();
convertFile(new String[]{
"INPUT=" + samFile.getAbsolutePath(),
"FASTQ=" + pair1.getAbsolutePath(),
"SECOND_END_FASTQ=" + pair2.getAbsolutePath()
});
}
开发者ID:broadinstitute,项目名称:picard,代码行数:14,代码来源:SamToFastqTest.java
示例4: testBadGroupedFile
import htsjdk.samtools.SAMFormatException; //导入依赖的package包/类
@Test (dataProvider = "badGroupedFiles", expectedExceptions=SAMFormatException.class)
public void testBadGroupedFile(final String samFilename) throws IOException {
final File samFile = new File(TEST_DATA_DIR, samFilename);
final File pair1File = newTempFastqFile("pair1");
final File pair2File = newTempFastqFile("pair2");
convertFile(new String[]{
"INPUT=" + TEST_DATA_DIR + "/" + samFilename,
"FASTQ=" + pair1File.getAbsolutePath(),
"SECOND_END_FASTQ=" + pair2File.getAbsolutePath()
});
}
开发者ID:broadinstitute,项目名称:picard,代码行数:13,代码来源:SamToFastqTest.java
示例5: BAMSplitGuesser
import htsjdk.samtools.SAMFormatException; //导入依赖的package包/类
/** The stream must point to a valid BAM file, because the header is read
* from it.
*/
public BAMSplitGuesser(
SeekableStream ss, Configuration conf)
throws IOException
{
this(ss, ss, conf);
// Secondary check that the header points to a BAM file: Picard can get
// things wrong due to its autodetection.
ss.seek(0);
if (ss.read(buf.array(), 0, 4) != 4 || buf.getInt(0) != BGZF_MAGIC)
throw new SAMFormatException("Does not seem like a BAM file");
}
开发者ID:HadoopGenomics,项目名称:Hadoop-BAM,代码行数:16,代码来源:BAMSplitGuesser.java
示例6: readSequenceRecord
import htsjdk.samtools.SAMFormatException; //导入依赖的package包/类
private static SAMSequenceRecord readSequenceRecord(final BinaryCodec stream, final String source) {
final int nameLength = stream.readInt();
if (nameLength <= 1) {
throw new SAMFormatException("Invalid BAM file header: missing sequence name in file " + source);
}
final String sequenceName = stream.readString(nameLength - 1);
// Skip the null terminator
stream.readByte();
final int sequenceLength = stream.readInt();
return new SAMSequenceRecord(SAMSequenceRecord.truncateSequenceName(sequenceName), sequenceLength);
}
开发者ID:enasequence,项目名称:cramtools,代码行数:12,代码来源:SAMFileHeader_Utils.java
示例7: readPartOfGeneFile
import htsjdk.samtools.SAMFormatException; //导入依赖的package包/类
private Throwable readPartOfGeneFile(final Chromosome chromosome,
final Integer startIndex, final Integer factor, final Integer num,
final Integer endIndex,
final ReaderState state, Double scaleFactor)
throws IOException {
double time0 = Utils.getSystemTimeMilliseconds();
try (AbstractFeatureReader<GeneFeature, LineIterator> featureReader = fileManager.makeGeneReader(
geneFile, determineGeneFileType(scaleFactor))) {
LOGGER.debug("Thread {} starts", Thread.currentThread().getName());
double time11 = Utils.getSystemTimeMilliseconds();
LOGGER.debug("Thread {} Reader creation {} ms", Thread.currentThread().getName(), time11 - time0);
int start = startIndex + factor * ParallelTaskExecutionUtils.MAX_BLOCK_SIZE;
int end;
if (factor != num - 1) {
end = startIndex + (factor + 1) * ParallelTaskExecutionUtils.MAX_BLOCK_SIZE;
} else {
end = endIndex;
}
LOGGER.debug("Thread {} Interval: {} - {}", Thread.currentThread().getName(), start, end);
try (CloseableIterator<GeneFeature> iterator = Utils.query(featureReader, chromosome, start, end)) {
double time21 = Utils.getSystemTimeMilliseconds();
LOGGER.debug("Thread {} Query took {} ms", Thread.currentThread().getName(), time21 - time11);
Map<String, Gene> overlappedMrnas = new HashMap<>();
time11 = Utils.getSystemTimeMilliseconds();
if (iterator.hasNext()) {
GeneFeature firstFeature = iterator.next();
processFeature(state, firstFeature, overlappedMrnas, start, end);
}
iterator.forEachRemaining(feature -> processFeature(state, feature, overlappedMrnas, start, end));
time21 = Utils.getSystemTimeMilliseconds();
LOGGER.debug("Thread {} Walkthrough took {} ms",
Thread.currentThread().getName(), time21 - time11);
fillExonsCountForOverlapping(overlappedMrnas, featureReader, chromosome);
} catch (SAMFormatException e) {
LOGGER.error("", e);
return e;
}
LOGGER.debug("Thread {} ends", Thread.currentThread().getName());
return null;
}
}
开发者ID:react-dev26,项目名称:NGB-master,代码行数:48,代码来源:AbstractGeneReader.java
示例8: initialize
import htsjdk.samtools.SAMFormatException; //导入依赖的package包/类
@Override public void initialize(InputSplit spl, TaskAttemptContext ctx)
throws IOException
{
// This method should only be called once (see Hadoop API). However,
// there seems to be disagreement between implementations that call
// initialize() and Hadoop-BAM's own code that relies on
// {@link SAMInputFormat} to call initialize() when the reader is
// created. Therefore we add this check for the time being.
if(isInitialized)
close();
isInitialized = true;
final FileSplit split = (FileSplit)spl;
this.start = split.getStart();
this.end = start + split.getLength();
final Configuration conf = ctx.getConfiguration();
final ValidationStringency stringency =
SAMHeaderReader.getValidationStringency(conf);
final Path file = split.getPath();
final FileSystem fs = file.getFileSystem(conf);
input = fs.open(file);
// SAMFileReader likes to make our life difficult, so complexity ensues.
// The basic problem is that SAMFileReader buffers its input internally,
// which causes two issues.
//
// Issue #1 is that SAMFileReader requires that its input begins with a
// SAM header. This is not fine for reading from the middle of a file.
// Because of the buffering, if we have the reader read the header from
// the beginning of the file and then seek to where we want to read
// records from, it'll have buffered some records from immediately after
// the header, which is no good. Thus we need to read the header
// separately and then use a custom stream that wraps the input stream,
// inserting the header at the beginning of it. (Note the spurious
// re-encoding of the header so that the reader can decode it.)
//
// Issue #2 is handling the boundary between two input splits. The best
// way seems to be the classic "in later splits, skip the first line, and
// in every split finish reading a partial line at the end of the split",
// but that latter part is a bit complicated here. Due to the buffering,
// we can easily overshoot: as soon as the stream moves past the end of
// the split, SAMFileReader has buffered some records past the end. The
// basic fix here is to have our custom stream count the number of bytes
// read and to stop after the split size. Unfortunately this prevents us
// from reading the last partial line, so our stream actually allows
// reading to the next newline after the actual end.
final SAMFileHeader header = createSamReader(input, stringency).getFileHeader();
waInput = new WorkaroundingStream(input, header);
final boolean firstSplit = this.start == 0;
if (firstSplit) {
// Skip the header because we already have it, and adjust the start
// to match.
final int headerLength = waInput.getRemainingHeaderLength();
input.seek(headerLength);
this.start += headerLength;
} else
input.seek(--this.start);
// Creating the iterator causes reading from the stream, so make sure
// to start counting this early.
waInput.setLength(this.end - this.start);
iterator = createSamReader(waInput, stringency).iterator();
if (!firstSplit) {
// Skip the first line, it'll be handled with the previous split.
try {
if (iterator.hasNext())
iterator.next();
} catch (SAMFormatException e) {}
}
}
开发者ID:HadoopGenomics,项目名称:Hadoop-BAM,代码行数:82,代码来源:SAMRecordReader.java
示例9: testReadsValidationStringencyStrict
import htsjdk.samtools.SAMFormatException; //导入依赖的package包/类
@Test(dataProvider = "validationStringency", expectedExceptions=SAMFormatException.class)
public void testReadsValidationStringencyStrict(final String bamFileName, final String referenceFileName, int count) throws Exception {
testValidationStringency(bamFileName, referenceFileName, "STRICT", count);
}
开发者ID:broadinstitute,项目名称:gatk,代码行数:5,代码来源:GATKToolUnitTest.java
示例10: queryMate
import htsjdk.samtools.SAMFormatException; //导入依赖的package包/类
@Override
public SAMRecord queryMate(SAMRecord rec) {
if (!rec.getReadPairedFlag()) {
throw new IllegalArgumentException("queryMate called for unpaired read.");
}
if (rec.getFirstOfPairFlag() == rec.getSecondOfPairFlag()) {
throw new IllegalArgumentException(
"SAMRecord must be either first and second of pair, but not both.");
}
final boolean firstOfPair = rec.getFirstOfPairFlag();
final CloseableIterator<SAMRecord> it;
if (rec.getMateReferenceIndex() == SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX) {
it = queryUnmapped();
} else {
it = queryAlignmentStart(rec.getMateReferenceName(), rec.getMateAlignmentStart());
}
try {
SAMRecord mateRec = null;
while (it.hasNext()) {
final SAMRecord next = it.next();
if (!next.getReadPairedFlag()) {
if (rec.getReadName().equals(next.getReadName())) {
throw new SAMFormatException(
"Paired and unpaired reads with same name: " + rec.getReadName());
}
continue;
}
if (firstOfPair) {
if (next.getFirstOfPairFlag()) {
continue;
}
} else {
if (next.getSecondOfPairFlag()) {
continue;
}
}
if (rec.getReadName().equals(next.getReadName())) {
if (mateRec != null) {
throw new SAMFormatException(
"Multiple SAMRecord with read name " + rec.getReadName() +
" for " + (firstOfPair ? "second" : "first") + " end.");
}
mateRec = next;
}
}
return mateRec;
} finally {
it.close();
}
}
开发者ID:googlegenomics,项目名称:gatk-tools-java,代码行数:51,代码来源:GA4GHSamReader.java
示例11: reduce
import htsjdk.samtools.SAMFormatException; //导入依赖的package包/类
/**
* 'key': the identifier of the aligned read without the integer indicating
* the member of the pair. 'values': the rest of the paired alignments, i.e
* the SAM line of the first paired alignment and the SAM line of the second
* paired alignment.
*/
@Override
protected void reduce(final Text key, final Iterable<Text> values,
final Context context) throws IOException, InterruptedException {
String stringVal;
final String strOutKey;
StringBuilder strOutValue = new StringBuilder();
SAMRecord samRecord;
String stringRecord;
this.records.clear();
for (Text val : values) {
stringVal = val.toString();
stringRecord = key.toString() + stringVal;
try {
samRecord = this.parser.parseLine(stringRecord);
this.records.add(samRecord);
} catch (SAMFormatException e) {
context.getCounter(this.counterGroup,
INVALID_SAM_ENTRIES_COUNTER.counterName()).increment(1);
getLogger().info("Invalid SAM output entry: "
+ e.getMessage() + " line='" + stringRecord + "'");
return;
}
}
// sort alignments of the current read
Collections.sort(this.records, new SAMComparator());
// Writing records
int indexOfFirstTab = this.records.get(0).getSAMString().indexOf("\t");
strOutKey =
this.records.get(0).getSAMString().substring(0, indexOfFirstTab);
strOutValue.append(this.records.get(0).getSAMString()
.substring(indexOfFirstTab + 1).replaceAll("\n", ""));
this.records.remove(0);
for (SAMRecord r : this.records) {
if (r.getFirstOfPairFlag()) {
strOutValue.append('\n');
} else {
strOutValue.append(SAM_RECORD_PAIRED_END_SERPARATOR);
}
strOutValue.append(r.getSAMString().replaceAll("\n", ""));
}
this.outKey.set(strOutKey);
this.outValue.set(strOutValue.toString());
context.write(this.outKey, this.outValue);
}
开发者ID:GenomicParisCentre,项目名称:eoulsan,代码行数:63,代码来源:PreTreatmentExpressionReducer.java
示例12: readHeader
import htsjdk.samtools.SAMFormatException; //导入依赖的package包/类
static SAMFileHeader readHeader(final BinaryCodec stream, final ValidationStringency validationStringency,
final String source) throws IOException {
final byte[] buffer = new byte[4];
stream.readBytes(buffer);
if (!Arrays.equals(buffer, "BAM\1".getBytes())) {
throw new IOException("Invalid BAM file header");
}
final int headerTextLength = stream.readInt();
final String textHeader = stream.readString(headerTextLength);
final SAMTextHeaderCodec headerCodec = new SAMTextHeaderCodec();
headerCodec.setValidationStringency(validationStringency);
final SAMFileHeader samFileHeader = headerCodec.decode(new StringLineReader(textHeader), source);
final int sequenceCount = stream.readInt();
if (samFileHeader.getSequenceDictionary().size() > 0) {
// It is allowed to have binary sequences but no text sequences, so
// only validate if both are present
if (sequenceCount != samFileHeader.getSequenceDictionary().size()) {
throw new SAMFormatException("Number of sequences in text header ("
+ samFileHeader.getSequenceDictionary().size() + ") != number of sequences in binary header ("
+ sequenceCount + ") for file " + source);
}
for (int i = 0; i < sequenceCount; i++) {
final SAMSequenceRecord binarySequenceRecord = readSequenceRecord(stream, source);
final SAMSequenceRecord sequenceRecord = samFileHeader.getSequence(i);
if (!sequenceRecord.getSequenceName().equals(binarySequenceRecord.getSequenceName())) {
throw new SAMFormatException("For sequence " + i
+ ", text and binary have different names in file " + source);
}
if (sequenceRecord.getSequenceLength() != binarySequenceRecord.getSequenceLength()) {
throw new SAMFormatException("For sequence " + i
+ ", text and binary have different lengths in file " + source);
}
}
} else {
// If only binary sequences are present, copy them into
// samFileHeader
final List<SAMSequenceRecord> sequences = new ArrayList<SAMSequenceRecord>(sequenceCount);
for (int i = 0; i < sequenceCount; i++) {
sequences.add(readSequenceRecord(stream, source));
}
samFileHeader.setSequenceDictionary(new SAMSequenceDictionary(sequences));
}
return samFileHeader;
}
开发者ID:enasequence,项目名称:cramtools,代码行数:49,代码来源:SAMFileHeader_Utils.java
注:本文中的htsjdk.samtools.SAMFormatException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论