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


Java SAMFileReader类代码示例

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


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

示例1: setupChromBamWriters

import net.sf.samtools.SAMFileReader; //导入依赖的package包/类
/**
 * Creates a collection of SAMFileWriters, one for each chromosome.
 *
 * The definition of the chromosomes is taken from the header of a template
 * bamfile.
 *
 * @param template
 */
private void setupChromBamWriters(File template) {

    SAMFileReader inputSam = new SAMFileReader(template);
    SAMFileHeader inputHeader = inputSam.getFileHeader();
    ArrayList<SAMSequenceRecord> samchroms;
    samchroms = new ArrayList<SAMSequenceRecord>(inputSam.getFileHeader().getSequenceDictionary().getSequences());

    // create another list of just chromosome names
    ArrayList<String> chroms = new ArrayList<String>();
    for (int i = 0; i < samchroms.size(); i++) {
        chroms.add(samchroms.get(i).getSequenceName());
    }
    chroms.add("unmapped");

    // create a filewriter for each chromosome
    for (int i = 0; i < chroms.size(); i++) {
        String nowchrom = chroms.get(i);
        SAMFileHeader nowheader = inputHeader.clone();
        nowheader.addComment("Merged data using GeneticThesaurus merge2chrom: chromosome " + nowchrom);
        SAMFileWriter nowWriter = new SAMFileWriterFactory().makeSAMOrBAMWriter(
                nowheader, true, new File(prefix + "." + nowchrom + ".bam"));
        chrombams.put(nowchrom, nowWriter);
    }

}
 
开发者ID:tkonopka,项目名称:GeneticThesaurus,代码行数:34,代码来源:ThesaurusMerge2Chrom.java

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

示例3: read_Reads

import net.sf.samtools.SAMFileReader; //导入依赖的package包/类
public boolean read_Reads(File path_readAlignments_genome, File path_readAlignments_transcriptome, String outputPath) throws IOException{

		_dictionaryWriter = new BufferedWriter(new FileWriter(new File(outputPath)));

		// Read the alignments for genome and transcriptome mapped reads
		if(path_readAlignments_genome != null){
			ExceRpt_Tools.printLineErr("Processing transcriptome alignments for genome-mapped reads...");
			_readingGenomeMappedReads = true;
			read_Reads(new SAMFileReader(path_readAlignments_genome));
			_dictionaryWriter.flush();
		}

		// Read the alignments for transcriptome mapped reads
		ExceRpt_Tools.printLineErr("Processing transcriptome alignments for genome-UNmapped reads...");
		_readingGenomeMappedReads = false;
		read_Reads(new SAMFileReader(path_readAlignments_transcriptome));
		_dictionaryWriter.flush();

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

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

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

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

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

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

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

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

示例11: getReadsForLocus

import net.sf.samtools.SAMFileReader; //导入依赖的package包/类
public Collection<RecordAndOffset> getReadsForLocus(GenomeAnalysisEngine toolkit, Strand strand, String contig,
													int pos, boolean filterDuplicates) {
	Map<Strand, ArrayList<SAMFileReader>> perStrandReaders = perThreadReaders.get();

	if (perStrandReaders == null) {

		perStrandReaders = new HashMap<>();
		perThreadReaders.set(perStrandReaders);
	}

	ArrayList<SAMFileReader> readers = perStrandReaders.get(strand);
	if (readers == null) {

		readers = new ArrayList<>();
		for (File f : getFilesForStrand(toolkit, strand)) {
			SAMFileReader reader = new SAMFileReader(f, true);
			readers.add(reader);

		}
		perStrandReaders.put(strand, readers);
	}

	LinkedList<SamRecordFilter> filters = new LinkedList<>(toolkit.getFilters());

	return es.cnio.bioinfo.bicycle.Tools.getReadsForLocus(strand, contig, pos, filterDuplicates, readers,
			filters, ListerFilter.TRIMMED_BASE);
}
 
开发者ID:sing-group,项目名称:bicycle,代码行数:28,代码来源:Tools.java

示例12: createSamLocusIterator

import net.sf.samtools.SAMFileReader; //导入依赖的package包/类
private static SamLocusIterator createSamLocusIterator(
		SAMFileReader reader,
		IntervalList site, List<SamRecordFilter> filters) {
	SamLocusIterator iterator;
	iterator = new SamLocusIterator(reader, site, true);


	iterator.setSamFilters(filters);

	iterator.setEmitUncoveredLoci(false);
	return iterator;
}
 
开发者ID:sing-group,项目名称:bicycle,代码行数:13,代码来源:Tools.java

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

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

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


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