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


Java SAMFileReader.iterator方法代码示例

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


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

示例1: BAMFile

import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
protected BAMFile (File file, boolean onlyMapped) throws SequenceFormatException, IOException {
	this.file = file;
	fileSize = file.length();
	name = file.getName();
	this.onlyMapped = onlyMapped;

	SAMFileReader.setDefaultValidationStringency(SAMFileReader.ValidationStringency.SILENT);

	fis = new FileInputStream(file);
	
	br = new SAMFileReader(fis);
	
	header = br.getFileHeader();
	
	it = br.iterator();
	readNext();
}
 
开发者ID:s-andrews,项目名称:BamQC,代码行数:18,代码来源:BAMFile.java

示例2: sourceReads

import net.sf.samtools.SAMFileReader; //导入方法依赖的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();
   }
 
开发者ID:shaunmahony,项目名称:multigps-archive,代码行数:28,代码来源:SAMFileHitLoader.java

示例3: SAMStats

import net.sf.samtools.SAMFileReader; //导入方法依赖的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();        
  }
 
开发者ID:shaunmahony,项目名称:multigps-archive,代码行数:22,代码来源:SAMStats.java

示例4: run

import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
public void run() {
	int num = 0;
	double weightedNum = 0;
	int numDuplicated = 0;
	HashSet<String> readNames = new HashSet<String>();
	log.debug("opening " + aln);
	SAMFileReader reader = new SAMFileReader(new File(aln));
	SAMRecordIterator sri = reader.iterator();
	while(sri.hasNext()) {
		SAMRecord samR = sri.next();
		num++;
		if (samR.getDuplicateReadFlag()) {
			numDuplicated++;
		}
		int multiplicity = samR.getIntegerAttribute("NH");
		weightedNum += weightedNum + 1/(double) multiplicity;
		readNames.add(samR.getReadName());
	}  
	reader.close();
	SAMStats stats = new SAMStats(sample, aln , num, weightedNum, numDuplicated, readNames.size());
	listener.doneAlnAnalysis(stats );
}
 
开发者ID:mgarber,项目名称:scriptureV2,代码行数:23,代码来源:ReadAlignmentStats.java

示例5: BAMFile

import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
protected BAMFile (File file, boolean onlyMapped) throws SequenceFormatException, IOException {
	this.file = file;
	fileSize = file.length();
	name = file.getName();
	this.onlyMapped = onlyMapped;

	SAMFileReader.setDefaultValidationStringency(SAMFileReader.ValidationStringency.SILENT);

	fis = new FileInputStream(file);
	
	br = new SAMFileReader(fis);
	
	it = br.iterator();
	readNext();
}
 
开发者ID:golharam,项目名称:FastQC,代码行数:16,代码来源:BAMFile.java

示例6: BamRegionsMap

import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
public BamRegionsMap(File bamfile, GenomeInfo ginfo, String validate, int minmapqual) throws IOException {

        this.ginfo = ginfo;
        this.minmapqual = minmapqual;
        if (bamfile != null) {
            bamreader = new SAMFileReader(bamfile);
            if (validate.equals("STRICT")) {
                bamreader.setValidationStringency(SAMFileReader.ValidationStringency.STRICT);
            } else if (validate.equals("LENIENT")) {
                bamreader.setValidationStringency(SAMFileReader.ValidationStringency.LENIENT);
            } else {
                bamreader.setValidationStringency(SAMFileReader.ValidationStringency.SILENT);
            }

            bamiterator = bamreader.iterator();
            if (bamiterator.hasNext()) {
                record = bamiterator.next();
                curchr = record.getReferenceName();
            }

        } else {
            bamreader = null;
            bamiterator = null;
        }

        regions = new HashMap<Integer, ArrayList<SAMRecord>>(128);
    }
 
开发者ID:tkonopka,项目名称:GeneticThesaurus,代码行数:28,代码来源:BamRegionsMap.java

示例7: read_Reads

import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
/**
 * Reads the read alignments
 * reference ID format is
 *   [genome|nogenome]:[library]:[referenceID]
 * e.g.
 *   genome:miRNA:hsa-mir-486-1:MI0002470:Homo:sapiens:miR-486:stem-loop
 * 
 * @param path_readAlignments
 * @throws IOException 
 */

