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


Java FastqRecord类代码示例

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


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

示例1: FastqGATKRead

import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
/**
 * Creates a GATKRead from a FastqRecord and a header.
 *
 * @param header the header for the record.
 * @param record the record to use as GATKRead.
 */
public FastqGATKRead(final SAMFileHeader header, final FastqRecord record) {
    super(new SAMRecord(header));
    Utils.nonNull(record, "null record");
    // update the record with the read name information
    FastqReadNameEncoding.updateReadFromReadName(this, record.getReadName());
    // set the bases and the qualities
    this.setBases(record.getReadBases());
    this.setBaseQualities(record.getBaseQualities());
    // add the comments in the quality header to the comment if present
    final String baseQualHeader = record.getBaseQualityHeader();
    if (baseQualHeader != null) {
        // the default tag in the specs is CO
        this.setAttribute(SAMTag.CO.toString(), baseQualHeader);
    }
    this.setIsUnmapped();
    if (this.isPaired()) {
        this.setMateIsUnmapped();
    }
}
 
开发者ID:magicDGS,项目名称:ReadTools,代码行数:26,代码来源:FastqGATKRead.java

示例2: createSamRecord

import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
private SAMRecord createSamRecord(final SAMFileHeader header, final String baseName, final FastqRecord frec, final boolean paired) {
    final SAMRecord srec = new SAMRecord(header);
    srec.setReadName(baseName);
    srec.setReadString(frec.getReadString());
    srec.setReadUnmappedFlag(true);
    srec.setAttribute(ReservedTagConstants.READ_GROUP_ID, READ_GROUP_NAME);
    final byte[] quals = StringUtil.stringToBytes(frec.getBaseQualityString());
    convertQuality(quals, QUALITY_FORMAT);
    for (final byte qual : quals) {
        final int uQual = qual & 0xff;
        if (uQual < MIN_Q || uQual > MAX_Q) {
            throw new PicardException("Base quality " + uQual + " is not in the range " + MIN_Q + ".." +
            MAX_Q + " for read " + frec.getReadHeader());
        }
    }
    srec.setBaseQualities(quals);

    if (paired) {
        srec.setReadPairedFlag(true);
        srec.setMateUnmappedFlag(true);
    }
    return srec ;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:24,代码来源:FastqToSam.java

示例3: createNewFastqRecordWithAdditionalAnnotation

import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
private static FastqRecord createNewFastqRecordWithAdditionalAnnotation(FastqRecord record, String additionalAnnotation, String sequence, String quality) {
	String seqHeaderPrefix = record.getReadHeader();
	String seqLine = record.getReadString();
	if (sequence != null) {
		seqLine = sequence;
	}
	String qualHeaderPrefix = record.getBaseQualityHeader();
	if (qualHeaderPrefix != null) {
		qualHeaderPrefix += additionalAnnotation;
	} else {
		qualHeaderPrefix = additionalAnnotation;
	}
	String qualLine = record.getBaseQualityString();
	if (quality != null) {
		qualLine = quality;
	}
	FastqRecord newRecord = new FastqRecord(seqHeaderPrefix, seqLine, qualHeaderPrefix, qualLine);
	return newRecord;
}
 
开发者ID:NimbleGen,项目名称:bioinformatics,代码行数:20,代码来源:FastqFindAndTrimTool.java

示例4: reverseCompliment

import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
public static void reverseCompliment(File inputFastqFile, File outputFastqFile) {

		try (FastqWriter writer = new FastqWriter(outputFastqFile)) {
			try (FastqReader reader = new FastqReader(inputFastqFile)) {
				while (reader.hasNext()) {
					FastqRecord record = reader.next();

					ISequence sequence = new NucleotideCodeSequence(record.getReadString());
					ISequence newSequence = sequence.getCompliment();

					String qualityString = record.getBaseQualityString();
					String newQualityString = qualityString;// StringUtil.reverse(qualityString);

					FastqRecord newRecord = new FastqRecord(record.getReadHeader(), newSequence.toString(), record.getBaseQualityHeader(), newQualityString);
					writer.write(newRecord);

				}
			}
		}
	}
 
开发者ID:NimbleGen,项目名称:bioinformatics,代码行数:21,代码来源:FastqUtil.java

示例5: subSample

import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
public static void subSample(File fastqFile, File outputFile, int sampleSize) throws IOException {

		int numberOfLines = FileUtil.countNumberOfLinesInFile(fastqFile);
		int numberOfEntries = numberOfLines / LINES_PER_ENTRY;

		sampleSize = Math.min(sampleSize, numberOfEntries);
		int[] sortedSampledIndexes = getSortedSampledIndexes(numberOfEntries, sampleSize, System.currentTimeMillis());

		int fastqIndex = 0;
		int sortedSampleIndex = 0;
		try (FastqWriter writer = new FastqWriter(outputFile)) {
			try (FastqReader reader = new FastqReader(fastqFile)) {
				while (reader.hasNext() && (sortedSampleIndex < sortedSampledIndexes.length)) {
					FastqRecord record = reader.next();

					if (fastqIndex == sortedSampledIndexes[sortedSampleIndex]) {
						writer.write(record);
						sortedSampleIndex++;
					}

					fastqIndex++;
				}
			}
		}

	}
 
开发者ID:NimbleGen,项目名称:bioinformatics,代码行数:27,代码来源:FastqUtil.java

示例6: MergedSamIterator

import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
public MergedSamIterator(Iterator<SAMRecord> samIter, Iterator<FastqRecord> fastq1Iter, Iterator<FastqRecord> fastq2Iter, boolean trimmingSkipped,
		ProbeTrimmingInformation probeTrimmingInformation, MergedSamNamingConvention namingConvention, boolean useFastqSequenceAndQualities, boolean shouldCheckIfBamTrimmed,
		boolean useFastqIndexesAsFastqReadNamesWhenMerging) {
	super();
	this.samIter = samIter;
	this.fastq1Iter = fastq1Iter;
	this.fastq2Iter = fastq2Iter;
	this.trimmingSkipped = trimmingSkipped;
	this.probeTrimmingInformation = probeTrimmingInformation;
	this.totalMatchingPairs = 0;
	this.namingConvention = namingConvention;
	this.useFastqSequenceAndQualities = useFastqSequenceAndQualities;
	this.shouldCheckIfBamTrimmed = shouldCheckIfBamTrimmed;
	this.useFastqIndexesAsFastqReadNamesWhenMerging = useFastqIndexesAsFastqReadNamesWhenMerging;
	this.fastqIndex = -1;
	this.sampleSamReadNames = new HashSet<>();
	this.sampleFastqReadNames = new HashSet<>();
	nextRecord = getNextRecordToReturn();
}
 
开发者ID:NimbleGen,项目名称:bioinformatics,代码行数:20,代码来源:FastqAndBamFileMerger.java

示例7: checkLengthAndContent

import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
/**
 * Quality controls a fastq read
 *
 * @param seqRecord a net.sf.picard.fastq.FastqRecord to QC
 * @param singleEndReadLength the expected length of a single end read
 * @return true if the read is the correct length and contains no 'N's,
 * false otherwise
 */
public boolean checkLengthAndContent(FastqRecord seqRecord, int singleEndReadLength)
{
    //get the length of them
    int seqLength = seqRecord.getReadString().length();
    String readString = seqRecord.getReadString();
    boolean containsN = readString.toLowerCase().contains("n");

    if (seqLength == singleEndReadLength && containsN == false)
    {
        return true;
    } else
    {
        return false;
    }
}
 
开发者ID:ethering,项目名称:GenomeHelper,代码行数:24,代码来源:FastqQC.java

示例8: getNucleotideCount

import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
/**
 * Counts the number of reads and their cumulative nucleotide content.
 * Useful for when a fastq file has varying read lengths, e.g. after
 * trimming. Prints the number of reads and their cumulative nucleotide
 * content.
 *
 * @param fastq the fastq-formatted sequence file to analyse
 * @return nucleotides the combined number of nucleotides in a fastq file
 */
public double getNucleotideCount(File fastq)
{
    FastqReader fq = new FastqReader(fastq);
    double reads = 0;
    double nucleotides = 0;

    for (FastqRecord seqRecord : fq)
    {
        reads++;
        int seqLength = seqRecord.getReadString().length();
        nucleotides += seqLength;
    }
    NumberFormat formatter = new DecimalFormat("###.#####");

    String readsString = formatter.format(reads);
    String ntString = formatter.format(nucleotides);
    System.out.println("No. of reads\tNucleotide count");
    System.out.println(readsString + "\t" + ntString);
    return nucleotides;
}
 
开发者ID:ethering,项目名称:GenomeHelper,代码行数:30,代码来源:FastqQC.java

示例9: veryfiyReads

import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
/**
 * Checks a fastq file to verify that all the reads can be parsed into a
 * FastqRecord. Errors should be thrown if any of the reads are not
 * formatted correctly.
 *
 * @param fastq the fastq file to verify
 */
public void veryfiyReads(File fastq)
{
    System.out.println("I should exit with a read count. If not check the error message");
    FastqReader fq = new FastqReader(fastq);
    Iterator it = fq.iterator();

    int itCounter = 0;
    while (it.hasNext())
    {
        FastqRecord seqRecord = (FastqRecord) it.next();
        itCounter++;
    }

    System.out.println("Counted " + itCounter + " reads");
}
 
开发者ID:ethering,项目名称:GenomeHelper,代码行数:23,代码来源:FastqQC.java

示例10: compressFastq

import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
public void compressFastq(File fastqFile, File fastqOut) throws FileNotFoundException, IOException, ClassNotFoundException
{
    FastqReader fqr = new FastqReader(fastqFile);
    FastqWriterFactory writer = new FastqWriterFactory();
    FastqWriter goodReads = writer.newWriter(fastqOut);

    Iterator<FastqRecord> it = fqr.iterator();

    //loop thru the interlaced file
    while (it.hasNext())
    {
        FastqRecord fastqRecord = it.next();
        if (!fastqRecord.getReadString().equalsIgnoreCase(""))
        {
            goodReads.write(fastqRecord);
        }
    }
    goodReads.close();
}
 
开发者ID:ethering,项目名称:GenomeHelper,代码行数:20,代码来源:FastqCompression.java

示例11: findKmerInReads

import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
/**
 * Finds kmer or subsequence in fastq file and prints to STDOUT
 * @param fastqFileIn the fastq file to search
 * @param kmer the kmer or subsequence to locate
 */
public void findKmerInReads(File fastqFileIn, String kmer) 
{
    FastqReader fq = new FastqReader(fastqFileIn);
    int found = 0;
    for (FastqRecord seqRecord : fq) 
    {
        String readString = seqRecord.getReadString();
        boolean containsKmer = readString.toLowerCase().contains(kmer.toLowerCase());
        if (containsKmer)
        {
            System.out.println(seqRecord.getReadHeader());
            System.out.println(readString);
            found++;
        }
    }
    System.out.println("Found "+ found + " occurances");
}
 
开发者ID:ethering,项目名称:GenomeHelper,代码行数:23,代码来源:FastqParser.java

示例12: testGroomRead

import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
/**
 * Test of groomRead method, of class FastqQC.
 */
@Test
public void testGroomRead()
{
    System.out.println("groomRead");
    // an illumina quality encoded read
    FastqRecord record = new FastqRecord("@HWI-EAS396_0001:5:1:10468:1298#0/1", "CTTTTAGCAAGATATCTTATCCATTCCATCTTCGATCCACACAATTGAATCATGTAATTCTCCAATGTAACGCAAT",
            "+HWI-EAS396_0001:5:1:10468:1298#0/1", "ddc_cfcccfa[ddab\\_a`cfffdffS_ffc^fYddcWe]`]X^bcbadcffccW^ae[ffffffcdffdfaWcc");

    FastqQC instance = new FastqQC();
    FastqQualityFormat qualFormat = instance.guessFormat(record);
    assertEquals(qualFormat.toString(), "Illumina");

    String format = "illumina";
    FastqRecord groomedRead = instance.groomRead(record, format);
    qualFormat = instance.guessFormat(groomedRead);
    assertEquals(qualFormat.toString(), "Standard");
}
 
开发者ID:ethering,项目名称:GenomeHelper,代码行数:21,代码来源:FastqQCTest.java

示例13: addRead

import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
@Override
public void addRead(final GATKRead read) {
    // adding the raw barcode information if found
    String readName = RTReadUtils.getReadNameWithIlluminaBarcode(read);
    // adding the pair information
    if (read.isPaired()) {
        readName += (read.isFirstOfPair())
                ? FastqConstants.FIRST_OF_PAIR : FastqConstants.SECOND_OF_PAIR;
    }
    writer.write(new FastqRecord(readName,
            read.getBasesString(),
            read.getAttributeAsString(SAMTag.CO.name()),
            ReadUtils.getBaseQualityString(read)));
}
 
开发者ID:magicDGS,项目名称:ReadTools,代码行数:15,代码来源:FastqGATKWriter.java

示例14: getRead

import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
private static final GATKRead getRead(final String[] tokens,
        final int baseToken, final int qualityToken) {
    return new FastqGATKRead(new FastqRecord(
            // the '@' symbol was removed when getting the tokens
            tokens[READ_NAME_TOKEN],
            tokens[baseToken],
            null, // there is no quality header
            tokens[qualityToken]));
}
 
开发者ID:magicDGS,项目名称:ReadTools,代码行数:10,代码来源:DistmapEncoder.java

示例15: fastqRecordDataProvider

import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
@DataProvider(name = "fastqRecordData")
public Iterator<Object[]> fastqRecordDataProvider() {
    final String baseQualities = "FFGCHI5";
    final String bases = "ACTGTTAG";
    final GATKRead baseRecord = ArtificialReadUtils
            .createArtificialUnmappedRead(null,
                    new byte[] {'A', 'C', 'T', 'G', 'T', 'T', 'A', 'G'},
                    new byte[] {37, 37, 38, 34, 39, 40, 20});
    baseRecord.setName("baseRecord");
    final List<Object[]> data = new ArrayList<>();
    // simple case test
    data.add(new Object[] {new FastqRecord(baseRecord.getName(), bases, null, baseQualities),
            baseRecord.deepCopy()});
    // case with comment information
    baseRecord.setAttribute(SAMTag.CO.name(), "quality comment");
    data.add(new Object[] {
            new FastqRecord(baseRecord.getName(), bases, "quality comment", baseQualities),
            baseRecord.deepCopy()});
    // case with a read name with pair-end information
    baseRecord.setIsSecondOfPair();
    baseRecord.setIsUnmapped();
    data.add(new Object[] {
            new FastqRecord(baseRecord.getName() + "/2", bases, "quality comment",
                    baseQualities),
            baseRecord.deepCopy()});
    // case with read name as CASAVA format
    baseRecord.setName("baseRecord");
    baseRecord.setAttribute("BC", "ATCG");
    data.add(new Object[] {
            new FastqRecord("baseRecord 2:N:3:ATCG", bases, "quality comment", baseQualities),
            baseRecord.deepCopy()});
    // case with PF flag
    baseRecord.setFailsVendorQualityCheck(true);
    data.add(new Object[] {
            new FastqRecord("baseRecord 2:Y:3:ATCG", bases, "quality comment", baseQualities),
            baseRecord.deepCopy()});
    return data.iterator();
}
 
开发者ID:magicDGS,项目名称:ReadTools,代码行数:39,代码来源:FastqGATKReadUnitTest.java


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