本文整理汇总了Java中htsjdk.samtools.fastq.FastqRecord类的典型用法代码示例。如果您正苦于以下问题:Java FastqRecord类的具体用法?Java FastqRecord怎么用?Java FastqRecord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FastqRecord类属于htsjdk.samtools.fastq包,在下文中一共展示了FastqRecord类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: testConstructor
import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
@Test(dataProvider = "fastqRecordData")
public void testConstructor(final FastqRecord record, final GATKRead expected)
throws Exception {
// create the read the read
final FastqGATKRead fastqRead = new FastqGATKRead(record);
Assert.assertFalse(fastqRead.hasHeader());
// test the information which provides from the name
// this is handled by FastqReaNameEncoding
Assert.assertEquals(fastqRead.getName(), expected.getName());
Assert.assertEquals(fastqRead.isSecondOfPair(), expected.isSecondOfPair());
Assert.assertEquals(fastqRead.failsVendorQualityCheck(),
expected.failsVendorQualityCheck());
// check other settings from the FastqGATKRead: bases, qualities
Assert.assertEquals(fastqRead.getBases(), expected.getBases());
Assert.assertEquals(fastqRead.getBaseQualities(), expected.getBaseQualities());
// the comment is not important, but if it is in the FastqGATKRead it should be updated
Assert.assertEquals(fastqRead.getAttributeAsString("CO"),
expected.getAttributeAsString("CO"));
// assert that it is unmapped always
Assert.assertTrue(fastqRead.isUnmapped());
// assert that the mate unmapped state is the same
if (expected.isPaired()) {
Assert.assertEquals(fastqRead.mateIsUnmapped(), expected.mateIsUnmapped());
}
// assert that the BC tag is the same
Assert.assertEquals(fastqRead.getAttributeAsString("BC"),
expected.getAttributeAsString("BC"));
}
开发者ID:magicDGS,项目名称:ReadTools,代码行数:29,代码来源:FastqGATKReadUnitTest.java
示例17: recordProvider
import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
@DataProvider(name = "iterators")
public Object[][] recordProvider() throws Exception {
// list to iterate
final List<FastqRecord> records = Arrays.asList(
new FastqRecord("read0", "ACTG", null, "FFFF"),
new FastqRecord("read1", "TTCC", "comment", "5555"),
new FastqRecord("read2#ACTG/2", "ACAG", "comment2", "F5II")
);
// expected reads
final GATKRead read0 = ArtificialReadUtils.createArtificialUnmappedRead(
null, new byte[] {'A', 'C', 'T', 'G'},
new byte[] {37, 37, 37, 37});
read0.setName("read0");
final GATKRead read1 = ArtificialReadUtils.createArtificialUnmappedRead(
null, new byte[] {'T', 'T', 'C', 'C'},
new byte[] {20, 20, 20, 20});
read1.setName("read1");
read1.setAttribute("CO", "comment");
final GATKRead read2 = ArtificialReadUtils.createArtificialUnmappedRead(
null, new byte[] {'A', 'C', 'A', 'G'},
new byte[] {37, 20, 40, 40});
read2.setName("read2");
read2.setIsSecondOfPair();
read2.setMateIsUnmapped();
read2.setAttribute("CO", "comment2");
read2.setAttribute("BC", "ACTG");
final List<GATKRead> expectedReads = Arrays.asList(read0, read1, read2);
// TODO: add more iterators?
return new Object[][] {
{records.iterator(), fastqEncoder, expectedReads}
};
}
开发者ID:magicDGS,项目名称:ReadTools,代码行数:35,代码来源:RecordToReadIteratorUnitTest.java
示例18: makeFastqRecords
import htsjdk.samtools.fastq.FastqRecord; //导入依赖的package包/类
private void makeFastqRecords(final FastqRecord[] recs, final int[] indices,
final ClusterData cluster, final boolean appendReadNumberSuffix) {
for (short i = 0; i < indices.length; ++i) {
final ReadData readData = cluster.getRead(indices[i]);
final String readBases = StringUtil.bytesToString(readData.getBases()).replace('.', 'N');
final String readName = readNameEncoder.generateReadName(cluster, appendReadNumberSuffix ? i + 1 : null);
recs[i] = new FastqRecord(
readName,
readBases,
null,
SAMUtils.phredToFastq(readData.getQualities())
);
}
}
开发者ID:broadinstitute,项目名称:picard,代码行数:15,代码来源:IlluminaBasecallsToFastq.java
示例19: doUnpaired
import htsjdk.samtools.fastq.FastqRecord; //导入依赖的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
示例20: doPaired
import htsjdk.samtools.fastq.FastqRecord; //导入依赖的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
注:本文中的htsjdk.samtools.fastq.FastqRecord类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论