public boolean read_Reads(SAMFileReader inputSam) throws IOException{
	inputSam.setValidationStringency(ValidationStringency.SILENT);
	//inputSam.setValidationStringency(ValidationStringency.LENIENT);

	// TODO: put this if/else back when we're done testing
	//if(inputSam.getFileHeader().getSortOrder().equals(SAMFileHeader.SortOrder.queryname)){
	SAMRecord thisRecord;
	HashMap<SAMRecord, String> thisRead = new HashMap<SAMRecord, String>(); 
	SAMRecordIterator it = inputSam.iterator();
	String lastReadID = null;
	while(it.hasNext()){
		//count++;
		thisRecord = it.next();

		//System.out.println(thisRecord.getReferenceName());
		if(!thisRecord.getReadName().equals(lastReadID)  &&  lastReadID != null){
			// new, non first
			assignRead(thisRead);
			thisRead = new HashMap<SAMRecord, String>();
		}

		// put the SAM record into the map with the library type as the value
		//thisRead.put(thisRecord, thisRecord.getReferenceName().split(":")[1]);

		if(_forceLibrary != null)
			thisRead.put(thisRecord, _forceLibrary);
		else
			thisRead.put(thisRecord, thisRecord.getReferenceName().split(":")[0]);
		lastReadID = thisRecord.getReadName();

	}
	// assign the final read!
	if(thisRead.size() > 0)
		assignRead(thisRead);

	/*}else{
	Thunder.printLineErr("ERROR: Input SAM file must be sorted by readID");
	inputSam.close();
	return false;
	}*/

	inputSam.close();
	return true;
}
 
开发者ID:gersteinlab,项目名称:exceRpt,代码行数:56,代码来源:ProcessEndogenousAlignments.java

示例8: loadSAMFile

import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
public static ArrayList<SAMRecord> loadSAMFile(String filename) {
	ArrayList<SAMRecord> samRecords = new ArrayList<SAMRecord>();
	
	File file = new File(filename);
	FileInputStream fis = null;
	try {
		fis = new FileInputStream(file);
	} catch (FileNotFoundException ex) { 
		log.error("File " + filename + " does not exist", ex); 
		return samRecords;
	}
	// Set the default validation Stringency
	SAMFileReader.setDefaultValidationStringency(SAMFileReader.ValidationStringency.SILENT);
	SAMFileReader samReader = new SAMFileReader(fis);
	Iterator<SAMRecord> it = samReader.iterator();
	SAMRecord samRecord;
	while(it.hasNext()) {
		try {
			samRecord = it.next();
			samRecords.add(samRecord);
		} catch (SAMFormatException sfe) { 
			log.error(sfe, sfe);
		}
	}
	// close the file streams
	try {
		samReader.close();
		fis.close();
	} catch (IOException ioe) {
		log.error(ioe, ioe);
		return samRecords;
	}
	return samRecords;
}
 
开发者ID:s-andrews,项目名称:BamQC,代码行数:35,代码来源:SAMRecordLoader.java

示例9: countReads

import net.sf.samtools.SAMFileReader; //导入方法依赖的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();
  }
 
开发者ID:shaunmahony,项目名称:multigps-archive,代码行数:30,代码来源:SAMReader.java

示例10: BamToSingleEndIterator

import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
public BamToSingleEndIterator(File bamFile)
{
	reader = new SAMFileReader(bamFile);
	header = reader.getFileHeader();
	iter = reader.iterator();
	nextAlignment=_next();
}
 
开发者ID:mgarber,项目名称:scriptureV2,代码行数:8,代码来源:BamToSingleEndIterator.java

示例11: BamToPairedEndIterator

import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
/**
 * @param bamFile Input SAM or BAM file to extract header and/or reads from.
 * @param 
 */
 

public BamToPairedEndIterator(File bamFile, TranscriptionRead txnRead, String flag, int maxAllowableInsert) {
	/**
	 * @param bamFile Input SAM or BAM file to extract header and/or reads from.
	 * @param  txnRead  if first read or second read is in direction of trasncription.
	 *         default: first read. TranscriptionRead.FIRST_OF_PAIR
	 * @param flag  "a" to report paired end reads and unpaired end reads
	 *        "p" to only report the paired end reads.
	 * @generator an PairedEndAlignment iterator.
	 *      
	 */
	
	this.flag=flag;
	reader = new SAMFileReader(bamFile);
	header = reader.getFileHeader();
	
	//set header to pairedEnd
	//header.setAttribute(mateLineFlag, "mergedPairedEndFormat");
	iter = reader.iterator();
	bufferCollection = new TreeMap<String,Alignment>();
	this.txnRead=txnRead;
	this.maxAllowableInsert=maxAllowableInsert;
	nextAlignment=advance();
	
}
 
