String bam_file = "/data/kimjh/WGS/simulation_test_chr1/seperate_10p/chr1_sim_70x_sorted_rmdup.bam";
String bam_index_file = "/data/kimjh/WGS/simulation_test_chr1/seperate_10p/chr1_sim_70x_sorted_rmdup.bam.bai";
File bam = new File(bam_file);
File bam_index = new File(bam_index_file);
SAMFileReader samReader = new SAMFileReader(bam, bam_index);
String chr_id = "chr1";
int start = 1;
int end = 20;
// int end = 247199724;
Interval interval = new Interval(chr_id, start, end);
IntervalList il = new IntervalList(samReader.getFileHeader());
il.add(interval);
SamLocusIterator sli = new SamLocusIterator(samReader, il, true);
FileWriter fw = new FileWriter("/data/kimjh/WGS/simulation_test_chr1/seperate_10p/gatk/depth_diff.txt");
BufferedWriter bw = new BufferedWriter(fw);
for (Iterator<SamLocusIterator.LocusInfo> iter = sli.iterator(); iter.hasNext();) {
SamLocusIterator.LocusInfo locusInfo = iter.next();
List recordList = locusInfo.getRecordAndPositions();
Iterator it = recordList.iterator();
String readBase = "";
String baseQuality = "";
while(it.hasNext()){
SamLocusIterator.RecordAndOffset record = (SamLocusIterator.RecordAndOffset) it.next();
if(baseQuality.equals("")){
// readBase += Byte.toString(record.getReadBase());
// baseQuality += record.getBaseQuality();
readBase += (char)(record.getReadBase()&0xff);
baseQuality += (int)((record.getBaseQuality()));
}else{
readBase += ","+(char)(record.getReadBase()&0xff);
baseQuality += ","+(int)((record.getBaseQuality()));
}
}
System.out.println("chr1\t"+locusInfo.getPosition()+"\t"+locusInfo.getRecordAndPositions().size()+"\t"+readBase+"\t"+baseQuality+"\n");
// bw.write("chr1\t"+locusInfo.getPosition()+"\t"+locusInfo.getRecordAndPositions().size()+"\n");
int pos = locusInfo.getPosition();
int size = locusInfo.getRecordAndPositions().size();
if (temp != null) {
t = temp.split("\t");
int sam_pos = Integer.parseInt(t[1]);
int sam_size = Integer.parseInt(t[2]);
while (sam_pos <= pos && temp != null) {
t = temp.split("\t");
sam_pos = Integer.parseInt(t[1]);
sam_size = Integer.parseInt(t[2]);
if (sam_pos == pos) {
if (sam_size != size) {
if(pos%1000000==0){
System.out.println(pos);
}
bw.write(pos + "\t" + size + "\t" + sam_size + "\n");
}
temp = br.readLine();
} else if(sam_pos>pos){
}else{
temp = br.readLine();
}
}
}
}
br.close();
fr.close();
bw.flush();
bw.close();
fw.close();
sli.close();
samReader.close();
}