Skip to content

Commit

Permalink
fix for #49
Browse files Browse the repository at this point in the history
  • Loading branch information
evantarbell committed Mar 3, 2020
1 parent d5194a6 commit ca552fb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/main/java/HMMR_ATAC/Main_HMMR_Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public class Main_HMMR_Driver {
/*
* Version number. Change as needed
*/
private static String versionNum = "1.2.9";
private static String versionNum = "1.2.10";

@SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException {
Expand Down
70 changes: 41 additions & 29 deletions src/main/java/WigMath/pileup.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.commons.math3.distribution.NormalDistribution;

import net.sf.samtools.SAMFileReader;
import net.sf.samtools.SAMFormatException;
import net.sf.samtools.SAMRecord;
import net.sf.samtools.util.CloseableIterator;
import FormatConverters.PileupToBedGraph;
Expand Down Expand Up @@ -224,38 +225,49 @@ public double[] makeBlock(TagNode t){
SAMFileReader reader = new SAMFileReader(input,index);
CloseableIterator<SAMRecord> iter = reader.query(t.getChrom(), t.getStart(),
t.getStop(), false);

while (iter.hasNext()){
SAMRecord record = iter.next();
if(!record.getReadUnmappedFlag() && !record.getMateUnmappedFlag()
&& record.getMappingQuality()>=minMapQ &&
!(record.getDuplicateReadFlag() && rmDup)
&& Math.abs(record.getInferredInsertSize()) <= 1000 && record.getInferredInsertSize() != 0) {
int readStart = record.getAlignmentStart();
int readStop = record.getAlignmentEnd();
// int readStop= record.getAlignmentStart() + record.getInferredInsertSize() - 1;
// if (record.getInferredInsertSize() < 0 ) {
// readStart = record.getAlignmentEnd() + record.getInferredInsertSize() + 1;
// readStop = record.getAlignmentEnd();
// }

cpmScale++;
if (readStart < t.getStart()){
readStart = t.getStart();
}
if (readStop < t.getStart()){
readStop = t.getStart();
}
if (readStop >= t.getStop()){
readStop = t.getStop()-1;
}
if (readStart >= t.getStop()){
readStart = t.getStop()-1;
SAMRecord record = null;
try{
record = iter.next();
}
catch(SAMFormatException ex){
System.out.println("SAM Record is problematic. Has mapQ != 0 for unmapped read. Will continue anyway");
}
if(record != null){
if (!record.getReadUnmappedFlag()
&& !record.getMateUnmappedFlag()
&& record.getMappingQuality() >= minMapQ
&& !(record.getDuplicateReadFlag() && rmDup)
&& Math.abs(record.getInferredInsertSize()) <= 1000
&& record.getInferredInsertSize() != 0) {
int readStart = record.getAlignmentStart();
int readStop = record.getAlignmentEnd();
// int readStop= record.getAlignmentStart() + record.getInferredInsertSize() - 1;
// if (record.getInferredInsertSize() < 0 ) {
// readStart = record.getAlignmentEnd() + record.getInferredInsertSize() + 1;
// readStop = record.getAlignmentEnd();
// }

cpmScale++;
if (readStart < t.getStart()) {
readStart = t.getStart();
}
if (readStop < t.getStart()) {
readStop = t.getStart();
}
if (readStop >= t.getStop()) {
readStop = t.getStop() - 1;
}
if (readStart >= t.getStop()) {
readStart = t.getStop() - 1;
}
temp[readStart - t.getStart()]++;
temp[readStop - t.getStart()]--;

}
temp[readStart - t.getStart()]++;
temp[readStop - t.getStart()]--;


}

}
iter.close();
reader.close();
Expand Down

0 comments on commit ca552fb

Please sign in to comment.