-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_splice_clips.c++
56 lines (46 loc) · 1.46 KB
/
remove_splice_clips.c++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
** Author: Nadia Davidson, [email protected]
** Modified:
**/
#include <iostream>
#include <numeric>
#include <SeqLib/BamReader.h>
#include <SeqLib/BamWriter.h>
#include <SeqLib/BWAWrapper.h>
using namespace std;
//static const int THREADS=8;
static const int MIN_TRANS_MAP_SC_LENGTH=12;
int main(int argc, char *argv[]){
std::string in_filename=argv[1];
std::string out_filename=argv[2];
std::string bwa_index=argv[3];
//Bam file reader
SeqLib::BamReader bw;
SeqLib::BamRecord read;
bw.Open(in_filename);
//open the output BAM
SeqLib::BamWriter writer; // or writer(SeqLib::SAM) or writer(SeqLib::CRAM)
writer.SetHeader(bw.Header());
writer.Open(out_filename);
//SeqLib::ThreadPool t(THREADS);
//writer.SetThreadPool(t);
writer.WriteHeader();
//open BWA Wrapper
SeqLib::BWAWrapper bwa;
bwa.LoadIndex(bwa_index);
while(bw.GetNextRecord(read)){
bool keep_read=true;
if(read.NumSoftClip()>=MIN_TRANS_MAP_SC_LENGTH){
SeqLib::BamRecordVector results;
bwa.AlignSequence(read.Sequence(), read.Qname(), results,false,1.0,0);
//cout << "Soft clipped:"<< r.NumSoftClip() << " ";
for(int a=0; a< results.size(); a++){
//cout << "Realigned: " << results[a].NumSoftClip() << " , " ;
if(results[a].NumSoftClip()<MIN_TRANS_MAP_SC_LENGTH) keep_read=false; //remove is alignment without softclip found
}
}
if(keep_read) writer.WriteRecord(read);
// cout << endl;
}
bw.Close();
}