当前位置: 首页>>代码示例>>Java>>正文


Java SAMRecord.getReadNegativeStrandFlag方法代码示例

本文整理汇总了Java中net.sf.samtools.SAMRecord.getReadNegativeStrandFlag方法的典型用法代码示例。如果您正苦于以下问题:Java SAMRecord.getReadNegativeStrandFlag方法的具体用法?Java SAMRecord.getReadNegativeStrandFlag怎么用?Java SAMRecord.getReadNegativeStrandFlag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.sf.samtools.SAMRecord的用法示例。


在下文中一共展示了SAMRecord.getReadNegativeStrandFlag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processRead

import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
protected void processRead(Collection<SAMRecord> records) {
      int mapcount = records.size();
      if (mapcount == 0) {
          return;
      }
      if (!useNonUnique && mapcount > 1) {
          return;
      }
	
      float weight = 1 / ((float)mapcount);
      Read currRead = new Read();
for (SAMRecord record : records) {
    int start = record.getAlignmentStart();
    int end = record.getAlignmentEnd();
    ReadHit currHit = new ReadHit(
				  record.getReferenceName().replaceFirst("^chr", ""), 
				  start, end, 
				  record.getReadNegativeStrandFlag() ? '-' : '+',
				  weight);
    currRead.addHit(currHit);
}currRead.setNumHits(mapcount);
addHits(currRead);
  }
 
开发者ID:shaunmahony,项目名称:multigps-archive,代码行数:24,代码来源:SAMFileHitLoader.java

示例2: processRead

import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
protected void processRead(Collection<SAMRecord> records) {
      int mapcount = records.size();
      if (mapcount == 0) {
          return;
      }
      if (!useNonUnique && mapcount > 1) {
          return;
      }
	
      float weight = 1 / ((float)mapcount);
      Read currRead = new Read((int)totalWeight);
for (SAMRecord record : records) {
	int start = record.getAlignmentStart();
    int end = record.getAlignmentEnd();
    ReadHit currHit = new ReadHit(gen, currID,
				  record.getReferenceName().replaceFirst("^chr", ""), 
				  start, end, 
				  record.getReadNegativeStrandFlag() ? '-' : '+',
				  weight);
    currRead.addHit(currHit);
    currID++;
}currRead.setNumHits(mapcount);
addHits(currRead);
totalWeight++;
  }
 
开发者ID:shaunmahony,项目名称:multigps-archive,代码行数:26,代码来源:SAMReader.java

示例3: count

import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
private void count(int adjustedStart, int adjustedEnd, ReadCounter counter, SAMRecord alignment) {
	
	
	for (int pos = adjustedStart; pos < adjustedEnd; pos++) {
		if (!alignment.getReadPairedFlag()||alignment.getFirstOfPairFlag()) {
			if (!alignment.getReadNegativeStrandFlag())
				counter.incrementCount(pos,ReadType.FIRSTREADFORWARDMAP);
			else
				counter.incrementCount(pos,ReadType.FIRSTREADREVERSEMAP);
		}else{
			if (!alignment.getReadNegativeStrandFlag())
				counter.incrementCount(pos,ReadType.SECONDREADFORWARDMAP);
			else
				counter.incrementCount(pos,ReadType.SECONDREADREVERSEMAP);
		}
	}
	
}
 
开发者ID:AbeelLab,项目名称:genometools,代码行数:19,代码来源:CoverageCounter.java

示例4: ThesaurusEntry

import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
/**
 * Construct an entry by parsing a SAM record for a read.
 *
 * The read name should be of the format, e.g. T100;chr1:10001-10100 i.e.
 * LABEL;CHROMOSOME;START-END
 *
 * Warning: this constructor will only set the following fields: originChr,
 * originStart, originEnd, alignChr, alignStart, alignEnd. Other fields must
 * be set via the separate set methods.
 *
 * @param record
 */
