-deal with offsets that can be -1
-added option to have "D"s inserted for deleted bases in pileup strings git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1635 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
01a9b1c63b
commit
a7c306f757
|
|
@ -37,13 +37,25 @@ abstract public class BasicPileup implements Pileup {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String baseWithStrandPileupAsString( List<SAMRecord> reads, List<Integer> offsets ) {
|
public static String baseWithStrandPileupAsString( List<SAMRecord> reads, List<Integer> offsets ) {
|
||||||
|
return baseWithStrandPileupAsString( reads, offsets, false );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String baseWithStrandPileupAsString( List<SAMRecord> reads, List<Integer> offsets, boolean includeDeletions ) {
|
||||||
StringBuilder bases = new StringBuilder();
|
StringBuilder bases = new StringBuilder();
|
||||||
|
|
||||||
for ( int i = 0; i < reads.size(); i++ ) {
|
for ( int i = 0; i < reads.size(); i++ ) {
|
||||||
SAMRecord read = reads.get(i);
|
SAMRecord read = reads.get(i);
|
||||||
int offset = offsets.get(i);
|
int offset = offsets.get(i);
|
||||||
|
|
||||||
char base = (char) read.getReadBases()[offset];
|
char base;
|
||||||
|
if ( offset == -1 ) {
|
||||||
|
if ( includeDeletions )
|
||||||
|
base = 'D';
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
base = (char) read.getReadBases()[offset];
|
||||||
|
}
|
||||||
|
|
||||||
base = Character.toUpperCase(base);
|
base = Character.toUpperCase(base);
|
||||||
if (read.getReadNegativeStrandFlag()) {
|
if (read.getReadNegativeStrandFlag()) {
|
||||||
|
|
@ -57,12 +69,21 @@ abstract public class BasicPileup implements Pileup {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Byte> basePileup( List<SAMRecord> reads, List<Integer> offsets ) {
|
public static ArrayList<Byte> basePileup( List<SAMRecord> reads, List<Integer> offsets ) {
|
||||||
|
return basePileup( reads, offsets, false );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<Byte> basePileup( List<SAMRecord> reads, List<Integer> offsets, boolean includeDeletions ) {
|
||||||
ArrayList<Byte> bases = new ArrayList<Byte>(reads.size());
|
ArrayList<Byte> bases = new ArrayList<Byte>(reads.size());
|
||||||
for ( int i = 0; i < reads.size(); i++ ) {
|
for ( int i = 0; i < reads.size(); i++ ) {
|
||||||
SAMRecord read = reads.get(i);
|
SAMRecord read = reads.get(i);
|
||||||
int offset = offsets.get(i);
|
int offset = offsets.get(i);
|
||||||
|
if ( offset == -1 ) {
|
||||||
|
if ( includeDeletions )
|
||||||
|
bases.add((byte)'D');
|
||||||
|
} else {
|
||||||
bases.add(read.getReadBases()[offset]);
|
bases.add(read.getReadBases()[offset]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return bases;
|
return bases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,6 +92,9 @@ abstract public class BasicPileup implements Pileup {
|
||||||
for ( int i = 0; i < reads.size(); i++ ) {
|
for ( int i = 0; i < reads.size(); i++ ) {
|
||||||
SAMRecord read = reads.get(i);
|
SAMRecord read = reads.get(i);
|
||||||
int offset = offsets.get(i);
|
int offset = offsets.get(i);
|
||||||
|
// skip deletion sites
|
||||||
|
if ( offset == -1 )
|
||||||
|
continue;
|
||||||
byte qual = (byte)read.getBaseQualities()[offset];
|
byte qual = (byte)read.getBaseQualities()[offset];
|
||||||
quals.add(qual);
|
quals.add(qual);
|
||||||
}
|
}
|
||||||
|
|
@ -117,7 +141,7 @@ abstract public class BasicPileup implements Pileup {
|
||||||
byte[] compressedQuals = (byte[]) read.getAttribute("SQ");
|
byte[] compressedQuals = (byte[]) read.getAttribute("SQ");
|
||||||
byte base2;
|
byte base2;
|
||||||
|
|
||||||
if (compressedQuals != null && compressedQuals.length == read.getReadLength()) {
|
if (offset != -1 && compressedQuals != null && compressedQuals.length == read.getReadLength()) {
|
||||||
base2 = (byte) BaseUtils.baseIndexToSimpleBase(QualityUtils.compressedQualityToBaseIndex(compressedQuals[offset]));
|
base2 = (byte) BaseUtils.baseIndexToSimpleBase(QualityUtils.compressedQualityToBaseIndex(compressedQuals[offset]));
|
||||||
hasAtLeastOneSQField = true;
|
hasAtLeastOneSQField = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -168,7 +192,7 @@ abstract public class BasicPileup implements Pileup {
|
||||||
|
|
||||||
byte[] compressedQuals = (byte[]) read.getAttribute("SQ");
|
byte[] compressedQuals = (byte[]) read.getAttribute("SQ");
|
||||||
byte qual2;
|
byte qual2;
|
||||||
if (compressedQuals != null) {
|
if (offset != -1 && compressedQuals != null) {
|
||||||
qual2 = QualityUtils.probToQual(QualityUtils.compressedQualityToProb(compressedQuals[offset]));
|
qual2 = QualityUtils.probToQual(QualityUtils.compressedQualityToProb(compressedQuals[offset]));
|
||||||
hasAtLeastOneSQField = true;
|
hasAtLeastOneSQField = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -201,6 +225,8 @@ abstract public class BasicPileup implements Pileup {
|
||||||
|
|
||||||
String bases = read.getReadString();
|
String bases = read.getReadString();
|
||||||
int offset = offsets.get(readIndex);
|
int offset = offsets.get(readIndex);
|
||||||
|
if ( offset == -1 )
|
||||||
|
continue;
|
||||||
|
|
||||||
int bestBaseIndex = BaseUtils.simpleBaseToBaseIndex(bases.charAt(offset));
|
int bestBaseIndex = BaseUtils.simpleBaseToBaseIndex(bases.charAt(offset));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ public class ReadBackedPileup extends BasicPileup {
|
||||||
char ref;
|
char ref;
|
||||||
List<SAMRecord> reads;
|
List<SAMRecord> reads;
|
||||||
List<Integer> offsets;
|
List<Integer> offsets;
|
||||||
|
boolean includeDeletions = false;
|
||||||
|
|
||||||
public ReadBackedPileup(char ref, AlignmentContext context ) {
|
public ReadBackedPileup(char ref, AlignmentContext context ) {
|
||||||
this(context.getLocation(), ref, context.getReads(), context.getOffsets());
|
this(context.getLocation(), ref, context.getReads(), context.getOffsets());
|
||||||
|
|
@ -37,6 +38,8 @@ public class ReadBackedPileup extends BasicPileup {
|
||||||
public List<SAMRecord> getReads() { return reads; }
|
public List<SAMRecord> getReads() { return reads; }
|
||||||
public List<Integer> getOffsets() { return offsets; }
|
public List<Integer> getOffsets() { return offsets; }
|
||||||
|
|
||||||
|
public void includeDeletionsInPileupString() { includeDeletions = true; }
|
||||||
|
|
||||||
public GenomeLoc getLocation() {
|
public GenomeLoc getLocation() {
|
||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
|
|
@ -84,6 +87,9 @@ public class ReadBackedPileup extends BasicPileup {
|
||||||
int[] counts = new int[4];
|
int[] counts = new int[4];
|
||||||
for (int i = 0; i < reads.size(); i++)
|
for (int i = 0; i < reads.size(); i++)
|
||||||
{
|
{
|
||||||
|
// skip deletion sites
|
||||||
|
if ( offsets.get(i) == -1 )
|
||||||
|
continue;
|
||||||
char base = Character.toUpperCase((char)(reads.get(i).getReadBases()[offsets.get(i)]));
|
char base = Character.toUpperCase((char)(reads.get(i).getReadBases()[offsets.get(i)]));
|
||||||
if (BaseUtils.simpleBaseToBaseIndex(base) == -1) { continue; }
|
if (BaseUtils.simpleBaseToBaseIndex(base) == -1) { continue; }
|
||||||
counts[BaseUtils.simpleBaseToBaseIndex(base)]++;
|
counts[BaseUtils.simpleBaseToBaseIndex(base)]++;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue