File: SWMain.cpp

package info (click to toggle)
libsmithwaterman 0.0+git20160702.2610e25-11
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 296 kB
  • sloc: cpp: 2,115; makefile: 59; sh: 16
file content (126 lines) | stat: -rw-r--r-- 4,811 bytes parent folder | download | duplicates (5)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <iostream>
#include <string.h>
//#include "Alignment.h"
//#include "Benchmark.h"
//#include "HashRegion.h"
#include "SmithWatermanGotoh.h"
#include "BandedSmithWaterman.h"

using namespace std;

int main(int argc, char* argv[]) {
/*
	printf("------------------------------------------------------------------------------\n");
	printf("Banded Smith-Waterman Algorithm (worst case)\n");
	printf("Michael Stromberg & Wan-Ping Lee  Marth Lab, Boston College Biology Department\n");
	printf("------------------------------------------------------------------------------\n\n");
*/
	// this version simulates the worst case of only a fragment hashing to the
	// reference sequence. Basically a non-centered diagonal in the Smith-Waterman
	// dynamic programming matrix.

	// here we simulate a region on the reference that occurs between position 4001
	// and position 4136. During hashing, only the first 20 bases in the query 
	// matched perfectly.

	// define the start and end coordinates of the entire reference region
	//const unsigned int start = 4001;
	//const unsigned int end   = 4136;

	//const unsigned int testStart = atoi(argv[1]);
	//const unsigned int testEnd = atoi(argv[2]);
	//const unsigned int testQueryStart = atoi(argv[3]);
	//const unsigned int testQueryEnd = atoi(argv[4]);
	
	//cout << endl<< "=====================================================" << endl;
	//cout << testStart << "\t" << testQueryStart << endl;
	
	// define the 20 b:q
	// ases that matched perfectly
	//HashRegion hr;
	
	//=====================================================
	// defind the hash region
	// first.first:   reference begin
	// first.second:  reference end
	// second.first:  query begin
	// second.second: query end
	//=====================================================
	
	pair< pair<unsigned int, unsigned int>, pair<unsigned int, unsigned int> > hr;
	hr.first.first   = 5;
	hr.first.second  = 13;
	hr.second.first  = 0;
	hr.second.second = 8;

	//=====================================================

	// for 76 bp reads, we expect as much as 12 mismatches - however this does not
	// translate to a bandwidth of 12 * 2 + 1 since most of these will be
	// substitution errors
	const unsigned char bandwidth = 11;

	// initialize
	const char* pReference = "ATGGCGGGGATCGGGACACTCGCCGGTGCGGGTACCCTA";
	const char* pQuery     =      "GGGGATCGGGACACTCGCTCTCCGGTGCGGGTA";
	
	const unsigned int referenceLen = strlen(pReference);
	const unsigned int queryLen     = strlen(pQuery);

	// ==============================================================================================
	// benchmarking reference on koi.bc.edu when NUM_ITERATIONS = 38000 on 76 bp read (1 try):
	// CPU time: 23.920 s, wall time: 24.012 s (1582.6 alignments/s)
	// ==============================================================================================
	//const unsigned int NUM_ITERATIONS = 38000;
	//unsigned int NUM_ITERATIONS = 1;

	// create a new Smith-Waterman alignment object
	CSmithWatermanGotoh sw(10.0f, -9.0f, 15.0f, 6.66f);
	CBandedSmithWaterman bsw(10.0f, -9.0f, 15.0f, 6.66f, bandwidth);

	// start timing the algorithm
	//CBenchmark bench;
	//bench.Start();

	// perform NUM_ITERATIONS alignments
	//Alignment bswAl;
	//Alignment swAl;
	//   referenceBegin, referenceEnd
	unsigned int referenceSW, referenceBSW;
	string cigarSW, cigarBSW;
	//for(unsigned int i = 0; i < NUM_ITERATIONS; i++) {
	  sw.Align(referenceSW, cigarSW, pReference, referenceLen, pQuery, queryLen);
	  bsw.Align(referenceBSW, cigarBSW, pReference, referenceLen, pQuery, queryLen, hr);
	//}

	// stop timing the algorithm
	//bench.Stop();
	
	// calculate the alignments per second
	//double elapsedWallTime = bench.GetElapsedWallTime();
	//double alignmentsPerSecond = (double)NUM_ITERATIONS / elapsedWallTime;
	
	// show our results
	//printf("%d\t%d\n", al.ReferenceBegin,al.QueryBegin);

	printf("Smith-Waterman\n");
	printf("reference:    %s %3u\n", cigarSW.c_str(), referenceSW);
	printf("Banded Smith-Waterman\n");
	printf("reference:    %s %3u\n", cigarBSW.c_str(), referenceBSW);
	/*  
	printf("Smith-Waterman\n");
	printf("reference:    %s %3u %3u\n", swAl.Reference.CData(), swAl.ReferenceBegin, swAl.ReferenceEnd);
        printf("query:        %s %3u %3u\n", swAl.Query.CData(), swAl.QueryBegin, swAl.QueryEnd);
        printf("mismatches:   %u\n", swAl.NumMismatches);
	printf("\n");	
	printf("Banded Smith-Waterman\n");
	printf("reference:    %s %3u %3u\n", bswAl.Reference.CData(), bswAl.ReferenceBegin, bswAl.ReferenceEnd);
        printf("query:        %s %3u %3u\n", bswAl.Query.CData(), bswAl.QueryBegin, bswAl.QueryEnd);
        printf("mismatches:   %u\n", bswAl.NumMismatches);
	*/
	//printf("alignments/s: %.1f\n\n", alignmentsPerSecond);

	//bench.DisplayTime("BandedSmithWaterman");

	return 0;
}