本文整理汇总了Java中net.sf.samtools.SAMRecord.getReferenceName方法的典型用法代码示例。如果您正苦于以下问题:Java SAMRecord.getReferenceName方法的具体用法?Java SAMRecord.getReferenceName怎么用?Java SAMRecord.getReferenceName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.samtools.SAMRecord
的用法示例。
在下文中一共展示了SAMRecord.getReferenceName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processOneUnalignedRecord
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
/**
* Converts a SAM record into a bed entry and outputs it straight away
*
* @param record
*/
private void processOneUnalignedRecord(SAMRecord record) {
// output the alignment positions into a bed file
int start = record.getAlignmentStart() - 1;
int end = start + record.getReadLength();
String out = record.getReferenceName() + "\t" + start + "\t" + end + "\n";
synchronized (outunaligned) {
try {
outunaligned.write(out.getBytes());
} catch (Exception ex) {
System.out.println("Exception writing unaligned bed: " + ex.getMessage());
}
}
// create a dummy thesaurus entry
ThesaurusEntry entry = new ThesaurusEntry(record, ginfo);
// complete it (need to fix alignment end manually, then use function to get anchors set right)
entry.alignEnd = entry.originEnd;
completeThesaurusEntry(entry, record);
// set the origin chromosome to -1 to signal unaligned setup
entry.originChrIndex = -1;
outputThesaurusEntry(entry, outstreams.get(entry.getAlignChr()));
}
示例2: splitIntoChroms
import net.sf.samtools.SAMRecord; //导入方法依赖的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();
}
示例3: SequenceRead
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
public SequenceRead(SAMRecord record) {
super(record.getAlignmentStart(), record.getAlignmentEnd());
this.chr = record.getReferenceName();
if (record.getReadNegativeStrandFlag()) {
strand = Strand.NEGATIVE;
} else {
strand = Strand.POSITIVE;
}
this.readBases = record.getReadBases();
this.qualities = record.getBaseQualities();
this.alignmentBlocks = record.getAlignmentBlocks();
}
示例4: 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;
}
示例5: 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;
}
示例6: SingleEndAlignment
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
public SingleEndAlignment(SAMRecord read) {
super(read.getReferenceName(), read.getAlignmentStart()-1, read.getAlignmentStart()); //This is a dummy setup
parseCigar(read.getCigarString(), read.getReferenceName(), read.getAlignmentStart()-1);
long startT = System.nanoTime();
setName(read.getReadName());
long cTime = System.nanoTime() - startT;
cTime = Math.round(cTime/(double)1000000);
if(cTime > 50) {
logger.debug("parse set read name took " + cTime);
}
startT = System.nanoTime();
if (read.getReadNegativeStrandFlag())
setOrientation(Strand.NEGATIVE);
else
setOrientation(Strand.POSITIVE);
cTime = System.nanoTime() - startT;
cTime = Math.round(cTime/(double)1000000);
if(cTime > 50) {
logger.debug("Set orientation took " + cTime);
}
startT = System.nanoTime();
try {
record = (SAMRecord) read.clone();
} catch (CloneNotSupportedException e) {
logger.warn("Caught exception on record " + read.getReadName());
e.printStackTrace();
}
//record=new WrapSamRecord(read);
assert(read.getAlignmentEnd() == getEnd()); // sanity check
cTime = System.nanoTime() - startT;
cTime = Math.round(cTime/(double)1000000);
if(cTime > 50) {
logger.debug("Cloning object took " + cTime);
}
}
示例7: isCompatiblePair
import net.sf.samtools.SAMRecord; //导入方法依赖的package包/类
private boolean isCompatiblePair(SAMRecord r1, SAMRecord r2) {
if(r1.getReferenceName()==r2.getReferenceName()){
if((r1.getAlignmentStart()==r2.getMateAlignmentStart())&& (r1.getMateAlignmentStart()==r2.getAlignmentStart())){
if(r1.getMateNegativeStrandFlag()==r2.getReadNegativeStrandFlag() && r1.getReadNegativeStrandFlag()==r2.getMateNegativeStrandFlag()){
if(r1.getMateReferenceName().equalsIgnoreCase(r2.getReferenceName()) && r2.getMateReferenceName().equalsIgnoreCase(r1.getReferenceName())){
return true;
}
}
}
}
return false;
}
示例8: 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;
}