-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuniqueseqs.cpp
executable file
·87 lines (62 loc) · 2.17 KB
/
uniqueseqs.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
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <algorithm>
using namespace std ;
// Comparison; not case sensitive.
bool compareNoCase (string first, string second)
{
int i=0;
while ((i < first.length()) && (i < second.length()))
{
if (tolower (first[i]) < tolower (second[i])) return true;
else if (tolower (first[i]) > tolower (second[i])) return false;
i++;
}
if (first.length() < second.length()) return true;
else return false;
}
int main ()
{
///////////////////////////////////////////////////////////////////////////////////
// Declaration of variables
ifstream ifile ;
ofstream ofile ;
string line ;
vector <string> dnaseq ;
///////////////////////////////////////////////////////////////////////////////////
// Opens all necessary files.
ifile.open("out");
ofile.open("unique.txt") ;
///////////////////////////////////////////////////////////////////////////////////
// Takes all data from in file, reads it line by line and puts each line into a
// vector element.
int size = 209 ;
// Modify this size according to what type of data you want to extract from the file.
while( ifile >> line )
{
if( line > size)
{
//cout << line << endl ;
dnaseq.push_back(line) ;
}
}
///////////////////////////////////////////////////////////////////////////////////
// Sorts all vector elements alphabetically, puts duplicate elements at the end of
//the vector list and erases them.
sort( dnaseq.begin(), dnaseq.end(), compareNoCase );
dnaseq.erase( unique( dnaseq.begin(), dnaseq.end() ) , dnaseq.end());
///////////////////////////////////////////////////////////////////////////////////
// Outputs vector contents into a new file.
for( int i = 0 ; i < dnaseq.size() ; i++ )
{
ofile << dnaseq[i] << endl ;
}
///////////////////////////////////////////////////////////////////////////////////
// Closes all necessary files.
ifile.close() ;
ofile.close() ;
///////////////////////////////////////////////////////////////////////////////////
return 0 ;
}