public ThesaurusEntry(SAMRecord record, GenomeInfo ginfo) {
    this.ginfo = ginfo;

    // parse the read name to get the origin location        
    String[] readelements = record.getReadName().split(";|:|-");
    //originChr = readelements[1];
    originChrIndex = ginfo.getChrIndex(readelements[1]);
    originStart = Integer.parseInt(readelements[2]);
    originEnd = Integer.parseInt(readelements[3]);

    // get the alignment location
    //alignChr = record.getReferenceName();
    alignChrIndex = ginfo.getChrIndex(record.getReferenceName());
    alignStart = record.getAlignmentStart();
    alignEnd = record.getAlignmentEnd();

    if (record.getReadNegativeStrandFlag()) {
        alignStrand = '-';
    } else {
        alignStrand = '+';
    }

    anchors = new ArrayList<ThesaurusAnchor>(2);
    // the anchor array will not be properly formed, i.e. any mismatches will not
    // be recorded either in the anchors or in the penalty field.

    ok = true;
}
 
开发者ID:tkonopka,项目名称:GeneticThesaurus,代码行数:41,代码来源:ThesaurusEntry.java

示例5: SequenceRead

import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
public SequenceRead(SAMRecord record) {
    super(record.getAlignmentStart(), record.getAlignmentEnd());
    this.chr = record.getReferenceName();
    if (record.getReadNegativeStrandFlag()) {
        strand = Strand.NEGATIVE;
    } else {
        strand = Strand.POSITIVE;
    }
    this.readBases = record.getReadBases();
    this.qualities = record.getBaseQualities();
    this.alignmentBlocks = record.getAlignmentBlocks();
}
 
开发者ID:REDetector,项目名称:RED,代码行数:13,代码来源:SequenceRead.java

示例6: toFastq

import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
private String toFastq(SAMRecord value1) {
	String seq=value1.getReadString();
	if(value1.getReadNegativeStrandFlag()){
		seq=Sequence.reverseSequence(seq);
	}
	String name=value1.getReadName();
	String quality=value1.getBaseQualityString();
	return name+"\n"+seq+"\n"+"+\n"+quality;
}
 
开发者ID:mgarber,项目名称:scriptureV2,代码行数:10,代码来源:ReadSimulator2.java

示例7: SAMFormatFullBED

import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
public static Gene SAMFormatFullBED(SAMRecord sam){
	String chr=sam.getReferenceName();
   	int start=sam.getAlignmentStart()-1; //TODO: Do we need the -1, it is a left over from the method above.
   	Strand strand=sam.getReadNegativeStrandFlag() ? Strand.NEGATIVE : Strand.POSITIVE;
   	String cigar= sam.getCigarString(); //parse cigar and put the breaks into their component parts, in parallel keep track of the splices
   	Collection<Alignments> aligns=parseCigar(cigar, chr, start);
	Gene gene=new Gene( aligns);
	gene.setName(sam.getReadName());
	gene.setOrientation(strand);
	if(sam.getReadString() != null) {gene.setSequence(sam.getReadString()); }
   	return gene;
}
 
开发者ID:mgarber,项目名称:scriptureV2,代码行数:13,代码来源:AlignmentUtils.java

示例8: SingleEndAlignment

import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
public SingleEndAlignment(SAMRecord read) {
  	super(read.getReferenceName(), read.getAlignmentStart()-1, read.getAlignmentStart()); //This is a dummy setup
  	parseCigar(read.getCigarString(), read.getReferenceName(), read.getAlignmentStart()-1);
  	long startT = System.nanoTime();
  	setName(read.getReadName());
long cTime = System.nanoTime() - startT;
cTime = Math.round(cTime/(double)1000000);
if(cTime > 50) {
	logger.debug("parse set read name  took " + cTime);
}

startT = System.nanoTime();
  	if (read.getReadNegativeStrandFlag()) 
  		setOrientation(Strand.NEGATIVE);
  	else
  		setOrientation(Strand.POSITIVE);
cTime = System.nanoTime() - startT;
cTime = Math.round(cTime/(double)1000000);
if(cTime > 50) {
	logger.debug("Set orientation took " + cTime);
}

  	startT = System.nanoTime();
  	try {
  		record = (SAMRecord) read.clone();
  	} catch (CloneNotSupportedException e) {
  		logger.warn("Caught exception on record " + read.getReadName());
  		e.printStackTrace();
  	}
  	//record=new WrapSamRecord(read);
  	assert(read.getAlignmentEnd() == getEnd()); // sanity check
cTime = System.nanoTime() - startT;
cTime = Math.round(cTime/(double)1000000);
if(cTime > 50) {
	logger.debug("Cloning object took " + cTime);
}
  }
 
