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(ifstream& flowFile, float signal, float noise, int maxHomoP){
21 m = MothurOut::getInstance();
32 flowFile >> seqName >> locationString >> lengthString >> flowString;
34 convert(lengthString.substr(7), seqLength);
35 convert(flowString.substr(9), numFlows);
37 flowData.resize(numFlows);
40 m->mothurOut("Error reading quality file, name blank at position, " + toString(flowFile.tellg()));
41 m->mothurOutEndLine();
44 seqName = seqName.substr(1);
45 for(int i=0;i<numFlows;i++) { flowFile >> flowData[i]; }
48 findDeadSpot(signal, noise, maxHomoP);
54 m->errorOut(e, "FlowData", "FlowData");
60 //**********************************************************************************************************************
62 void FlowData::findDeadSpot(float signalIntensity, float noiseIntensity, int maxHomoP){
66 float maxIntensity = (float) maxHomoP + 0.49;
69 while(currLength < seqLength + 4){
74 float intensity = flowData[i + 4 * deadSpot];
75 if(intensity > signalIntensity){
78 if(intensity < noiseIntensity || intensity > maxIntensity){
82 currLength += (int)(intensity+0.5);
85 if(noise > 0 || signal == 0){
92 seqLength = currLength;
96 m->errorOut(e, "FlowData", "findDeadSpot");
101 //**********************************************************************************************************************
103 void FlowData::translateFlow(){
107 for(int i=0;i<deadSpot;i++){
108 int intensity = (int)(flowData[i] + 0.5);
109 char base = baseFlow[i % 4];
111 for(int j=0;j<intensity;j++){
116 if(sequence.size() > 4){
117 sequence = sequence.substr(4);
123 catch(exception& e) {
124 m->errorOut(e, "FlowData", "translateFlow");
129 //**********************************************************************************************************************
131 void FlowData::capFlows(int maxFlows){
136 if(deadSpot > maxFlows){ deadSpot = maxFlows; }
139 catch(exception& e) {
140 m->errorOut(e, "FlowData", "capFlows");
145 //**********************************************************************************************************************
147 bool FlowData::hasMinFlows(int minFlows){
152 if(deadSpot >= minFlows){ pastMin = 1; }
155 catch(exception& e) {
156 m->errorOut(e, "FlowData", "hasMinFlows");
161 //**********************************************************************************************************************
163 Sequence FlowData::getSequence(){
166 return Sequence(seqName, sequence);
168 catch(exception& e) {
169 m->errorOut(e, "FlowData", "getSequence");
174 //**********************************************************************************************************************
176 int FlowData::getSeqLength(){
181 catch(exception& e) {
182 m->errorOut(e, "FlowData", "getSeqLength");
187 //**********************************************************************************************************************
189 void FlowData::printFlows(ofstream& outFlowFile){
191 // outFlowFile << '>' << seqName << locationString << " length=" << seqLength << " numflows=" << maxFlows << endl;
192 outFlowFile << seqName << ' ' << deadSpot << ' ' << setprecision(2);
194 for(int i=0;i<numFlows;i++){
195 outFlowFile << flowData[i] << ' ';
199 catch(exception& e) {
200 m->errorOut(e, "FlowData", "printFlows");
205 //**********************************************************************************************************************
207 void FlowData::printFlows(ofstream& outFlowFile, string scrapCode){
210 // outFlowFile << '>' << seqName << locationString << " length=" << seqLength << " numflows=" << maxFlows << endl;
212 outFlowFile << seqName << '|' << scrapCode << ' ' << deadSpot << ' ' << setprecision(2);
214 for(int i=0;i<numFlows;i++){
215 outFlowFile << flowData[i] << ' ';
219 catch(exception& e) {
220 m->errorOut(e, "FlowData", "printFlows");
225 //**********************************************************************************************************************
227 void FlowData::printFASTA(ofstream& outFASTA){
230 outFASTA << '>' << seqName << endl;
231 outFASTA << sequence << endl;
234 catch(exception& e) {
235 m->errorOut(e, "FlowData", "printFlows");
241 //**********************************************************************************************************************