本文整理汇总了Java中net.sf.samtools.SAMRecord.getReadLength方法的典型用法代码示例。如果您正苦于以下问题:Java SAMRecord.getReadLength方法的具体用法?Java SAMRecord.getReadLength怎么用?Java SAMRecord.getReadLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.samtools.SAMRecord
的用法示例。
在下文中一共展示了SAMRecord.getReadLength方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processOneUnalignedRecord
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
/**
* Converts a SAM record into a bed entry and outputs it straight away
*
* @param record
*/
private void processOneUnalignedRecord(SAMRecord record) {
// output the alignment positions into a bed file
int start = record.getAlignmentStart() - 1;
int end = start + record.getReadLength();
String out = record.getReferenceName() + "\t" + start + "\t" + end + "\n";
synchronized (outunaligned) {
try {
outunaligned.write(out.getBytes());
} catch (Exception ex) {
System.out.println("Exception writing unaligned bed: " + ex.getMessage());
}
}
// create a dummy thesaurus entry
ThesaurusEntry entry = new ThesaurusEntry(record, ginfo);
// complete it (need to fix alignment end manually, then use function to get anchors set right)
entry.alignEnd = entry.originEnd;
completeThesaurusEntry(entry, record);
// set the origin chromosome to -1 to signal unaligned setup
entry.originChrIndex = -1;
outputThesaurusEntry(entry, outstreams.get(entry.getAlignChr()));
}
示例2: SAMStats
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
public SAMStats(boolean bowtie1, boolean bowtie2){
this.bowtie1 = bowtie1;
this.bowtie2 = bowtie2;
histo = new RealValuedHistogram(0, 1000, 100);
SAMFileReader reader = new SAMFileReader(System.in);
reader.setValidationStringency(ValidationStringency.SILENT);
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();
reader.close();
}
示例3: 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();
}
示例4: 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;
}
示例5: 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;
}
示例6: 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();
}
示例7: 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();
}
示例8: 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++;
}
}
}
示例9: 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++;
}
}
}
示例10: processBT2SAMRecord
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
public void processBT2SAMRecord(SAMRecord r){
totalReads++;
if(!r.getReadUnmappedFlag()){
totalHits++;
int count =1; //TODO: Fix this if using bowtie2 for multi-mapping reads
int primAScore = r.getIntegerAttribute("AS");
int secAScore=-1000000;
if(r.getIntegerAttribute("XS")!=null)
secAScore = r.getIntegerAttribute("XS");
boolean currUnique = primAScore > secAScore ? true : false;
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++;
}
}
}