本文整理汇总了Java中net.sf.samtools.SAMRecord.getReadString方法的典型用法代码示例。如果您正苦于以下问题:Java SAMRecord.getReadString方法的具体用法?Java SAMRecord.getReadString怎么用?Java SAMRecord.getReadString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.samtools.SAMRecord
的用法示例。
在下文中一共展示了SAMRecord.getReadString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertToPairedEndFragment
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
public static SAMRecord convertToPairedEndFragment(SAMRecord rec) {
int insertSize = Math.abs(rec.getInferredInsertSize());
//TODO: possible to remove (insertSize > 0) clause? What does an insert size of 0 mean?
if (rec.getReadPairedFlag() && rec.getProperPairFlag() && !rec.getReadUnmappedFlag()
&& (insertSize <= MAX_INSERT) && (rec.getAlignmentStart() < rec.getMateAlignmentStart())
&& rec.getReferenceName() != "chrM") // current paired end representation doesn't do well with circular chromosomes
{
//We need to get the full fragment contained by read.getStart to pair.getEnd
int readEnd=rec.getAlignmentEnd();
int mateStart=rec.getMateAlignmentStart();
//int extension = insertSize - rec.getReadLength();
int extension=(mateStart-readEnd)+rec.getReadLength();
if (extension <= MAX_INSERT) {
String newRead = rec.getReadString() + StringUtils.repeat("N", extension);
rec.setReadString(newRead);
String newQual = StringUtils.repeat("A", newRead.length());
if(!rec.getBaseQualityString().equals("*")) newQual = rec.getBaseQualityString() + StringUtils.repeat("A", extension);
rec.setBaseQualityString(newQual);
String newCigar=newRead.length()+"M";
rec.setCigarString(newCigar);
// Change attributes to represent single read
rec.setMateReferenceName("*");
rec.setMateAlignmentStart(0);
rec.setFirstOfPairFlag(false);
rec.setMateNegativeStrandFlag(false);
rec.setMateUnmappedFlag(false);
rec.setProperPairFlag(false);
rec.setReadPairedFlag(false);
rec.setSecondOfPairFlag(false);
}
} else {
rec = null;
}
return rec;
}
示例2: toFastq
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
private String toFastq(SAMRecord value1) {
String seq=value1.getReadString();
if(value1.getReadNegativeStrandFlag()){
seq=Sequence.reverseSequence(seq);
}
String name=value1.getReadName();
String quality=value1.getBaseQualityString();
return name+"\n"+seq+"\n"+"+\n"+quality;
}
示例3: SAMFormatFullBED
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
public static Gene SAMFormatFullBED(SAMRecord sam){
String chr=sam.getReferenceName();
int start=sam.getAlignmentStart()-1; //TODO: Do we need the -1, it is a left over from the method above.
Strand strand=sam.getReadNegativeStrandFlag() ? Strand.NEGATIVE : Strand.POSITIVE;
String cigar= sam.getCigarString(); //parse cigar and put the breaks into their component parts, in parallel keep track of the splices
Collection<Alignments> aligns=parseCigar(cigar, chr, start);
Gene gene=new Gene( aligns);
gene.setName(sam.getReadName());
gene.setOrientation(strand);
if(sam.getReadString() != null) {gene.setSequence(sam.getReadString()); }
return gene;
}
示例4: trim
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
private boolean trim(SAMRecord record, int trimMismatches) {
record.setAttribute("XT", "true");
String sequenceCT = record.getReadString();
int mismatches = (Integer) record.getAttribute("NM");
if (mismatches >= trimMismatches) {
boolean isReverse = record.getReadNegativeStrandFlag();
int currentMismatches = 0;
int trimPoint = isReverse ? sequenceCT.length() : 0;
CigarIterator cigarIterator =
new CigarIterator(record.getCigarString(), isReverse);
MDTagIterator mdIterator = new MDTagIterator((String) record.getAttribute("MD"), isReverse);
CigarOperator lastCigarOperator = null;
while (cigarIterator.hasNext() && currentMismatches < trimMismatches) {
CigarOperator operator = cigarIterator.next();
switch (operator) {
case M:
MDTagOperator mdOperator = mdIterator.next();
if (mdOperator == MDTagOperator.VARIANT) {
currentMismatches++;
if (currentMismatches < trimMismatches) {
trimPoint = trimPoint + (isReverse ? -1 : 1);
}
} else if (mdOperator == MDTagOperator.SEQUENCE_MATCH) {
// do nothing
trimPoint = trimPoint + (isReverse ? -1 : 1);
} else {
//should not happen
return false; // do not trim
}
break;
case I:
currentMismatches++;
if (currentMismatches < trimMismatches) {
trimPoint = trimPoint + (isReverse ? -1 : 1);
}
break;
case D:
currentMismatches++;
mdIterator.next();
break;
default:
return false; //do not trim this read, since it has non-supported CIGAR operations
}
lastCigarOperator = operator;
}
if (currentMismatches >= trimMismatches) {
if (isReverse) {
//trimPoint ++; //trim the last mismatch
record.setReadString(record.getReadString().substring(0, trimPoint).replaceAll(".", "" +
TRIMMED_BASE)
+ record.getReadString().substring(trimPoint));
} else {
//trimPoint --; //trim the last mismatch
record.setReadString(record.getReadString().substring(0, trimPoint) + record.getReadString()
.substring
(trimPoint).replaceAll(".", "" + TRIMMED_BASE));
}
return true;
}
}
return false;
}
示例5: getSamString
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
/**
* Get sam line for record
* @param rec The record
* @return Sam formatted line ending in newline
*/
public static String getSamString(SAMRecord rec) {
// Make string representation of record in sam format
String rtrn = rec.getReadName() + "\t";
// Get sam flags
int flags = 0;
// 0x1 template having multiple segments in sequencing
if(rec.getReadPairedFlag()) flags += 1;
// 0x4 segment unmapped
if(rec.getReadUnmappedFlag()) flags += 4;
// 0x10 SEQ being reverse complemented
if(rec.getReadNegativeStrandFlag()) flags += 16;
// 0x100 secondary alignment
if(rec.getNotPrimaryAlignmentFlag()) flags += 256;
// 0x200 not passing quality controls
if(rec.getReadFailsVendorQualityCheckFlag()) flags += 512;
// 0x400 PCR or optical duplicate
if(rec.getDuplicateReadFlag()) flags += 1024;
if(rec.getReadPairedFlag()) {
// 0x2 each segment properly aligned according to the aligner
if(rec.getProperPairFlag()) flags += 2;
// 0x8 next segment in the template unmapped
if(rec.getMateUnmappedFlag()) flags += 8;
// 0x20 SEQ of the next segment in the template being reversed
if(rec.getMateNegativeStrandFlag()) flags += 32;
// 0x40 the first segment in the template
if(rec.getFirstOfPairFlag()) flags += 64;
// 0x80 the last segment in the template
if(rec.getSecondOfPairFlag()) flags += 128;
}
rtrn += Integer.valueOf(flags).toString() + "\t";
// The rest of the sam fields
rtrn += rec.getReferenceName() + "\t";
rtrn += rec.getAlignmentStart() + "\t";
rtrn += rec.getMappingQuality() + "\t";
rtrn += rec.getCigarString() + "\t";
rtrn += rec.getMateReferenceName() + "\t";
rtrn += rec.getMateAlignmentStart() + "\t";
rtrn += rec.getInferredInsertSize() + "\t";
rtrn += rec.getReadString() + "\t";
rtrn += rec.getBaseQualityString() + "\n";
return rtrn;
}
示例6: WrapSamRecord
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
public WrapSamRecord(SAMRecord record){
this.mappingQuality=record.getMappingQuality();
this.isDuplicate=record.getDuplicateReadFlag();
this.readSequence=record.getReadString();
}