本文整理汇总了Java中htsjdk.samtools.fastq.FastqReader类的典型用法代码示例。如果您正苦于以下问题:Java FastqReader类的具体用法?Java FastqReader怎么用?Java FastqReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FastqReader类属于htsjdk.samtools.fastq包,在下文中一共展示了FastqReader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: determineQualityFormat
import htsjdk.samtools.fastq.FastqReader; //导入依赖的package包/类
/**
* Looks at fastq input(s) and attempts to determine the proper quality format
*
* Closes the reader(s) by side effect
*
* @param reader1 The first fastq input
* @param reader2 The second fastq input, if necessary. To not use this input, set it to null
* @param expectedQuality If provided, will be used for sanity checking. If left null, autodetection will occur
*/
public static FastqQualityFormat determineQualityFormat(final FastqReader reader1, final FastqReader reader2, final FastqQualityFormat expectedQuality) {
final QualityEncodingDetector detector = new QualityEncodingDetector();
if (reader2 == null) {
detector.add(QualityEncodingDetector.DEFAULT_MAX_RECORDS_TO_ITERATE, reader1);
} else {
detector.add(QualityEncodingDetector.DEFAULT_MAX_RECORDS_TO_ITERATE, reader1, reader2);
reader2.close();
}
reader1.close();
final FastqQualityFormat qualityFormat = detector.generateBestGuess(QualityEncodingDetector.FileContext.FASTQ, expectedQuality);
if (detector.isDeterminationAmbiguous()) {
LOG.warn("Making ambiguous determination about fastq's quality encoding; more than one format possible based on observed qualities.");
}
LOG.info(String.format("Auto-detected quality format as: %s.", qualityFormat));
return qualityFormat;
}
开发者ID:broadinstitute,项目名称:picard,代码行数:30,代码来源:FastqToSam.java
示例2: getBaseName
import htsjdk.samtools.fastq.FastqReader; //导入依赖的package包/类
/** Returns read baseName and asserts correct pair read name format:
* <ul>
* <li> Paired reads must either have the exact same read names or they must contain at least one "/"
* <li> and the First pair read name must end with "/1" and second pair read name ends with "/2"
* <li> The baseName (read name part before the /) must be the same for both read names
* <li> If the read names are exactly the same but end in "/2" or "/1" then an exception will be thrown
* </ul>
*/
String getBaseName(final String readName1, final String readName2, final FastqReader freader1, final FastqReader freader2) {
String [] toks = getReadNameTokens(readName1, 1, freader1);
final String baseName1 = toks[0] ;
final String num1 = toks[1] ;
toks = getReadNameTokens(readName2, 2, freader2);
final String baseName2 = toks[0] ;
final String num2 = toks[1];
if (!baseName1.equals(baseName2)) {
throw new PicardException(String.format("In paired mode, read name 1 (%s) does not match read name 2 (%s)", baseName1,baseName2));
}
final boolean num1Blank = StringUtil.isBlank(num1);
final boolean num2Blank = StringUtil.isBlank(num2);
if (num1Blank || num2Blank) {
if(!num1Blank) throw new PicardException(error(freader1,"Pair 1 number is missing (" +readName1+ "). Both pair numbers must be present or neither.")); //num1 != blank and num2 == blank
else if(!num2Blank) throw new PicardException(error(freader2, "Pair 2 number is missing (" +readName2+ "). Both pair numbers must be present or neither.")); //num1 == blank and num =2 != blank
} else {
if (!num1.equals("1")) throw new PicardException(error(freader1,"Pair 1 number must be 1 ("+readName1+")"));
if (!num2.equals("2")) throw new PicardException(error(freader2,"Pair 2 number must be 2 ("+readName2+")"));
}
return baseName1 ;
}
开发者ID:broadinstitute,项目名称:picard,代码行数:34,代码来源:FastqToSam.java
示例3: getReadNameTokens
import htsjdk.samtools.fastq.FastqReader; //导入依赖的package包/类
/** Breaks up read name into baseName and number separated by the last / */
private String [] getReadNameTokens(final String readName, final int pairNum, final FastqReader freader) {
if(readName.equals("")) throw new PicardException(error(freader,"Pair read name "+pairNum+" cannot be empty: "+readName));
final int idx = readName.lastIndexOf('/');
final String[] result = new String[2];
if (idx == -1) {
result[0] = readName;
result[1] = null;
} else {
result[1] = readName.substring(idx+1, readName.length()); // should be a 1 or 2
if(!result[1].equals("1") && !result[1].equals("2")) { //if not a 1 or 2 then names must be identical
result[0] = readName;
result[1] = null;
}
else {
result[0] = readName.substring(0,idx); // baseName
}
}
return result ;
}
开发者ID:broadinstitute,项目名称:picard,代码行数:25,代码来源:FastqToSam.java
示例4: getNucleotideCount
import htsjdk.samtools.fastq.FastqReader; //导入依赖的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
示例5: veryfiyReads
import htsjdk.samtools.fastq.FastqReader; //导入依赖的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
示例6: compressFastq
import htsjdk.samtools.fastq.FastqReader; //导入依赖的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
示例7: findKmerInReads
import htsjdk.samtools.fastq.FastqReader; //导入依赖的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
示例8: testWritingReading
import htsjdk.samtools.fastq.FastqReader; //导入依赖的package包/类
@Test(dataProvider = "readsToWrite")
public void testWritingReading(final List<GATKRead> readsToWrite) throws Exception {
final File tempFile = IOUtils.createTempFile("testWriting", "fastq");
final FastqGATKWriter writer = new FastqGATKWriter(
new FastqWriterFactory().newWriter(tempFile));
readsToWrite.forEach(writer::addRead);
writer.close();
// now check if reading is the same
final FastqReader reader = new FastqReader(tempFile);
final Iterator<GATKRead> iterator = new RecordToReadIterator<>(reader.iterator(), FastqGATKRead::new);
readsToWrite.forEach(r -> Assert.assertEquals(iterator.next().convertToSAMRecord(null),
r.convertToSAMRecord(null)));
Assert.assertFalse(iterator.hasNext());
reader.close();
}
开发者ID:magicDGS,项目名称:ReadTools,代码行数:16,代码来源:FastqGATKWriterUnitTest.java
示例9: doUnpaired
import htsjdk.samtools.fastq.FastqReader; //导入依赖的package包/类
/** Creates a simple SAM file from a single fastq file. */
protected int doUnpaired(final FastqReader freader, final SAMFileWriter writer) {
int readCount = 0;
final ProgressLogger progress = new ProgressLogger(LOG);
for ( ; freader.hasNext() ; readCount++) {
final FastqRecord frec = freader.next();
final SAMRecord srec = createSamRecord(writer.getFileHeader(), SequenceUtil.getSamReadNameFromFastqHeader(frec.getReadHeader()) , frec, false) ;
srec.setReadPairedFlag(false);
writer.addAlignment(srec);
progress.record(srec);
}
return readCount;
}
开发者ID:broadinstitute,项目名称:picard,代码行数:15,代码来源:FastqToSam.java
示例10: doPaired
import htsjdk.samtools.fastq.FastqReader; //导入依赖的package包/类
/** More complicated method that takes two fastq files and builds pairing information in the SAM. */
protected int doPaired(final FastqReader freader1, final FastqReader freader2, final SAMFileWriter writer) {
int readCount = 0;
final ProgressLogger progress = new ProgressLogger(LOG);
for ( ; freader1.hasNext() && freader2.hasNext() ; readCount++) {
final FastqRecord frec1 = freader1.next();
final FastqRecord frec2 = freader2.next();
final String frec1Name = SequenceUtil.getSamReadNameFromFastqHeader(frec1.getReadHeader());
final String frec2Name = SequenceUtil.getSamReadNameFromFastqHeader(frec2.getReadHeader());
final String baseName = getBaseName(frec1Name, frec2Name, freader1, freader2);
final SAMRecord srec1 = createSamRecord(writer.getFileHeader(), baseName, frec1, true) ;
srec1.setFirstOfPairFlag(true);
srec1.setSecondOfPairFlag(false);
writer.addAlignment(srec1);
progress.record(srec1);
final SAMRecord srec2 = createSamRecord(writer.getFileHeader(), baseName, frec2, true) ;
srec2.setFirstOfPairFlag(false);
srec2.setSecondOfPairFlag(true);
writer.addAlignment(srec2);
progress.record(srec2);
}
if (freader1.hasNext() || freader2.hasNext()) {
throw new PicardException("Input paired fastq files must be the same length");
}
return readCount;
}
开发者ID:broadinstitute,项目名称:picard,代码行数:32,代码来源:FastqToSam.java
示例11: testClipping
import htsjdk.samtools.fastq.FastqReader; //导入依赖的package包/类
@Test(dataProvider = "clippingTests")
public void testClipping(final String clippingAction, final String bases1_1, final String quals1_1, final String bases1_2, final String quals1_2,
final String bases2_1, final String quals2_1, final String bases2_2, final String quals2_2, final String testName) throws IOException {
final File samFile = new File(TEST_DATA_DIR, CLIPPING_TEST_DATA) ;
final File f1 = File.createTempFile("clippingtest1", "fastq");
final File f2 = File.createTempFile("clippingtest2", "fastq");
f1.deleteOnExit();
f2.deleteOnExit();
if (clippingAction != null) {
convertFile(new String[]{
"INPUT=" + samFile.getAbsolutePath(),
"FASTQ=" + f1.getAbsolutePath(),
"SECOND_END_FASTQ=" + f2.getAbsolutePath(),
"CLIPPING_ACTION=" + clippingAction,
"CLIPPING_ATTRIBUTE=" + "XT"
});
} else {
convertFile(new String[]{
"INPUT=" + samFile.getAbsolutePath(),
"FASTQ=" + f1.getAbsolutePath(),
"SECOND_END_FASTQ=" + f2.getAbsolutePath(),
});
}
Iterator<FastqRecord> it = new FastqReader(f1).iterator();
FastqRecord first = it.next();
Assert.assertEquals(first.getReadString(), bases1_1, testName);
Assert.assertEquals(first.getBaseQualityString(), quals1_1, testName);
FastqRecord second = it.next();
Assert.assertEquals(second.getReadString(), bases1_2, testName);
Assert.assertEquals(second.getBaseQualityString(), quals1_2, testName);
it = new FastqReader(f2).iterator();
first = it.next();
Assert.assertEquals(first.getReadString(), bases2_1, testName);
Assert.assertEquals(first.getBaseQualityString(), quals2_1, testName);
second = it.next();
Assert.assertEquals(second.getReadString(), bases2_2, testName);
Assert.assertEquals(second.getBaseQualityString(), quals2_2, testName);
}
开发者ID:broadinstitute,项目名称:picard,代码行数:41,代码来源:SamToFastqTest.java
示例12: testTrimming
import htsjdk.samtools.fastq.FastqReader; //导入依赖的package包/类
@Test(dataProvider = "trimmedData")
public void testTrimming(final String samFilename, final int read1Trim,
final int read1MaxBases, final int expectedRead1Length, final int read2Trim,
final int read2MaxBases, final int expectedRead2Length) throws IOException {
final File samFile = new File(TEST_DATA_DIR, samFilename);
final File pair1File = newTempFastqFile("pair1");
final File pair2File = newTempFastqFile("pair2");
pair1File.deleteOnExit();
pair2File.deleteOnExit();
convertFile(new String[]{
"INPUT=" + samFile.getAbsolutePath(),
"FASTQ=" + pair1File.getAbsolutePath(),
"SECOND_END_FASTQ=" + pair2File.getAbsolutePath(),
"READ1_TRIM=" + read1Trim,
"READ1_MAX_BASES_TO_WRITE=" + read1MaxBases,
"READ2_TRIM=" + read2Trim,
"READ2_MAX_BASES_TO_WRITE=" + read2MaxBases
});
for (final FastqRecord first : new FastqReader(pair1File)) {
Assert.assertEquals(first.getReadString().length(), expectedRead1Length, "Incorrect read length");
Assert.assertEquals(first.getBaseQualityString().length(), expectedRead1Length, "Incorrect quality string length");
}
for (final FastqRecord second : new FastqReader(pair2File)) {
Assert.assertEquals(second.getReadString().length(), expectedRead2Length, "Incorrect read length");
Assert.assertEquals(second.getBaseQualityString().length(), expectedRead2Length, "Incorrect quality string length");
}
}
开发者ID:broadinstitute,项目名称:picard,代码行数:31,代码来源:SamToFastqTest.java
示例13: createFastqReadHeaderSet
import htsjdk.samtools.fastq.FastqReader; //导入依赖的package包/类
private Set<String> createFastqReadHeaderSet(final File file) {
final Set<String> set = new HashSet<String>();
final FastqReader freader = new FastqReader(file);
while (freader.hasNext()) {
final FastqRecord frec = freader.next();
set.add(frec.getReadHeader());
}
return set ;
}
开发者ID:broadinstitute,项目名称:picard,代码行数:10,代码来源:SamToFastqTest.java
示例14: getReadsFromFastq
import htsjdk.samtools.fastq.FastqReader; //导入依赖的package包/类
private static final List<GATKRead> getReadsFromFastq(final File fastqFile) {
try (final FastqReader reader = new FastqReader(fastqFile)) {
final List<GATKRead> readList = new ArrayList<>();
reader.forEachRemaining(read -> readList.add(fastqRecordToGATKRead(read)));
return readList;
}
}
开发者ID:broadinstitute,项目名称:gatk,代码行数:8,代码来源:PSFilterTest.java
示例15: printFastq
import htsjdk.samtools.fastq.FastqReader; //导入依赖的package包/类
/**
* A helper method to print out the sequence ids in a fastq file
* @param fastqFile the fastq file for which the sequence ids should be printed
*/
public void printFastq(File fastqFile)
{
FastqReader fq = new FastqReader(fastqFile);
Iterator it = fq.iterator();
//loop thru the left hand reads
while (it.hasNext())
{
FastqRecord seqRecord = (FastqRecord) it.next();
System.out.println(seqRecord.getReadHeader());
}
fq.close();
}
开发者ID:ethering,项目名称:GenomeHelper,代码行数:17,代码来源:FastqInterlacer.java
示例16: qcSingleEndReads
import htsjdk.samtools.fastq.FastqReader; //导入依赖的package包/类
/**
* Removes reads that contain short/long reads or that contain an 'N', from
* a fastq file
*
* @param fastqFileIn the fastq file
* @param readsOut the good reads
* @param singleEndReadLength the expected length of a single read
* @param format the fastq format (can only be 'illumina' or 'sanger')
* @param writeBadSeqs whether to write the bad reads to a file (bad reads
* file name will start with 'bad_')
*/
public void qcSingleEndReads(File fastqFileIn, File readsOut, int singleEndReadLength, String format, boolean writeBadSeqs)
{
FastqReader fq = new FastqReader(fastqFileIn);
FastqWriterFactory writer = new FastqWriterFactory();
FastqWriter goodSeqs = writer.newWriter(readsOut);
FastqWriter badSeqs = getBadSeqFastqWriter(readsOut, writer);
int itCounter = 0;
if (checkFormat(format) == true)
{
//create an interator for the interlaced file
for (FastqRecord seqRecord : fq)
{
boolean goodRead = checkLengthAndContent(seqRecord, singleEndReadLength);
if (goodRead)
{
FastqRecord newSeq = groomRead(seqRecord, format);
goodSeqs.write(newSeq);
itCounter++;
} else if (writeBadSeqs == true)
{
badSeqs.write(seqRecord);
}
}
}
goodSeqs.close();
badSeqs.close();
System.out.println("Completed writing " + itCounter + " good reads");
}
开发者ID:ethering,项目名称:GenomeHelper,代码行数:45,代码来源:FastqQC.java
示例17: veryfiyPairedReads
import htsjdk.samtools.fastq.FastqReader; //导入依赖的package包/类
/**
* Verifies that two files of left/right paired-end reads are in order and
* contain no fastq format errors
*
* @param fastqLeft the left-handed fastq file to verify
* @param fastqRight the right-handed fastq file to verify
*/
public void veryfiyPairedReads(File fastqLeft, File fastqRight)
{
//System.out.println("I should exit with a read count. If not check the error message");
FastqReader fql = new FastqReader(fastqLeft);
Iterator itl = fql.iterator();
FastqReader fqr = new FastqReader(fastqRight);
Iterator itr = fqr.iterator();
int itCounter = 0;
while (itl.hasNext())
{
FastqRecord seqRecordLeft = (FastqRecord) itl.next();
FastqRecord seqRecordRight = (FastqRecord) itr.next();
String[] leftNameArray = seqRecordLeft.getReadHeader().split(" ");
String[] rightNameArray = seqRecordRight.getReadHeader().split(" ");
String leftName = leftNameArray[0];
String rightName = rightNameArray[0];
//System.out.println(leftName + " : "+rightName);
if (!leftName.equalsIgnoreCase(rightName))
{
System.out.println("Found an error at read " + itCounter);
System.err.println(leftName + " is not the same as " + rightName);
System.exit(0);
}
itCounter++;
}
System.out.println("Counted " + itCounter + " reads which were all in order");
}
开发者ID:ethering,项目名称:GenomeHelper,代码行数:38,代码来源:FastqQC.java
示例18: writeRecords
import htsjdk.samtools.fastq.FastqReader; //导入依赖的package包/类
/**
*
* @param fastqReader a FastqReader object
* @param out - the output fastq reads
* @param mappedReads a HashSet of mapped reads
*/
public static void writeRecords(FastqReader fastqReader, FastqWriter out, HashSet<String> mappedReads) {
while (fastqReader.hasNext()) {
FastqRecord record = fastqReader.next();
String readName = record.getReadHeader();
int hashIndex = readName.indexOf(" ");
readName = readName.substring(0, hashIndex);
if (mappedReads.contains(readName)) {
out.write(record);
}
}
out.close();
}
开发者ID:ethering,项目名称:GenomeHelper,代码行数:19,代码来源:FastqParser.java
示例19: getPairedFastqSeqsFromHashSet
import htsjdk.samtools.fastq.FastqReader; //导入依赖的package包/类
/**
* Extract paired-end fastq sequences from a list of sequence names
*
* @param list a HashSet of read names
* @param fastqLeft all left-handed reads
* @param fastqRight all right-handed reads
* @param fastqLeftOut the left-handed reads in the list
* @param fastqRightOut the right-handed reads in the list
* @throws FileNotFoundException
* @throws IOException
*/
public void getPairedFastqSeqsFromHashSet(HashSet list, File fastqLeft, File fastqRight,
File fastqLeftOut, File fastqRightOut) throws FileNotFoundException, IOException {
final FastqReader readerLeft = new FastqReader(fastqLeft);
final FastqReader readerRight = new FastqReader(fastqRight);
FastqWriterFactory writer = new FastqWriterFactory();
FastqWriter outLeft = writer.newWriter(fastqLeftOut);
FastqWriter outRight = writer.newWriter(fastqRightOut);
int recordsfound = 0;
while (readerLeft.hasNext()) {
FastqRecord recordLeft = readerLeft.next();
FastqRecord recordRight = readerRight.next();
String leftRead = recordLeft.getReadHeader();
int hashIndex = leftRead.indexOf(" ");
leftRead = leftRead.substring(0, hashIndex);
if (list.contains(leftRead)) {
recordsfound++;
outLeft.write(recordLeft);
outRight.write(recordRight);
}
}
System.out.println("Processed " + list.size() + " , found " + recordsfound);
}
开发者ID:ethering,项目名称:GenomeHelper,代码行数:38,代码来源:FastqParser.java
示例20: fastqToFastaFile
import htsjdk.samtools.fastq.FastqReader; //导入依赖的package包/类
/**
* Turns a fastq file into fasta format
*
* @param fastqIn the fastq intput file
* @param fastaOut the fasta output file
* @throws IOException
*/
public void fastqToFastaFile(File fastqIn, File fastaOut) throws IOException {
final FastqReader reader = new FastqReader(fastqIn);
Writer out = new BufferedWriter(new FileWriter(fastaOut));
while (reader.hasNext()) {
FastqRecord record = reader.next();
out.write(fastqToFastaSeq(record).toString());
}
out.close();
}
开发者ID:ethering,项目名称:GenomeHelper,代码行数:17,代码来源:FastqParser.java
注:本文中的htsjdk.samtools.fastq.FastqReader类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论