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) {
72 }else{ m->mothurOut("Error in reading your flowfile, at position " + toString(flowFile.tellg()) + ". Blank name."); m->mothurOutEndLine(); m->control_pressed = true; }
77 m->errorOut(e, "FlowData", "getSequenceName");
82 //**********************************************************************************************************************
84 void FlowData::updateEndFlow(){
87 if (baseFlow.length() > 4) { return; }
90 float maxIntensity = (float) maxHomoP + 0.49;
94 while(deadSpot < endFlow){
98 for(int i=0;i<baseFlow.length();i++){
99 float intensity = flowData[i + deadSpot];
100 if(intensity > signalIntensity){
103 if(intensity < noiseIntensity || intensity > maxIntensity){
109 if(noise > 0 || signal == 0){
113 deadSpot += baseFlow.length();
118 catch(exception& e) {
119 m->errorOut(e, "FlowData", "findDeadSpot");
124 //**********************************************************************************************************************
127 //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
129 void FlowData::translateFlow(){
132 set<char> charInMiddle;
134 bool updateOld = false;
136 for(int i=0;i<endFlow;i++){
137 int intensity = (int)(flowData[i] + 0.5);
138 char base = baseFlow[i % baseFlow.length()];
140 if (intensity == 0) { //are we in the middle
141 if (oldspot != -1) { charInMiddle.insert(base); }
142 }else if (intensity >= 1) {
143 if (oldspot == -1) { updateOld = true; }
144 else { //check for bases inbetween two 1's
145 if (charInMiddle.count(base) != 0) { //we want to covert to an N
146 sequence = sequence.substr(0, oldspot+1);
150 charInMiddle.clear();
154 for(int j=0;j<intensity;j++){
158 if (updateOld) { oldspot = sequence.length()-1; updateOld = false; }
161 if(sequence.size() > 4){
162 sequence = sequence.substr(4);
168 catch(exception& e) {
169 m->errorOut(e, "FlowData", "translateFlow");
174 //**********************************************************************************************************************
176 void FlowData::capFlows(int mF){
181 if(endFlow > maxFlows){ endFlow = maxFlows; }
185 catch(exception& e) {
186 m->errorOut(e, "FlowData", "capFlows");
191 //**********************************************************************************************************************
193 bool FlowData::hasGoodHomoP(){
197 float maxIntensity = (float) maxHomoP + 0.49;
199 for(int i=0;i<endFlow;i++){
200 if(flowData[i] > maxIntensity){
206 catch(exception& e) {
207 m->errorOut(e, "FlowData", "hasMinFlows");
212 //**********************************************************************************************************************
214 bool FlowData::hasMinFlows(int minFlows){
218 if(endFlow >= minFlows){ pastMin = 1; }
222 catch(exception& e) {
223 m->errorOut(e, "FlowData", "hasMinFlows");
228 //**********************************************************************************************************************
230 Sequence FlowData::getSequence(){
233 return Sequence(seqName, sequence);
235 catch(exception& e) {
236 m->errorOut(e, "FlowData", "getSequence");
241 //**********************************************************************************************************************
243 void FlowData::printFlows(ofstream& outFlowFile){
245 // outFlowFile << '>' << seqName << locationString << " length=" << seqLength << " numflows=" << maxFlows << endl;
246 outFlowFile << seqName << ' ' << endFlow << ' ' << setprecision(2);
248 for(int i=0;i<maxFlows;i++){
249 outFlowFile << flowData[i] << ' ';
253 catch(exception& e) {
254 m->errorOut(e, "FlowData", "printFlows");
259 //**********************************************************************************************************************
261 void FlowData::printFlows(ofstream& outFlowFile, string scrapCode){
263 outFlowFile << seqName << '|' << scrapCode << ' ' << endFlow << ' ' << setprecision(2);
265 for(int i=0;i<numFlows;i++){
266 outFlowFile << flowData[i] << ' ';
270 catch(exception& e) {
271 m->errorOut(e, "FlowData", "printFlows");
276 //**********************************************************************************************************************
278 string FlowData::getName(){
283 catch(exception& e) {
284 m->errorOut(e, "FlowData", "getName");
289 //**********************************************************************************************************************