本文整理汇总了Java中net.sf.samtools.SAMRecord.getReadUnmappedFlag方法的典型用法代码示例。如果您正苦于以下问题:Java SAMRecord.getReadUnmappedFlag方法的具体用法?Java SAMRecord.getReadUnmappedFlag怎么用?Java SAMRecord.getReadUnmappedFlag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.samtools.SAMRecord
的用法示例。
在下文中一共展示了SAMRecord.getReadUnmappedFlag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sourceReads
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
/**
* Get the reads from the appropriate source (implementation-specific).
* Loads data to the fivePrimesList and hitsCountList
*/
public void sourceReads() {
this.initialize();
SAMFileReader reader = new SAMFileReader(file);
reader.setValidationStringency(ValidationStringency.SILENT);
CloseableIterator<SAMRecord> iter = reader.iterator();
Collection<SAMRecord> byRead = new ArrayList<SAMRecord>();
String lastread = null;
while (iter.hasNext()) {
SAMRecord record = iter.next();
if (record.getReadUnmappedFlag()) {continue; }
if (lastread == null || !lastread.equals(record.getReadName())) {
processRead(byRead);
byRead.clear();
}
lastread = record.getReadName();
byRead.add(record);
}
processRead(byRead);
iter.close();
reader.close();
}
示例2: _next
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
private Alignment _next()
{
SAMRecord record;
while (iter.hasNext())
{
try {
record=iter.next();
}
catch (SAMFormatException e)
{
System.err.println("catch SAMFormatException");
continue;
};
if(record.getReadUnmappedFlag()) continue;
SingleEndAlignment retv=new SingleEndAlignment(record);
return retv;
}
return null;
}
示例3: run
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
@Override
public void run() {
theslog.log(true, "Pass one: " + bamfile.getAbsolutePath());
// set up input/output objects using SAM library
SAMFileReader inputSam = new SAMFileReader(bamfile);
inputSam.setValidationStringency(SAMFileReader.ValidationStringency.SILENT);
for (final SAMRecord record : inputSam) {
if (record.getReadUnmappedFlag()) {
// if read is unaligned, output coordinates into a bed file
processOneUnalignedRecord(record);
} else {
// if aligned, then make thesaurus entries
int mapqual = record.getMappingQuality();
// only consider reads with a minimum mapping quality
// (this here is not a "real" mapping quality, but a proxy for number of mismatches)
if (mapqual >= minmapqual) {
// check that read is aligned
processOneRecord(record);
}
}
}
// and close the input file stream
inputSam.close();
}
示例4: processSequence
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
@Override
public void processSequence(SAMRecord sequence) {
// extract the method used for generating the SAM/BAM file if present in the header file.
if(!headerParsed) {
String fullHeader = sequence.getHeader().getTextHeader();
if(fullHeader != null) {
String[] headerLines = fullHeader.split("@");
for(int i=0; i<headerLines.length; i++) {
if(headerLines[i].startsWith("PG")) {
command += headerLines[i].replace("PG\t", "").replace('\t', ' ');
}
}
}
headerParsed = true;
}
actualCount++;
if (!sequence.isSecondaryOrSupplementary()) {
++primaryCount;
}
if (sequence.getReadPairedFlag()) {
pairedCount++;
if (sequence.getProperPairFlag()) properPairCount++;
if (sequence.getMateUnmappedFlag() && ! sequence.getReadUnmappedFlag()) singletonCount++;
}
if (sequence.getReadUnmappedFlag()) unmappedCount++;
if (sequence.getReadFailsVendorQualityCheckFlag()) qcFailCount++;
if (sequence.getDuplicateReadFlag()) duplicateCount++;
}
示例5: countReads
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
protected void countReads() {
readLength=-1;
totalHits=0;
totalWeight=0;
SAMFileReader reader = new SAMFileReader(inFile);
CloseableIterator<SAMRecord> iter = reader.iterator();
Collection<SAMRecord> byRead = new ArrayList<SAMRecord>();
String lastread = null;
while (iter.hasNext()) {
currID++;
SAMRecord record = iter.next();
if(readLength ==-1)
readLength = record.getReadLength();
if (record.getReadUnmappedFlag()) {continue; }
if (lastread == null || !lastread.equals(record.getReadName())) {
processRead(byRead);
byRead.clear();
}
lastread = record.getReadName();
byRead.add(record);
}
processRead(byRead);
iter.close();
reader.close();
populateArrays();
}
示例6: convertToPairedEndFragment
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
public static SAMRecord convertToPairedEndFragment(SAMRecord rec) {
int insertSize = Math.abs(rec.getInferredInsertSize());
//TODO: possible to remove (insertSize > 0) clause? What does an insert size of 0 mean?
if (rec.getReadPairedFlag() && rec.getProperPairFlag() && !rec.getReadUnmappedFlag()
&& (insertSize <= MAX_INSERT) && (rec.getAlignmentStart() < rec.getMateAlignmentStart())
&& rec.getReferenceName() != "chrM") // current paired end representation doesn't do well with circular chromosomes
{
//We need to get the full fragment contained by read.getStart to pair.getEnd
int readEnd=rec.getAlignmentEnd();
int mateStart=rec.getMateAlignmentStart();
//int extension = insertSize - rec.getReadLength();
int extension=(mateStart-readEnd)+rec.getReadLength();
if (extension <= MAX_INSERT) {
String newRead = rec.getReadString() + StringUtils.repeat("N", extension);
rec.setReadString(newRead);
String newQual = StringUtils.repeat("A", newRead.length());
if(!rec.getBaseQualityString().equals("*")) newQual = rec.getBaseQualityString() + StringUtils.repeat("A", extension);
rec.setBaseQualityString(newQual);
String newCigar=newRead.length()+"M";
rec.setCigarString(newCigar);
// Change attributes to represent single read
rec.setMateReferenceName("*");
rec.setMateAlignmentStart(0);
rec.setFirstOfPairFlag(false);
rec.setMateNegativeStrandFlag(false);
rec.setMateUnmappedFlag(false);
rec.setProperPairFlag(false);
rec.setReadPairedFlag(false);
rec.setSecondOfPairFlag(false);
}
} else {
rec = null;
}
return rec;
}
示例7: readMapsToProbe
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
private boolean readMapsToProbe(SAMRecord read, SAMFileHeader header) {
if (read.getReadUnmappedFlag()) return false;
int left, right;
if (read.getReferenceName().contains("OriginalArray")) {
left = ORIGINAL_ARRAY_LEFT;
right = ORIGINAL_ARRAY_RIGHT;
} else if (read.getReferenceName().contains("MainArray")) {
left = MAIN_ARRAY_LEFT;
right = MAIN_ARRAY_RIGHT;
} else if (read.getReferenceName().contains("SimpleArray")) {
left = SIMPLE_ARRAY_LEFT;
right = SIMPLE_ARRAY_RIGHT;
} else if (read.getReferenceName().contains("140105")) {
left = ARRAY_140105;
right = ARRAY_140105;
} else if (read.getReferenceName().contains("Mouse")) {
left = MRNA_ARRAY_LEFT;
right = MRNA_ARRAY_RIGHT;
} else {
log.error("This reference name doesn't match: " + read.getReferenceName());
return false;
}
left = T7BASES + left;
right = header.getSequence(read.getReferenceIndex()).getSequenceLength() - right - T7BASES;
if ((read.getAlignmentStart() <= left - OVERLAP) || read.getAlignmentEnd() >= right + OVERLAP) {
return true;
}
return false;
}
示例8: addStartEndIndices
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
private void addStartEndIndices(SAMRecord first, SAMRecord second) {
if (!first.getReadUnmappedFlag() && !second.getReadUnmappedFlag()) {
int start = Math.min(first.getAlignmentStart(), second.getAlignmentStart());
int end = Math.max(first.getAlignmentEnd(), second.getAlignmentEnd());
startIndex[start]++;
endIndex[end]++;
}
}
示例9: filterOut
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
@Override
public boolean filterOut(SAMRecord record) {
if (this.freezeCountersInThread.get() == null) {
this.freezeCountersInThread.set(false);
}
//remove reads with two or more alignments
if (this.freezeCountersInThread.get() == false) this.processedReadsCounter ++;
if (record.getReadUnmappedFlag()) {
if (this.freezeCountersInThread.get() == false) this.unmmapedReadsCounter++;
System.err.println("UNMAPPED READ!");
System.exit(1);
return false;
}
if (onlyWithOneAlignment) {
// bowtie 1
if (record.getHeader().getProgramRecord("Bowtie") != null) {
if (record.getAttribute("XM") != null
&& ((Integer) record.getAttribute("XM")) > 1) {
if (this.freezeCountersInThread.get() == false) this.withMoreThanOneAlignmentCounter++;
return true;
}
}
// bowtie 2
if (record.getHeader().getProgramRecord("bowtie2") != null) {
if (record.getAttribute("XS") != null) {
if (this.freezeCountersInThread.get() == false) this.withMoreThanOneAlignmentCounter++;
return true;
}
}
}
//remove ambiguous
if (removeAmbiguous) {
if (record.getAttribute("ZA") != null && record.getAttribute("ZA").toString().equals("Y")) {
if (this.freezeCountersInThread.get() == false) this.ambiguousReadCounter++;
return true;
}
}
//trim to x mismatch (trim must be before bad bisulfited)
if (trim) {
boolean trimmed = trim(record, trimUntil);
if (trimmed && this.freezeCountersInThread.get() == false) this.trimmedCounter++;
}
//bad bisulfited filter
if (removeBad) {
if (record.getReadGroup().getId().equals("WATSON") && watson.matcher(record.getReadString()).find()
||
record.getReadGroup().getId().equals("CRICK") && crick.matcher(record.getReadString()).find()) {
if (this.freezeCountersInThread.get() == false) this.badBisulfitedCounter++;
return true;
}
}
return false;
}
示例10: readNext
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
private void readNext() throws SequenceFormatException {
SAMRecord record;
while (true) {
if (!it.hasNext()) {
nextSequence = null;
try {
br.close();
fis.close();
}
catch (IOException ioe) {
log.error(ioe, ioe);
}
return;
}
try {
record = it.next();
}
catch (SAMFormatException sfe) {
throw new SequenceFormatException(sfe.getMessage());
}
// We skip over entries with no mapping if that's what the user asked for
if (onlyMapped && record.getReadUnmappedFlag()) {
continue;
}
break;
}
if (recordSize == 0) {
recordSize = (record.getReadLength()*2)+150;
if (br.isBinary()) {
recordSize /= 4;
}
}
nextSequence = record;
}
示例11: processSequence
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
@Override
public void processSequence(SAMRecord read) {
if (read.getReadUnmappedFlag()) return;
int leftClip = 0;
int rightClip = 0;
// Get the CIGAR list
Cigar cigar = read.getCigar();
if (cigar == null || read.getCigarLength() == 0) {
log.debug("Read " + read.getReadString() + " does not have Cigar string.");
return;
}
List<CigarElement> elements = cigar.getCigarElements();
CigarElement first = elements.get(0);
CigarElement last = elements.get(elements.size()-1);
if (first.getOperator().equals(CigarOperator.S)) {
if (read.getReadNegativeStrandFlag()) {
rightClip = first.getLength();
}
else {
leftClip = first.getLength();
}
}
if (last.getOperator().equals(CigarOperator.S)) {
if (read.getReadNegativeStrandFlag()) {
leftClip = last.getLength();
}
else {
rightClip = last.getLength();
}
}
int max=leftClip;
if (rightClip>leftClip)max=rightClip;
if (max+1 > leftClipCounts.length) expandCounts(max+1);
leftClipCounts[leftClip]++;
rightClipCounts[rightClip]++;
}
示例12: sourceReads
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
/**
* Get the reads from the appropriate source (implementation-specific).
* Loads data to the fivePrimesList and hitsCountList
*/
public void sourceReads() {
this.initialize();
SAMFileReader reader = new SAMFileReader(file);
reader.setValidationStringency(ValidationStringency.SILENT);
CloseableIterator<SAMRecord> iter = reader.iterator();
while (iter.hasNext()) {
SAMRecord record = iter.next();
if (record.getReadUnmappedFlag()) {continue; }
float weight = 1/(float)record.getIntegerAttribute("NH");
Read currRead = new Read();
List<AlignmentBlock> blocks = record.getAlignmentBlocks();
for(int a=0; a<blocks.size(); a++){ //Iterate over alignment blocks
AlignmentBlock currBlock = blocks.get(a);
int aStart = currBlock.getReferenceStart();
int aEnd = aStart + currBlock.getLength()-1;
int aLen = currBlock.getLength();
boolean nearbyBlocks=true;
while(nearbyBlocks && a<blocks.size()-1){
if(blocks.get(a+1).getReferenceStart() - currBlock.getReferenceStart() < record.getReadLength()){
aEnd = blocks.get(a+1).getReferenceStart() + blocks.get(a+1).getLength()-1;
aLen += blocks.get(a+1).getLength();
a++;
}else{
nearbyBlocks=false;
}
}
ReadHit currHit = new ReadHit(
record.getReferenceName().replaceFirst("^chr", ""),
aStart, aEnd,
record.getReadNegativeStrandFlag() ? '-' : '+',
weight);
currRead.addHit(currHit);
}
addHits(currRead);
}
iter.close();
reader.close();
}
示例13: countReads
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
protected void countReads() {
readLength=-1;
totalHits=0;
totalWeight=0;
SAMFileReader reader = new SAMFileReader(inFile);
reader.setValidationStringency(ValidationStringency.SILENT);
CloseableIterator<SAMRecord> iter = reader.iterator();
while (iter.hasNext()) {
currID++;
SAMRecord record = iter.next();
if (record.getReadUnmappedFlag()) {continue; }
float weight = 1/(float)record.getIntegerAttribute("NH");
if(readLength ==-1)
readLength = record.getReadLength();
Read currRead = new Read((int)totalWeight);
List<AlignmentBlock> blocks = record.getAlignmentBlocks();
for(int a=0; a<blocks.size(); a++){ //Iterate over alignment blocks
AlignmentBlock currBlock = blocks.get(a);
int aStart = currBlock.getReferenceStart();
int aEnd = aStart + currBlock.getLength()-1;
int aLen = currBlock.getLength();
boolean nearbyBlocks=true;
while(nearbyBlocks && a<blocks.size()-1){
if(blocks.get(a+1).getReferenceStart() - currBlock.getReferenceStart() < record.getReadLength()){
aEnd = blocks.get(a+1).getReferenceStart() + blocks.get(a+1).getLength()-1;
aLen += blocks.get(a+1).getLength();
a++;
}else{
nearbyBlocks=false;
}
}
ReadHit currHit = new ReadHit(gen,
currID,
record.getReferenceName().replaceFirst("^chr", ""),
aStart, aEnd,
record.getReadNegativeStrandFlag() ? '-' : '+',
weight);
currRead.addHit(currHit);
currID++;
}
addHits(currRead);
totalWeight++;
}
iter.close();
reader.close();
populateArrays();
}
示例14: processSAMRecord
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
public void processSAMRecord(SAMRecord r){
totalReads++;
if(!r.getReadUnmappedFlag()){
totalHits++;
int count = 1; //Have to figure out something for BWA when reporting multiple alignments
if(r.getIntegerAttribute("NH")!=null)
count = r.getIntegerAttribute("NH");
if(count==1 && r.getMappingQuality()!=0) //Second clause for BWA
uniquelyMapped++;
weight += 1/(float)count;
if(r.getReadPairedFlag()){
if(r.getMateUnmappedFlag()){
singleEnd++;
}else{
pairMapped++;
if(r.getMateReferenceName().equals(r.getReferenceName())){
pairedEndSameChr++;
}else{
pairedEndDiffChr++;
}
}
}else{
singleEnd++;
}
List<AlignmentBlock> blocks = r.getAlignmentBlocks();
if(blocks.size()>=2){
junctions+=blocks.size()-1;
}
if(!r.getNotPrimaryAlignmentFlag()){
if(!r.getReadPairedFlag() || r.getFirstOfPairFlag()){
LHits++;
if(r.getReadPairedFlag() && r.getProperPairFlag()){
properPair++;
if(!r.getReadNegativeStrandFlag() && r.getMateNegativeStrandFlag()){
double dist = (r.getMateAlignmentStart()+r.getReadLength())-r.getAlignmentStart();
histo.addValue(dist);
}
}
}else if(r.getSecondOfPairFlag()){
RHits++;
}
}else{
notPrimary++;
}
}
}
示例15: processBT1SAMRecord
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
public void processBT1SAMRecord(SAMRecord r){
totalReads++;
if(!r.getReadUnmappedFlag())
if(r.getIntegerAttribute("XM")!=null){
int xm = r.getIntegerAttribute("XM");
if(xm!=0)
weight++;
}
else{
totalHits++;
int count =1; //TODO: Fix this if using bowtie for multi-mapping reads
boolean currUnique = true;
if(count==1 && currUnique){
uniquelyMapped++;
}
weight += 1/(float)count;
if(r.getReadPairedFlag()){
if(r.getMateUnmappedFlag()){
singleEnd++;
}else{
pairMapped++;
if(r.getMateReferenceName().equals(r.getReferenceName())){
pairedEndSameChr++;
}else{
pairedEndDiffChr++;
}
}
}else{
singleEnd++;
}
List<AlignmentBlock> blocks = r.getAlignmentBlocks();
if(blocks.size()>=2){
junctions+=blocks.size()-1;
}
if(!r.getNotPrimaryAlignmentFlag()){
if(!r.getReadPairedFlag() || r.getFirstOfPairFlag()){
LHits++;
if(r.getReadPairedFlag() && r.getProperPairFlag()){
properPair++;
if(!r.getReadNegativeStrandFlag() && r.getMateNegativeStrandFlag()){
double dist = (r.getMateAlignmentStart()+r.getReadLength())-r.getAlignmentStart();
histo.addValue(dist);
}
}
}else if(r.getSecondOfPairFlag()){
RHits++;
}
}else{
notPrimary++;
}
}
}