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);
47 if (!m->control_pressed) {
48 for(int i=0;i<numFlows;i++) { flowFile >> flowData[i]; }
54 if(flowFile){ return 1; }
58 m->errorOut(e, "FlowData", "getNext");
63 //********************************************************************************************************************
64 string FlowData::getSequenceName(ifstream& flowFile) {
70 if (name.length() != 0) {
71 for (int i = 0; i < name.length(); i++) {
72 if (name[i] == ':') { name[i] = '_'; m->changedSeqNames = true; }
74 }else{ m->mothurOut("Error in reading your flowfile, at position " + toString(flowFile.tellg()) + ". Blank name."); m->mothurOutEndLine(); m->control_pressed = true; }
79 m->errorOut(e, "FlowData", "getSequenceName");
84 //**********************************************************************************************************************
86 void FlowData::updateEndFlow(){
89 if (baseFlow.length() > 4) { return; }
92 float maxIntensity = (float) maxHomoP + 0.49;
96 while(deadSpot < endFlow){
100 for(int i=0;i<baseFlow.length();i++){
101 float intensity = flowData[i + deadSpot];
102 if(intensity > signalIntensity){
105 if(intensity < noiseIntensity || intensity > maxIntensity){
111 if(noise > 0 || signal == 0){
115 deadSpot += baseFlow.length();
120 catch(exception& e) {
121 m->errorOut(e, "FlowData", "findDeadSpot");
126 //**********************************************************************************************************************
128 void FlowData::translateFlow(){
132 for(int i=0;i<endFlow;i++){
133 int intensity = (int)(flowData[i] + 0.5);
134 char base = baseFlow[i % baseFlow.length()];
136 for(int j=0;j<intensity;j++){
141 if(sequence.size() > 4){
142 sequence = sequence.substr(4);
148 catch(exception& e) {
149 m->errorOut(e, "FlowData", "translateFlow");
154 //**********************************************************************************************************************
156 void FlowData::capFlows(int mF){
161 if(endFlow > maxFlows){ endFlow = maxFlows; }
165 catch(exception& e) {
166 m->errorOut(e, "FlowData", "capFlows");
171 //**********************************************************************************************************************
173 bool FlowData::hasMinFlows(int minFlows){
177 if(endFlow >= minFlows){ pastMin = 1; }
181 catch(exception& e) {
182 m->errorOut(e, "FlowData", "hasMinFlows");
187 //**********************************************************************************************************************
189 Sequence FlowData::getSequence(){
192 return Sequence(seqName, sequence);
194 catch(exception& e) {
195 m->errorOut(e, "FlowData", "getSequence");
200 //**********************************************************************************************************************
202 void FlowData::printFlows(ofstream& outFlowFile){
204 // outFlowFile << '>' << seqName << locationString << " length=" << seqLength << " numflows=" << maxFlows << endl;
205 outFlowFile << seqName << ' ' << endFlow << ' ' << setprecision(2);
207 for(int i=0;i<maxFlows;i++){
208 outFlowFile << flowData[i] << ' ';
212 catch(exception& e) {
213 m->errorOut(e, "FlowData", "printFlows");
218 //**********************************************************************************************************************
220 void FlowData::printFlows(ofstream& outFlowFile, string scrapCode){
222 outFlowFile << seqName << '|' << scrapCode << ' ' << endFlow << ' ' << setprecision(2);
224 for(int i=0;i<numFlows;i++){
225 outFlowFile << flowData[i] << ' ';
229 catch(exception& e) {
230 m->errorOut(e, "FlowData", "printFlows");
235 //**********************************************************************************************************************
237 string FlowData::getName(){
242 catch(exception& e) {
243 m->errorOut(e, "FlowData", "getName");
248 //**********************************************************************************************************************