-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmxRead.h
212 lines (144 loc) · 5.55 KB
/
dmxRead.h
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// ==========================================================================
// dmx
// ==========================================================================
// Copyright (c) 2012, Jay DePasse, University of Pittsburgh
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Knut Reinert or the FU Berlin nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: Jay DePasse <[email protected]>
// ==========================================================================
#ifndef SANDBOX_JVD_APPS_DMX_DMXREAD_H_
#define SANDBOX_JVD_APPS_DMX_DMXREAD_H_
#include <utility>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <fstream>
#include <stdint.h>
//#include <snappy.h>
//enum barcodeAssignmentType { BOTH, FWD, REV, NO_MATCH, MISMATCH } ;
#define BOTH 'B'
#define FWD 'F'
#define REV 'R'
#define NO_MATCH 'N'
#define MISMATCH 'M'
typedef char barcodeAssignmentType;
class dmxRead {
private:
short int fBCidx;
short int rBCidx;
barcodeAssignmentType descriptionCode;
unsigned readID;
/*
* groupSize is the number of reads that share barcode, random counter and random primer
* cluster size is the size of each of the clusters (based on remaining sequence) identified
* in the alignment of the group and then clustered based on kmer distribution
*/
uint16_t groupSize, clusterSize;
public:
/*
* Constructors, Destructor, clone methods
*/
dmxRead();
dmxRead * newClone();
dmxRead( barcodeAssignmentType _descriptionCode, std::string _tag, unsigned _readID );
/*
* Initialization/Set methods
*/
void fwd( int _fBCidx, std::string _fSeq );
void rev( int _rBCidx, std::string _rSeq );
void fwd( int _fBCidx, std::string _fSeq, std::string _fQual );
void rev( int _rBCidx, std::string _rSeq, std::string _rQual );
/*
* Access/Get methods
*/
barcodeAssignmentType getDescriptionCode() { return descriptionCode; }
std::string getDescription();
std::string getShortDescription();
void getDinucleotideFreqs( std::vector< double > & kmer );
void getDinucleotideFreqs( std::string s, std::vector< double > & kmer );
int getFwdBCidx() { return fBCidx; }
int getRevBCidx() { return rBCidx; }
int get_readID() { return readID; }
void setGroupSize( int _groupSize ) { groupSize = _groupSize; }
void setClusterSize( int _clusterSize ) { clusterSize = _clusterSize; }
/*
* Operators
*/
bool operator== ( dmxRead & other );
/*
* Printing and debugging
*/
void print();
void printFFasta( unsigned i, std::ofstream & fh );
void printRFasta( unsigned i, std::ofstream & fh );
void printFFastq( unsigned i, std::ofstream & fh );
void printRFastq( unsigned i, std::ofstream & fh );
void printFasta( unsigned i, std::ofstream & fh );
void printFastq( unsigned i, std::ofstream & fh );
//TODO Eventually all data members below should be private TODO//
std::string tag;
std::string fSeq, rSeq;
std::string fQual, rQual;
};
struct dmxReadCompare {
enum cmp { LT, EQ, GT };
bool operator() ( dmxRead * x, dmxRead * y ) const {
if ( x->getDescriptionCode() != y->getDescriptionCode() ) {
std::cout << "Trying to compare " << x->getDescriptionCode() << " to " << y->getDescriptionCode() << " in read sort." << std::endl;
}
cmp fCmp = EQ;
cmp rCmp = EQ;
if ( x->getDescriptionCode() != REV ) {
if ( x->getFwdBCidx() < y->getFwdBCidx() ) { fCmp = LT; }
else if ( x->getFwdBCidx() > y->getFwdBCidx() ) { fCmp = GT; }
}
if ( x->getDescriptionCode() != FWD ) {
if ( x->getRevBCidx() < y->getRevBCidx() ) { rCmp = LT; }
else if ( x->getRevBCidx() > y->getRevBCidx() ) { rCmp = GT; }
}
switch (fCmp) {
case LT:
return true;
case GT:
return false;
default:
switch (rCmp) {
case LT:
return true;
case EQ:
return x->tag < y->tag;
default:
return false;
}
return false;
}
}
};
#endif // #ifndef SANDBOX_JVD_APPS_DMX_DMXREAD_H_