开发者ID:mgarber,项目名称:scriptureV2,代码行数:31,代码来源:BamToPairedEndIterator.java

示例12: doWork

import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
@Override
protected int doWork() {
	
	try {
		
        IoUtil.assertFileIsReadable(INPUT);
        IoUtil.assertFileIsWritable(OUTPUT);
		
        final SAMFileReader reader = new SAMFileReader(INPUT);
        final SAMFileHeader header = reader.getFileHeader();
        final SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(header, true, OUTPUT);
        SAMRecordIterator itr = reader.iterator();
        while (itr.hasNext()) {
        	SAMRecord record = itr.next();
        	record.setDuplicateReadFlag(false);
        	writer.addAlignment(record);
        }
        itr.close();
        writer.close();
        reader.close();
        
	} catch (Exception e) {
		log.error(e);
	}
	
	return 0;
}
 
开发者ID:mgarber,项目名称:scriptureV2,代码行数:28,代码来源:UnmarkDuplicates.java

示例13: sourceReads

import net.sf.samtools.SAMFileReader; //导入方法依赖的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

示例14: countReads

import net.sf.samtools.SAMFileReader; //导入方法依赖的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();
  }
 
开发者ID:shaunmahony,项目名称:multigps-archive,代码行数:54,代码来源:TophatSAMReader.java

示例15: main

import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
public static void main (String [] args) throws IOException {
	ArgumentMap argMap = CLUtil.getParameters(args,USAGE , "default");
	String alnFile = argMap.getInput();
	String out = argMap.getOutput();
	List<String> seqsToChange = new ArrayList<String>();
	if(argMap.containsKey("seqsToFix")) {
		seqsToChange = CLUtil.listFromArray(argMap.getMandatory("seqsToFix").split(","));
	}

	SAMFileReader reader = new SAMFileReader(new File(alnFile));
	SAMFileWriterFactory samfwf = new SAMFileWriterFactory();
	SAMFileHeader oldHeader = reader.getFileHeader();
	SAMFileHeader header = oldHeader.clone();
	header.setSortOrder(oldHeader.getSortOrder());
	oldHeader.getAttributes();
	for (Map.Entry<String, String> he : oldHeader.getAttributes()) { 
		header.setAttribute(he.getKey(), he.getValue());
	}
	
	
	
	header.addProgramRecord(new SAMProgramRecord("nextgen.core.programs.FixChromosomeNames -in " + alnFile + " -out " + out));
	SAMSequenceDictionary ssd = header.getSequenceDictionary();
	SAMSequenceDictionary newSSD = new SAMSequenceDictionary();
	List<SAMSequenceRecord > sequences = ssd.getSequences();
	for (SAMSequenceRecord s : sequences) {
		if(seqsToChange.isEmpty() || seqsToChange.contains(s.getSequenceName())) {
			SAMSequenceRecord ns = new SAMSequenceRecord("chr" + s.getSequenceName(), s.getSequenceLength());
			ns.setAssembly(s.getAssembly());
			ns.setSpecies(ns.getSpecies());
			for (Map.Entry<String, String> e : s.getAttributes()) { 
				ns.setAttribute(e.getKey(), e.getValue());
			}
			newSSD.addSequence(ns);
		} else {
			newSSD.addSequence(s);
		}
	}
	header.setSequenceDictionary(newSSD);
	
	samfwf.setCreateIndex(true);
	SAMFileWriter writer = samfwf.makeBAMWriter(header, true, new File(out))  ;
	
	Iterator<SAMRecord> alnIt = reader.iterator();
	while (alnIt.hasNext()) {
		SAMRecord a = alnIt.next();
		if(seqsToChange.isEmpty() || seqsToChange.contains(a.getReferenceName())) {
			a.setReferenceName("chr"+a.getReferenceName());
			a.setHeader(header);
		}
		writer.addAlignment(a);
	}
	
	reader.close();
	writer.close();

}
 
开发者ID:mgarber,项目名称:scriptureV2,代码行数:58,代码来源:FixChromosomeNames.java


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