开发者ID:mgarber,项目名称:scriptureV2,代码行数:38,代码来源:SingleEndAlignment.java

示例9: isCompatiblePair

import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
private boolean isCompatiblePair(SAMRecord r1, SAMRecord r2) {
	if(r1.getReferenceName()==r2.getReferenceName()){
		if((r1.getAlignmentStart()==r2.getMateAlignmentStart())&& (r1.getMateAlignmentStart()==r2.getAlignmentStart())){
			if(r1.getMateNegativeStrandFlag()==r2.getReadNegativeStrandFlag() && r1.getReadNegativeStrandFlag()==r2.getMateNegativeStrandFlag()){
				if(r1.getMateReferenceName().equalsIgnoreCase(r2.getReferenceName()) && r2.getMateReferenceName().equalsIgnoreCase(r1.getReferenceName())){
					return true;
				}
			}
		}
	}
	return false;
}
 
开发者ID:mgarber,项目名称:scriptureV2,代码行数:13,代码来源:AlignmentPair.java

示例10: getSingleEndRead

import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
/**
 * Gets a single end read.
 * 
 * @param sections The tab split sections from the SAM file
 * @param flag The binary flag field from the file
 * @return The read which was read
 * @throws SeqMonkException
 */
private SequenceReadWithChromosome getSingleEndRead (SAMRecord samRecord) throws SeqMonkException {
	int strand;
	int start;
	int end;

	start = samRecord.getAlignmentStart();
	end = samRecord.getAlignmentEnd();

	if (samRecord.getReadNegativeStrandFlag()) {
		strand = Location.REVERSE;
	}
	else {
		strand = Location.FORWARD;
	}


	if (extendBy > 0) {
		if (strand == Location.FORWARD) {
			end += extendBy;
		}
		else if (strand == Location.REVERSE) {
			start -= extendBy;
		}
	}

	ChromosomeWithOffset c;
	try {
		c = collection.genome().getChromosome(samRecord.getReferenceName());
	}
	catch (Exception iae) {
		throw new SeqMonkException(iae.getLocalizedMessage());
	}
	
	start = c.position(start);
	end = c.position(end);

	// We also don't allow readings which are beyond the end of the chromosome
	if (end > c.chromosome().length()) {
		int overrun = end - c.chromosome().length();
		throw new SeqMonkException("Reading position "+end+" was "+overrun+"bp beyond the end of chr"+c.chromosome().name()+" ("+c.chromosome().length()+")");
	}
	if (start < 1) {
		throw new SeqMonkException("Reading position "+start+" was before the start of chr"+c.chromosome().name()+" ("+c.chromosome().length()+")");			
	}

	// We can now make the new reading
	SequenceReadWithChromosome read = new SequenceReadWithChromosome(c.chromosome(),SequenceRead.packPosition(start,end,strand));

	return read;
}
 
开发者ID:s-andrews,项目名称:SeqMonk,代码行数:59,代码来源:BAMFileParser.java

示例11: getPairedEndRead

import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
/**
 * Gets a paired end read.  This method assumes that it will only be passed reads which map
 * to the reverse strand since these are the ones which contain enough information to 
 * unambiguously locate both ends of the pair.
 * 
 * @param sections The tab split sections from the SAM file
 * @param flag The binary flag field
 * @return The read which was read
 * @throws SeqMonkException
 */
