-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreadspam.cpp
157 lines (150 loc) · 4.36 KB
/
readspam.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details at
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include <iostream>
#include <stdlib.h>
#include <getopt.h>
#include <iomanip>
#include "Sequence.h"
#include "Seed.h"
void printHelp(){
std::string help =
"\nUsage: ./fswm [options] <filelist>"
"\n"
"\nformat:"
"\n\t <filelist>:"
"\n\t A plain text file, specifying the relative path to each input dataset."
"\n\t To create the filelist simply run:"
"\n\t ls ./path/to/input/* > filelist "
"\n\t (assuming all your proteome files (*.fasta, *.faa, etc.) are stored in the input-folder.)"
"\n\t Sequence must be in FASTA format. Each genome must be in its own FASTA file."
"\n\t There can be multiple header in each FASTA file"
"\n\t >Gene1"
"\n\t ATAGTAGATGAT.."
"\n\t >Contig2"
"\n\t ATAGTAGATGAT.."
"\n\t >Contig3"
"\n\t ATGATGATGATGATG.."
"\n\t .."
"\n\t "
"\nOptions:"
"\n\t -h: print this help and exit"
"\n\t -k <integer>: pattern weight (default 12)"
"\n\t -l <integer>: don't care positions (default 100)"
"\n\t -t <integer>: numer of threads (default: 10)"
"\n\t -s <integer>: the minimum score of a spaced-word match to be considered homologous (default: 0)"
"\n";
std::cout << help << std::endl;
}
int weight = 12;
int dontCare = 100;
int threads = 10;
int threshold = 0;
void parseParameters(int argc, char *argv[]){
int option_char;
while ((option_char = getopt (argc, argv, "l:k:t:hs:")) != -1){
switch (option_char){
case 's':
threshold = atoi (optarg);
break;
case 'l':
dontCare = atoi (optarg);
break;
case 'k':
weight = atoi (optarg);
if(weight<8 || weight > 16){
std::cerr << "Weight (-k) must be between 8 and 16"<< std::endl;
exit (EXIT_FAILURE);
}
break;
case 't':
threads = atoi (optarg);
if(threads<1){
std::cerr << "threads (-t) must be an integer larger than 0"<< std::endl;
exit (EXIT_FAILURE);
}
break;
case 'h':
printHelp();
exit (EXIT_SUCCESS);
break;
case '?':
printHelp();
exit (EXIT_FAILURE);
}
}
}
void writeDmat(std::vector<std::vector<double> > dmat, std::vector<Sequence>& sequences){
std::cout << sequences.size() << std::endl;
for (int i = 0; i < sequences.size(); i++)
{
std::string name = sequences[i].getHeader();
for(int k = 0; k < 10; k++){
if(k >= name.length())
std::cout << " ";
else
std::cout << name[k];
}
for (int j = 0; j < sequences.size(); j++)
{
if (i > j)
std::cout << std::fixed <<std::setprecision(12) << dmat[i][j] << " ";
else if(j>i)
std::cout << std::fixed<< std::setprecision(12) << dmat[j][i] << " ";
else
std::cout << std::setprecision(12) << "0" << " ";
}
std::cout << std::endl;
}
}
int main(int argc, char *argv[]){
if(argc < 2)
{
printHelp();
exit (EXIT_FAILURE);
}
parseParameters(argc, argv);
std::string list(argv[argc-1]);
Seed seed(weight,dontCare);
std::vector<Sequence> sequences = Sequence::read(list);
std::vector<std::vector<double> >DMat(sequences.size(), std::vector<double>(sequences.size(),0));
Seed::init();
omp_set_dynamic(0);
omp_set_num_threads(threads);
if(sequences.size() < 2){
std::cerr << "there must be at least 2 sequences"<< std::endl;
exit (EXIT_FAILURE);
}
#pragma omp parallel for schedule(runtime)
for(int i = 0; i < sequences.size();i++)
{
sequences[i].sortFirstBits(seed);
sequences[i].sortFirstBitsRev(seed);
}
for(int i = 0; i < sequences.size(); i++)
{
sequences[i].sortNextBits(seed);
sequences[i].sortNextBitsRev(seed);
}
int number = (sequences.size()*(sequences.size()-1))/2;
int cnt = 1;
for(int i = 0; i < sequences.size(); i++)
{
for(int j = i + 1; j < sequences.size(); j++)
{
DMat[i][j] = sequences[i].compareSequences(sequences[j], seed, threads, threshold);
DMat[j][i] = DMat[i][j];
}
}
writeDmat(DMat, sequences);
}