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 //**********************************************************************************************************************
129 //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
131 void FlowData::translateFlow(){
134 set<char> charInMiddle;
136 bool updateOld = false;
138 for(int i=0;i<endFlow;i++){
139 int intensity = (int)(flowData[i] + 0.5);
140 char base = baseFlow[i % baseFlow.length()];
142 if (intensity == 0) { //are we in the middle
143 if (oldspot != -1) { charInMiddle.insert(base); }
144 }else if (intensity >= 1) {
145 if (oldspot == -1) { updateOld = true; }
146 else { //check for bases inbetween two 1's
147 if (charInMiddle.count(base) != 0) { //we want to covert to an N
148 sequence = sequence.substr(0, oldspot+1);
152 charInMiddle.clear();
156 for(int j=0;j<intensity;j++){
160 if (updateOld) { oldspot = sequence.length()-1; updateOld = false; }
163 if(sequence.size() > 4){
164 sequence = sequence.substr(4);
170 catch(exception& e) {
171 m->errorOut(e, "FlowData", "translateFlow");
176 //**********************************************************************************************************************
178 void FlowData::capFlows(int mF){
183 if(endFlow > maxFlows){ endFlow = maxFlows; }
187 catch(exception& e) {
188 m->errorOut(e, "FlowData", "capFlows");
193 //**********************************************************************************************************************
195 bool FlowData::hasMinFlows(int minFlows){
199 if(endFlow >= minFlows){ pastMin = 1; }
203 catch(exception& e) {
204 m->errorOut(e, "FlowData", "hasMinFlows");
209 //**********************************************************************************************************************
211 Sequence FlowData::getSequence(){
214 return Sequence(seqName, sequence);
216 catch(exception& e) {
217 m->errorOut(e, "FlowData", "getSequence");
222 //**********************************************************************************************************************
224 void FlowData::printFlows(ofstream& outFlowFile){
226 // outFlowFile << '>' << seqName << locationString << " length=" << seqLength << " numflows=" << maxFlows << endl;
227 outFlowFile << seqName << ' ' << endFlow << ' ' << setprecision(2);
229 for(int i=0;i<maxFlows;i++){
230 outFlowFile << flowData[i] << ' ';
234 catch(exception& e) {
235 m->errorOut(e, "FlowData", "printFlows");
240 //**********************************************************************************************************************
242 void FlowData::printFlows(ofstream& outFlowFile, string scrapCode){
244 outFlowFile << seqName << '|' << scrapCode << ' ' << endFlow << ' ' << setprecision(2);
246 for(int i=0;i<numFlows;i++){
247 outFlowFile << flowData[i] << ' ';
251 catch(exception& e) {
252 m->errorOut(e, "FlowData", "printFlows");
257 //**********************************************************************************************************************
259 string FlowData::getName(){
264 catch(exception& e) {
265 m->errorOut(e, "FlowData", "getName");
270 //**********************************************************************************************************************