-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfasta_random_sample.cpp
68 lines (50 loc) · 1.58 KB
/
fasta_random_sample.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
/*
* Copyright (C) 2009-2012 Simon A. Berger
*
* This file is part of papara.
*
* papara 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.
*
* papara 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.
*
* You should have received a copy of the GNU General Public License
* along with papara. If not, see <http://www.gnu.org/licenses/>.
*/
// just a test if i can write this faster in c++ than in ruby (I always forget half of the ruby syntax and hate to look up the details again and again...)
#include <iostream>
#include <cstdlib>
int main( int argc, char *argv[] ) {
std::string line;
bool fixed_number = false;
size_t num = 0;
double p;
if( argc > 1 ) {
p = atof(argv[1]);
if( p < 0 ) {
std::cerr << "bad p: " << p << "\n";
}
num = size_t(p);
fixed_number = p >= 1.0;
} else {
p = 0.1;
}
bool is_on = false;
while( !std::cin.eof() ) {
line.clear();
std::getline( std::cin, line );
if( line.size() > 0 ) {
if( line[0] == '>' ) {
is_on = (std::rand() / float(RAND_MAX)) < p;
}
}
if( is_on ) {
std::cout << line << "\n";
}
}
}