private SequenceReadWithChromosome getPairedEndRead (SAMRecord samRecord) throws SeqMonkException {
	int strand;
	int start;
	int end;

	if (!samRecord.getReadNegativeStrandFlag()) {
		throw new SeqMonkException("Read passed to parse pair was not on the negative strand");
	}
	
	if (samRecord.getMateNegativeStrandFlag()) {
		throw new SeqMonkException("Ignored discordantly stranded read pair");
	}
	
	end = samRecord.getAlignmentEnd();
	start = samRecord.getMateAlignmentStart();
	
	if (start > end) {
		throw new SeqMonkException("Ignored discordantly stranded read pair");
	}
	
	if (samRecord.getFirstOfPairFlag()) {
		strand = Location.REVERSE;
	}
	else {
		strand = Location.FORWARD;
	}
	
	if ((end - start)+1 > pairedEndDistance) {
		throw new SeqMonkException("Distance between ends "+((end - start)+1)+" was larger than cutoff ("+pairedEndDistance+")");
	}

	ChromosomeWithOffset c;

	try {
		c = dataCollection().genome().getChromosome(samRecord.getReferenceName());
	}
	catch (Exception e) {
		throw new SeqMonkException(e.getLocalizedMessage());
	}
	
	start = c.position(start);
	end = c.position(end);

	// We also don't allow readings which are beyond the end of the chromosome
	if (end > c.chromosome().length()) {
		int overrun = end - c.chromosome().length();
		throw new SeqMonkException("Reading position "+end+" was "+overrun+"bp beyond the end of chr"+c.chromosome().name()+" ("+c.chromosome().length()+")");
	}
	if (start < 1) {
		throw new SeqMonkException("Reading position "+start+" was before the start of chr"+c.chromosome().name()+" ("+c.chromosome().length()+")");			
	}

	// We can now make the new reading
	SequenceReadWithChromosome read = new SequenceReadWithChromosome(c.chromosome(),SequenceRead.packPosition(start,end,strand));

	return read;
}
 
开发者ID:s-andrews,项目名称:SeqMonk,代码行数:68,代码来源:BAMFileParser.java

示例12: trim

import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
private boolean trim(SAMRecord record, int trimMismatches) {
	record.setAttribute("XT", "true");
	String sequenceCT = record.getReadString();

	int mismatches = (Integer) record.getAttribute("NM");

	if (mismatches >= trimMismatches) {

		boolean isReverse = record.getReadNegativeStrandFlag();


		int currentMismatches = 0;
		int trimPoint = isReverse ? sequenceCT.length() : 0;

		CigarIterator cigarIterator =
				new CigarIterator(record.getCigarString(), isReverse);

		MDTagIterator mdIterator = new MDTagIterator((String) record.getAttribute("MD"), isReverse);

		CigarOperator lastCigarOperator = null;
		while (cigarIterator.hasNext() && currentMismatches < trimMismatches) {
			CigarOperator operator = cigarIterator.next();

			switch (operator) {
				case M:
					MDTagOperator mdOperator = mdIterator.next();
					if (mdOperator == MDTagOperator.VARIANT) {
						currentMismatches++;
						if (currentMismatches < trimMismatches) {
							trimPoint = trimPoint + (isReverse ? -1 : 1);
						}
					} else if (mdOperator == MDTagOperator.SEQUENCE_MATCH) {
						// do nothing
						trimPoint = trimPoint + (isReverse ? -1 : 1);
					} else {
						//should not happen
						return false; // do not trim
					}

					break;
				case I:
					currentMismatches++;
					if (currentMismatches < trimMismatches) {
						trimPoint = trimPoint + (isReverse ? -1 : 1);
					}
					break;
				case D:
					currentMismatches++;
					mdIterator.next();
					break;
				default:
					return false; //do not trim this read, since it has non-supported CIGAR operations
			}
			lastCigarOperator = operator;
		}

		if (currentMismatches >= trimMismatches) {
			if (isReverse) {
				//trimPoint ++; //trim the last mismatch
				record.setReadString(record.getReadString().substring(0, trimPoint).replaceAll(".", "" +
						TRIMMED_BASE)
						+ record.getReadString().substring(trimPoint));
			} else {
				//trimPoint --; //trim the last mismatch
				record.setReadString(record.getReadString().substring(0, trimPoint) + record.getReadString()
						.substring
								(trimPoint).replaceAll(".", "" + TRIMMED_BASE));
			}
			return true;
		}

	}
	return false;

}
 
