本文整理汇总了Java中htsjdk.samtools.util.SequenceUtil类的典型用法代码示例。如果您正苦于以下问题:Java SequenceUtil类的具体用法?Java SequenceUtil怎么用?Java SequenceUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SequenceUtil类属于htsjdk.samtools.util包,在下文中一共展示了SequenceUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkNucleotideRegex
import htsjdk.samtools.util.SequenceUtil; //导入依赖的package包/类
/**
* Determine whether it's a valid regex.
* Also, any letters should be one of AGCTN (case insensitive)
*
* @param strPattern
* @return
*/
static boolean checkNucleotideRegex(String strPattern) {
try {
//First check if it's valid regex
Pattern pattern = Pattern.compile(strPattern);
byte[] bytes = strPattern.getBytes();
for (byte c : bytes) {
if (Character.isLetter(c)) {
boolean validBase = SequenceUtil.isValidBase(c);
validBase |= c == 'N';
if (!validBase) return false;
}
}
} catch (PatternSyntaxException e) {
return false;
}
return true;
}
示例2: countMismatches
import htsjdk.samtools.util.SequenceUtil; //导入依赖的package包/类
/**
* Compare barcode sequence to bases from read
*
* @return how many bases did not match
*/
private static int countMismatches(final byte[][] barcodeBytes, final byte[][] readSubsequence, final byte[][] qualities, final int minimumBaseQuality) {
int numMismatches = 0;
for (int j = 0; j < barcodeBytes.length; j++) {
for (int i = 0; (i < barcodeBytes[j].length && readSubsequence[j].length > i); ++i) {
if (SequenceUtil.isNoCall(readSubsequence[j][i])) {
continue;
}
if (!SequenceUtil.basesEqual(barcodeBytes[j][i], readSubsequence[j][i])) {
++numMismatches;
continue;
}
if (qualities != null && qualities[j][i] < minimumBaseQuality) {
++numMismatches;
}
}
}
return numMismatches;
}
示例3: calculateGc
import htsjdk.samtools.util.SequenceUtil; //导入依赖的package包/类
public static int calculateGc(final byte[] bases, final int startIndex, final int endIndex, final CalculateGcState state) {
if (state.init) {
state.init = false;
state.gcCount = 0;
state.nCount = 0;
for (int i = startIndex; i < endIndex; ++i) {
final byte base = bases[i];
if (SequenceUtil.basesEqual(base, (byte)'G') || SequenceUtil.basesEqual(base, (byte)'C')) ++state.gcCount;
else if (SequenceUtil.basesEqual(base, (byte)'N')) ++state.nCount;
}
} else {
final byte newBase = bases[endIndex - 1];
if (SequenceUtil.basesEqual(newBase, (byte)'G') || SequenceUtil.basesEqual(newBase, (byte)'C')) ++state.gcCount;
else if (newBase == 'N') ++state.nCount;
if (SequenceUtil.basesEqual(state.priorBase, (byte)'G') || SequenceUtil.basesEqual(state.priorBase, (byte)'C')) --state.gcCount;
else if (SequenceUtil.basesEqual(state.priorBase, (byte)'N')) --state.nCount;
}
state.priorBase = bases[startIndex];
if (state.nCount > 4) return -1;
else return (state.gcCount * 100) / (endIndex - startIndex);
}
示例4: makeOverlapDetector
import htsjdk.samtools.util.SequenceUtil; //导入依赖的package包/类
public static OverlapDetector<Interval> makeOverlapDetector(final File samFile, final SAMFileHeader header, final File ribosomalIntervalsFile, final Log log) {
final OverlapDetector<Interval> ribosomalSequenceOverlapDetector = new OverlapDetector<Interval>(0, 0);
if (ribosomalIntervalsFile != null) {
final IntervalList ribosomalIntervals = IntervalList.fromFile(ribosomalIntervalsFile);
if (ribosomalIntervals.size() == 0) {
log.warn("The RIBOSOMAL_INTERVALS file, " + ribosomalIntervalsFile.getAbsolutePath() + " does not contain intervals");
}
try {
SequenceUtil.assertSequenceDictionariesEqual(header.getSequenceDictionary(), ribosomalIntervals.getHeader().getSequenceDictionary());
} catch (SequenceUtil.SequenceListsDifferException e) {
throw new PicardException("Sequence dictionaries differ in " + samFile.getAbsolutePath() + " and " + ribosomalIntervalsFile.getAbsolutePath(),
e);
}
final IntervalList uniquedRibosomalIntervals = ribosomalIntervals.uniqued();
final List<Interval> intervals = uniquedRibosomalIntervals.getIntervals();
ribosomalSequenceOverlapDetector.addAll(intervals, intervals);
}
return ribosomalSequenceOverlapDetector;
}
示例5: addRead
import htsjdk.samtools.util.SequenceUtil; //导入依赖的package包/类
private void addRead(final GcObject gcObj, final SAMRecord rec, final String group, final byte[] gc, final byte[] refBases) {
if (!rec.getReadPairedFlag() || rec.getFirstOfPairFlag()) ++gcObj.totalClusters;
final int pos = rec.getReadNegativeStrandFlag() ? rec.getAlignmentEnd() - scanWindowSize : rec.getAlignmentStart();
++gcObj.totalAlignedReads;
if (pos > 0) {
final int windowGc = gc[pos];
if (windowGc >= 0) {
++gcObj.readsByGc[windowGc];
gcObj.basesByGc[windowGc] += rec.getReadLength();
gcObj.errorsByGc[windowGc] +=
SequenceUtil.countMismatches(rec, refBases, bisulfite) +
SequenceUtil.countInsertedBases(rec) + SequenceUtil.countDeletedBases(rec);
}
}
if (gcObj.group == null) {
gcObj.group = group;
}
}
示例6: acceptRead
import htsjdk.samtools.util.SequenceUtil; //导入依赖的package包/类
@Override
protected void acceptRead(final SAMRecord rec, final ReferenceSequence ref) {
// Skip unwanted records
if (PF_READS_ONLY && rec.getReadFailsVendorQualityCheckFlag()) return;
if (ALIGNED_READS_ONLY && rec.getReadUnmappedFlag()) return;
if (rec.isSecondaryOrSupplementary()) return;
final byte[] bases = rec.getReadBases();
final byte[] quals = rec.getBaseQualities();
final byte[] oq = rec.getOriginalBaseQualities();
final int length = quals.length;
for (int i=0; i<length; ++i) {
if (INCLUDE_NO_CALLS || !SequenceUtil.isNoCall(bases[i])) {
qCounts[quals[i]]++;
if (oq != null) oqCounts[oq[i]]++;
}
}
}
示例7: reverseComplement
import htsjdk.samtools.util.SequenceUtil; //导入依赖的package包/类
private static Allele reverseComplement(final Allele oldAllele, final Interval target, final ReferenceSequence referenceSequence, final boolean isBiAllelicIndel, final boolean addToStart){
if (oldAllele.isSymbolic() || oldAllele.isNoCall()) {
return oldAllele;
}
else if (isBiAllelicIndel) {
// target.getStart is 1-based, reference bases are 0-based
final StringBuilder alleleBuilder = new StringBuilder(target.getEnd() - target.getStart() + 1);
if (addToStart) {
alleleBuilder.append((char) referenceSequence.getBases()[target.getStart() - 2]);
}
alleleBuilder.append(SequenceUtil.reverseComplement(oldAllele.getBaseString().substring(1, oldAllele.length())));
if (!addToStart) {
alleleBuilder.append((char) referenceSequence.getBases()[target.getEnd() - 1]);
}
return Allele.create(alleleBuilder.toString(), oldAllele.isReference());
} else {
return Allele.create(SequenceUtil.reverseComplement(oldAllele.getBaseString()), oldAllele.isReference());
}
}
示例8: extractBasesForAltAllele
import htsjdk.samtools.util.SequenceUtil; //导入依赖的package包/类
static byte[] extractBasesForAltAllele(final NovelAdjacencyReferenceLocations narl, final boolean forUpstreamLoc,
final ReferenceMultiSource reference) {
try {
final byte[] ref = reference
.getReferenceBases(forUpstreamLoc ? narl.leftJustifiedLeftRefLoc :
narl.leftJustifiedRightRefLoc)
.getBases();
final String ins = narl.complication.getInsertedSequenceForwardStrandRep();
if (ins.isEmpty()) {
return ref;
} else {
return forUpstreamLoc ? ArrayUtils.addAll(ref, ins.getBytes())
: ArrayUtils.addAll(ref, SequenceUtil.reverseComplement(ins).getBytes());
}
} catch (final IOException ioex) {
throw new GATKException("Could not read reference for extracting reference bases.", ioex);
}
}
示例9: addRead
import htsjdk.samtools.util.SequenceUtil; //导入依赖的package包/类
/**
* Adds a read to this count object by increasing counts of the base qualities.
*/
Counts addRead(final GATKRead read) {
final byte[] bases = read.getBases();
final byte[] quals = read.getBaseQualities();
final byte[] oq = ReadUtils.getOriginalBaseQualities(read);
final int length = quals.length;
for (int i=0; i<length; ++i) {
if (includeNoCalls || !SequenceUtil.isNoCall(bases[i])) {
qCounts[quals[i]]++;
if (oq != null) {
oqCounts[oq[i]]++;
}
}
}
return this;
}
示例10: clearReadAlignment
import htsjdk.samtools.util.SequenceUtil; //导入依赖的package包/类
/**
* Returns input read with alignment-related info cleared
*/
private static GATKRead clearReadAlignment(final GATKRead read, final SAMFileHeader header) {
final GATKRead newRead = new SAMRecordToGATKReadAdapter(new SAMRecord(header));
newRead.setName(read.getName());
newRead.setBases(read.getBases());
newRead.setBaseQualities(read.getBaseQualities());
if (read.isReverseStrand()) {
SequenceUtil.reverseComplement(newRead.getBases());
SequenceUtil.reverseQualities(newRead.getBaseQualities());
}
newRead.setIsUnmapped();
newRead.setIsPaired(read.isPaired());
if (read.isPaired()) {
newRead.setMateIsUnmapped();
if (read.isFirstOfPair()) {
newRead.setIsFirstOfPair();
} else if (read.isSecondOfPair()) {
newRead.setIsSecondOfPair();
}
}
final String readGroup = read.getReadGroup();
if (readGroup != null) {
newRead.setAttribute(SAMTag.RG.name(), readGroup);
}
return newRead;
}
示例11: assertFastaContent
import htsjdk.samtools.util.SequenceUtil; //导入依赖的package包/类
private void assertFastaContent(final Path path, final boolean withDescriptions, final SAMSequenceDictionary dictionary, final int defaultBpl,
final Map<String, byte[]> bases, final Map<String, Integer> basesPerLine)
throws IOException {
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(path.getFileSystem().provider().newInputStream(path)))) {
for (final SAMSequenceRecord sequence : dictionary.getSequences()) {
final String description = String.format("index=%d\tlength=%d",
dictionary.getSequenceIndex(sequence.getSequenceName()), sequence.getSequenceLength());
final String expectedHeader =
FastaReferenceWriter.HEADER_START_CHAR + sequence.getSequenceName()
+ ((withDescriptions) ? FastaReferenceWriter.HEADER_NAME_AND_DESCRIPTION_SEPARATOR + description : "");
Assert.assertEquals(reader.readLine(), expectedHeader);
final byte[] expectedBases = bases.get(sequence.getSequenceName());
final int bpl_ = basesPerLine.get(sequence.getSequenceName());
final int bpl = bpl_ < 0 ? (defaultBpl < 0 ? FastaReferenceWriter.DEFAULT_BASES_PER_LINE : defaultBpl) : bpl_;
int offset = 0;
while (offset < expectedBases.length) {
final int expectedLength = Math.min(expectedBases.length - offset, bpl);
final byte[] expectedBaseLine = SequenceUtil.upperCase(Arrays.copyOfRange(expectedBases, offset, offset + expectedLength));
final byte[] actualBaseLine = SequenceUtil.upperCase(reader.readLine().getBytes());
Assert.assertEquals(actualBaseLine, expectedBaseLine);
offset += expectedLength;
}
}
}
}
示例12: reset
import htsjdk.samtools.util.SequenceUtil; //导入依赖的package包/类
void reset(EvidenceRecord evidenceRecord) {
this.evidenceRecord = evidenceRecord;
negative = "-".equals(evidenceRecord.Strand);
baseBuf.clear();
scoreBuf.clear();
if (evidenceRecord.Strand.equals("+")) {
baseBuf.put(evidenceRecord.Sequence.getBytes());
scoreBuf.put(SAMUtils.fastqToPhred(evidenceRecord.Scores));
} else {
byte[] bytes = evidenceRecord.Sequence.getBytes();
SequenceUtil.reverseComplement(bytes);
baseBuf.put(bytes);
bytes = SAMUtils.fastqToPhred(evidenceRecord.Scores);
SequenceUtil.reverseQualities(bytes);
scoreBuf.put(bytes);
}
baseBuf.flip();
scoreBuf.flip();
firstHalf.clear();
secondHalf.clear();
}
示例13: test_Start_1
import htsjdk.samtools.util.SequenceUtil; //导入依赖的package包/类
@Test
public void test_Start_1() {
int start = 1;
ReferenceRegion region = new ReferenceRegion(data, 0, "chr1", start);
Assert.assertEquals(start, region.alignmentStart);
Assert.assertEquals(0, region.arrayPosition(start));
for (int pos = start, index = 0; pos < start + 10; pos++, index++) {
Assert.assertEquals(data[index], region.base(pos));
}
int len = 10;
String expectedMD5 = SequenceUtil.calculateMD5String(data, 0, len);
String md5 = region.md5(start, len);
Assert.assertEquals(expectedMD5, md5);
}
示例14: test_Start_2
import htsjdk.samtools.util.SequenceUtil; //导入依赖的package包/类
@Test
public void test_Start_2() {
int start = 2;
ReferenceRegion region = new ReferenceRegion(data, 0, "chr1", start);
Assert.assertEquals(start, region.alignmentStart);
Assert.assertEquals(0, region.arrayPosition(start));
for (int pos = start, index = 0; pos < start + 10; pos++, index++) {
Assert.assertEquals(data[index], region.base(pos));
}
int len = 10;
String expectedMD5 = SequenceUtil.calculateMD5String(data, 0, len);
String md5 = region.md5(start, len);
Assert.assertEquals(expectedMD5, md5);
}
示例15: test_HangingEnd
import htsjdk.samtools.util.SequenceUtil; //导入依赖的package包/类
@Test
public void test_HangingEnd() {
int start = 2;
ReferenceRegion region = new ReferenceRegion(data, 0, "chr1", start);
Assert.assertEquals(start, region.alignmentStart);
Assert.assertEquals(0, region.arrayPosition(start));
for (int pos = start, index = 0; pos < start + 10; pos++, index++) {
Assert.assertEquals(data[index], region.base(pos));
}
String expectedMD5 = SequenceUtil.calculateMD5String(data, 0, data.length);
String md5 = region.md5(start, data.length + 10);
Assert.assertEquals(expectedMD5, md5);
md5 = region.md5(start, data.length + 100);
Assert.assertEquals(expectedMD5, md5);
}