5 * Created by Pat Schloss on 12/22/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
12 //**********************************************************************************************************************
14 FlowData::FlowData(){}
16 //**********************************************************************************************************************
18 FlowData::~FlowData(){ /* do nothing */ }
20 //**********************************************************************************************************************
22 FlowData::FlowData(int numFlows, float signal, float noise, int maxHomoP, string baseFlow) :
23 numFlows(numFlows), signalIntensity(signal), noiseIntensity(noise), maxHomoP(maxHomoP), baseFlow(baseFlow){
26 m = MothurOut::getInstance();
28 flowData.assign(numFlows, 0);
34 m->errorOut(e, "FlowData", "FlowData");
40 //**********************************************************************************************************************
42 bool FlowData::getNext(ifstream& flowFile){
45 seqName = getSequenceName(flowFile);
46 if (m->debug) { m->mothurOut("[DEBUG]: flow = " + seqName + " "); }
48 if (m->debug) { m->mothurOut(toString(endFlow) + " "); }
49 if (!m->control_pressed) {
50 if (m->debug) { m->mothurOut(" "); }
51 for(int i=0;i<numFlows;i++) {
52 flowFile >> flowData[i];
53 if (m->debug) { m->mothurOut(toString(flowData[i]) + " "); }
55 if (m->debug) { m->mothurOut("\n"); }
61 if(flowFile){ return 1; }
65 m->errorOut(e, "FlowData", "getNext");
70 //********************************************************************************************************************
71 string FlowData::getSequenceName(ifstream& flowFile) {
77 if (name.length() != 0) {
79 }else{ m->mothurOut("Error in reading your flowfile, at position " + toString(flowFile.tellg()) + ". Blank name."); m->mothurOutEndLine(); m->control_pressed = true; }
84 m->errorOut(e, "FlowData", "getSequenceName");
89 //**********************************************************************************************************************
91 void FlowData::updateEndFlow(){
94 if (baseFlow.length() > 4) { return; }
97 float maxIntensity = (float) maxHomoP + 0.49;
101 while(deadSpot < endFlow){
105 for(int i=0;i<baseFlow.length();i++){
106 float intensity = flowData[i + deadSpot];
107 if(intensity > signalIntensity){
110 if(intensity < noiseIntensity || intensity > maxIntensity){
116 if(noise > 0 || signal == 0){
120 deadSpot += baseFlow.length();
125 catch(exception& e) {
126 m->errorOut(e, "FlowData", "findDeadSpot");
131 //**********************************************************************************************************************
134 //then the second positive flow is for a T, but you saw a T between the last and previous flow adn it wasn't positive, so something is missing
136 void FlowData::translateFlow(){
139 set<char> charInMiddle;
141 bool updateOld = false;
143 for(int i=0;i<endFlow;i++){
144 int intensity = (int)(flowData[i] + 0.5);
145 char base = baseFlow[i % baseFlow.length()];
147 if (intensity == 0) { //are we in the middle
148 if (oldspot != -1) { charInMiddle.insert(base); }
149 }else if (intensity >= 1) {
150 if (oldspot == -1) { updateOld = true; }
151 else { //check for bases inbetween two 1's
152 if (charInMiddle.count(base) != 0) { //we want to covert to an N
153 sequence = sequence.substr(0, oldspot+1);
157 charInMiddle.clear();
161 for(int j=0;j<intensity;j++){
165 if (updateOld) { oldspot = sequence.length()-1; updateOld = false; }
168 if(sequence.size() > 4){
169 sequence = sequence.substr(4);
175 catch(exception& e) {
176 m->errorOut(e, "FlowData", "translateFlow");
181 //**********************************************************************************************************************
183 void FlowData::capFlows(int mF){
188 if(endFlow > maxFlows){ endFlow = maxFlows; }
192 catch(exception& e) {
193 m->errorOut(e, "FlowData", "capFlows");
198 //**********************************************************************************************************************
200 bool FlowData::hasGoodHomoP(){
204 float maxIntensity = (float) maxHomoP + 0.49;
206 for(int i=0;i<endFlow;i++){
207 if(flowData[i] > maxIntensity){
213 catch(exception& e) {
214 m->errorOut(e, "FlowData", "hasMinFlows");
219 //**********************************************************************************************************************
221 bool FlowData::hasMinFlows(int minFlows){
225 if(endFlow >= minFlows){ pastMin = 1; }
229 catch(exception& e) {
230 m->errorOut(e, "FlowData", "hasMinFlows");
235 //**********************************************************************************************************************
237 Sequence FlowData::getSequence(){
240 return Sequence(seqName, sequence);
242 catch(exception& e) {
243 m->errorOut(e, "FlowData", "getSequence");
248 //**********************************************************************************************************************
250 void FlowData::printFlows(ofstream& outFlowFile){
252 // outFlowFile << '>' << seqName << locationString << " length=" << seqLength << " numflows=" << maxFlows << endl;
253 outFlowFile << seqName << ' ' << endFlow << ' ' << setprecision(2);
255 for(int i=0;i<maxFlows;i++){
256 outFlowFile << flowData[i] << ' ';
260 catch(exception& e) {
261 m->errorOut(e, "FlowData", "printFlows");
266 //**********************************************************************************************************************
268 void FlowData::printFlows(ofstream& outFlowFile, string scrapCode){
270 outFlowFile << seqName << '|' << scrapCode << ' ' << endFlow << ' ' << setprecision(2);
272 for(int i=0;i<numFlows;i++){
273 outFlowFile << flowData[i] << ' ';
277 catch(exception& e) {
278 m->errorOut(e, "FlowData", "printFlows");
283 //**********************************************************************************************************************
285 string FlowData::getName(){
290 catch(exception& e) {
291 m->errorOut(e, "FlowData", "getName");
296 //**********************************************************************************************************************