开发者ID:sing-group,项目名称:bicycle,代码行数:76,代码来源:ListerFilter.java

示例13: completeThesaurusEntry

import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
/**
 * updates a ThesaurusEntry with information about anchor points.
 *
 * This is done by comparing sequences stored in the SAM record and the
 * genome fasta file.
 *
 * @param entry
 * @param record
 * @param genomereader
 */
private void completeThesaurusEntry(ThesaurusEntry entry, SAMRecord record) {

    // get sequences of the read and the genome alignment
    byte[] readseq = record.getReadBases();
    byte[] genomeseq = seqmap.getSequenceBase1(entry.getAlignChr(), entry.alignStart, entry.alignEnd);

    // if clipping has occured, need to redefine readseq
    int numclip = readseq.length - genomeseq.length;
    if (numclip != 0) {
        Cigar cig = record.getCigar();
        if (cig.getCigarElement(0).getOperator() == CigarOperator.S) {
            // clip from the start
            readseq = Arrays.copyOfRange(readseq, numclip, readseq.length);
        } else {
            // clip from the end
            readseq = Arrays.copyOfRange(readseq, 0, readseq.length - numclip);
        }
    }

    // compare the sequences to count substitutions 
    int substitutions = 0;
    int nowreadlen = readseq.length;
    for (int i = 0; i < nowreadlen; i++) {
        if (readseq[i] != genomeseq[i]) {
            substitutions++;
        }
    }

    // reloop and output
    if (substitutions == 0) {
        entry.penalty = 0;
        return;
    }

    // loop and collect information about the type of substitution
    for (int i = 0; i < nowreadlen; i++) {
        if (readseq[i] != genomeseq[i]) {
            ThesaurusAnchor anchor = new ThesaurusAnchor();

            if (record.getReadNegativeStrandFlag()) {
                anchor.originPosition = entry.originEnd - i;
                byte[] temp = new byte[1];
                temp[0] = readseq[i];
                anchor.originRef = (char) (SequenceComplementer.complement(temp)[0]);
                temp[0] = genomeseq[i];
                anchor.originAlt = (char) (SequenceComplementer.complement(temp)[0]);

                anchor.alignPosition = entry.alignStart + i;
                anchor.alignRef = (char) genomeseq[i];
                anchor.alignAlt = (char) readseq[i];

            } else {
                anchor.originPosition = (entry.originStart + i);
                anchor.originRef = (char) readseq[i];
                anchor.originAlt = (char) genomeseq[i];

                anchor.alignPosition = (entry.alignStart + i);
                anchor.alignRef = (char) genomeseq[i];
                anchor.alignAlt = (char) readseq[i];
            }
            entry.addAnchor(anchor);
        }
    }
}
 
开发者ID:tkonopka,项目名称:GeneticThesaurus,代码行数:75,代码来源:ThesaurusWrite.java

示例14: 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]++;
	
}
 
开发者ID:s-andrews,项目名称:BamQC,代码行数:49,代码来源:SoftClipDistribution.java

示例15: 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();
   }
 
开发者ID:shaunmahony,项目名称:multigps-archive,代码行数:48,代码来源:TophatFileHitLoader.java


注:本文中的net.sf.samtools.SAMRecord.getReadNegativeStrandFlag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。