-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditDist.cpp
67 lines (51 loc) · 1.37 KB
/
editDist.cpp
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
56
57
58
59
60
61
62
63
64
65
66
/*
* failQualPair
* Date: Oct-10-2012
* Author : Gabriel Renaud gabriel.reno [at sign here ] gmail.com
*
*/
#include <iostream>
#include "api/BamMultiReader.h"
#include "api/BamReader.h"
#include "api/BamWriter.h"
#include "api/BamAux.h"
#include "libgab.h"
using namespace std;
using namespace BamTools;
int main (int argc, char *argv[]) {
if( (argc== 1) ||
(argc== 2 && string(argv[1]) == "-h") ||
(argc== 2 && string(argv[1]) == "-help") ||
(argc== 2 && string(argv[1]) == "--help") ){
cout<<"Usage:editDist [in bam]"<<endl<<"this program returns the NM field of all aligned reads"<<endl;
return 1;
}
string bamfiletopen = string(argv[1]);
// cout<<bamfiletopen<<endl;
BamReader reader;
// cout<<"ok"<<endl;
if ( !reader.Open(bamfiletopen) ) {
cerr << "Could not open input BAM files." << endl;
return 1;
}
BamAlignment al;
// cout<<"ok"<<endl;
while ( reader.GetNextAlignment(al) ) {
// cout<<al.Name<<endl;
if(!al.IsMapped())
continue;
if(al.HasTag("NM") ){
int editDist;
if(al.GetTag("NM",editDist) ){
cout<<editDist<<endl;
}else{
cerr<<"Cannot retrieve NM field for "<<al.Name<<endl;
return 1;
}
}else{
cerr<<"Warning: read "<<al.Name<<" is aligned but has no NM field"<<endl;
}
} //while al
reader.Close();
return 0;
}