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


Java SAMFileReader.close方法代码示例

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


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

示例1: splitIntoChroms

import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
/**
 * copy reads from one bam file and put them into files by chromosome.
 *
 * @param nowbam
 */
private void splitIntoChroms(File nowbam) {
    SAMFileReader inputSam = new SAMFileReader(nowbam);

    // write each aligned record into its separate file, or into "unmapped"
    for (final SAMRecord record : inputSam) {
        String nowchrom = record.getReferenceName();
        SAMFileWriter nowwriter = chrombams.get(nowchrom);
        if (nowwriter == null) {
            nowwriter = chrombams.get("unmapped");
        }
        nowwriter.addAlignment(record);
    }

    inputSam.close();
}
 
开发者ID:tkonopka,项目名称:GeneticThesaurus,代码行数:21,代码来源:ThesaurusMerge2Chrom.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: close

import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
public void close() {
		
		writer.close();
/*		reader = new SAMFileReader(new File(this.output+".temp.bam"));
		header = reader.getFileHeader();
	    header.setSortOrder(SortOrder.coordinate);
		final SAMFileWriter writer2 = new SAMFileWriterFactory().makeSAMOrBAMWriter(header, false, new File(this.output));
	    for (final SAMRecord rec: reader) {
	    	writer2.addAlignment(rec);
	    }
	    logger.info("Finished reading inputs, merging and writing to output now.");

	    reader.close();
	    writer2.close();*/
		//Now build a BAM index
		File transcriptomeBamIdxFile = new File( this.output + BAMIndex.BAMIndexSuffix);
		if(transcriptomeBamIdxFile.exists()) { transcriptomeBamIdxFile.delete();}
		SAMFileReader reader2 = new SAMFileReader(new File(this.output));
		BuildBamIndex.createIndex(reader2,transcriptomeBamIdxFile);
		reader2.close();
	}
 
开发者ID:mgarber,项目名称:scriptureV2,代码行数:22,代码来源:PairedEndWriter.java

示例6: apply

import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
@Override
public String apply(File f) {
    if (!detectable(f)) {
        throw new IllegalArgumentException("Cannot detect sample name for file: " + f.getPath());
    }
    final SAMFileReader in = new SAMFileReader(f);
    try {
        final SAMFileHeader header = in.getFileHeader();
        final List<SAMReadGroupRecord> rgs = header.getReadGroups();
        assertFalse(rgs.isEmpty(), "Cannot determine sample name: missing read group information for file: " + f.getPath());
        assertFalse(rgs.size() > 1, "Cannot determine sample name: more than one read group detected for file: " + f.getPath());
        final String sample = rgs.get(0).getSample();
        assertFalse(sample == null, "Cannot determine sample name: missing sample name in read group for file: " + f.getPath());
        return sample;
    } finally {
        in.close();
    }
}
 
开发者ID:TGenNorth,项目名称:ISGPipeline,代码行数:19,代码来源:BAMSampleNameDetectionAlgorithm.java

示例7: run

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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: getSizesFromSAM

import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
public static Map<String, Integer> getSizesFromSAM(String samFileName) {
	final SAMFileReader inputSam = new SAMFileReader(new File(samFileName));
	SAMFileHeader header = inputSam.getFileHeader();
	SAMSequenceDictionary dictionary = header.getSequenceDictionary();
	List<SAMSequenceRecord> references = dictionary.getSequences();
	Map<String, Integer> sizes = new LinkedHashMap<String, Integer>(references.size());
	for(SAMSequenceRecord r : references) {
		sizes.put(r.getSequenceName(), r.getSequenceLength());
	}
	inputSam.close();
	
	return sizes;
}
 
开发者ID:mgarber,项目名称:scriptureV2,代码行数:14,代码来源:AlignmentUtils.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: doWork

import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
@Override
protected int doWork() {
    IoUtil.assertFileIsReadable(INPUT);
    IoUtil.assertFileIsWritable(OUTPUT);
    IoUtil.assertFileIsWritable(STATS);

    try {
    	// Read and filter
    	SAMFileReader reader = new SAMFileReader(INPUT);
    	final SAMFileHeader header = reader.getFileHeader();

    	// In our current pipeline, unsorted BAM files output by BWA alignment have read pairs next to each other.
    	if (header.getSortOrder() == SAMFileHeader.SortOrder.unsorted) {
    		log.warn("Treating unsorted SAM file as queryname-sorted.  Check that this produces correct behavior.");
    	}
    	header.setSortOrder(SAMFileHeader.SortOrder.queryname);
    	
    	PairedEndReadIterator itr = new PairedEndReadIterator(reader);
    	
    	header.setSortOrder(SAMFileHeader.SortOrder.unsorted);
    	SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(header, false, OUTPUT);
    	
    	while (itr.hasNext()) {
    		Pair<SAMRecord> pair = itr.next();
    		SAMRecord first = pair.getValue1();
    		SAMRecord second = pair.getValue2();
    		
    		if (readMapsToProbe(first, header) || readMapsToProbe(second, header)) {
    			writer.addAlignment(first);
    			writer.addAlignment(second);
    			addStartEndIndices(first, second);
    		}
    	}
    	
    	reader.close();
    	writer.close();
    	
    	BufferedWriter bw = new BufferedWriter(new FileWriter(STATS));
		bw.write("index\tstart\tend\n");
    	for (int i = 0; i < startIndex.length; i++) {
    		bw.write(i + "\t" + startIndex[i] + "\t"+ endIndex[i] + "\n");
    	}
    	bw.close();
    	
    } catch (Exception e) {
    	log.error(e);
    }

    return 0;
}
 
开发者ID:mgarber,项目名称:scriptureV2,代码行数:51,代码来源:CountProbes.java


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