1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
/*
* flowdata.cpp
* Mothur
*
* Created by Pat Schloss on 12/22/10.
* Copyright 2010 Schloss Lab. All rights reserved.
*
*/
#include "flowdata.h"
//**********************************************************************************************************************
FlowData::FlowData(){}
//**********************************************************************************************************************
FlowData::~FlowData(){ /* do nothing */ }
//**********************************************************************************************************************
FlowData::FlowData(int numFlows, float signal, float noise, int maxHomoP, string baseFlow) :
numFlows(numFlows), signalIntensity(signal), noiseIntensity(noise), maxHomoP(maxHomoP), baseFlow(baseFlow){
try {
m = MothurOut::getInstance();
flowData.assign(numFlows, 0);
// baseFlow = "TACG";
seqName = "";
locationString = "";
}
catch(exception& e) {
m->errorOut(e, "FlowData", "FlowData");
exit(1);
}
}
//**********************************************************************************************************************
bool FlowData::getNext(ifstream& flowFile){
try {
seqName = getSequenceName(flowFile);
if (m->debug) { m->mothurOut("[DEBUG]: flow = " + seqName + " "); }
flowFile >> endFlow;
if (m->debug) { m->mothurOut(toString(endFlow) + " "); }
if (!m->control_pressed) {
if (m->debug) { m->mothurOut(" "); }
for(int i=0;i<numFlows;i++) {
flowFile >> flowData[i];
if (m->debug) { m->mothurOut(toString(flowData[i]) + " "); }
}
if (m->debug) { m->mothurOut("\n"); }
updateEndFlow();
translateFlow();
m->gobble(flowFile);
}
if(flowFile){ return 1; }
else { return 0; }
}
catch(exception& e) {
m->errorOut(e, "FlowData", "getNext");
exit(1);
}
}
//********************************************************************************************************************
string FlowData::getSequenceName(ifstream& flowFile) {
try {
string name = "";
flowFile >> name;
if (name.length() != 0) {
m->checkName(name);
}else{ m->mothurOut("Error in reading your flowfile, at position " + toString(flowFile.tellg()) + ". Blank name."); m->mothurOutEndLine(); m->control_pressed = true; }
return name;
}
catch(exception& e) {
m->errorOut(e, "FlowData", "getSequenceName");
exit(1);
}
}
//**********************************************************************************************************************
void FlowData::updateEndFlow(){
try{
if (baseFlow.length() > 4) { return; }
//int currLength = 0;
float maxIntensity = (float) maxHomoP + 0.49;
int deadSpot = 0;
while(deadSpot < endFlow){
int signal = 0;
int noise = 0;
for(int i=0;i<baseFlow.length();i++){
float intensity = flowData[i + deadSpot];
if(intensity > signalIntensity){
signal++;
if(intensity < noiseIntensity || intensity > maxIntensity){
noise++;
}
}
}
if(noise > 0 || signal == 0){
break;
}
deadSpot += baseFlow.length();
}
endFlow = deadSpot;
}
catch(exception& e) {
m->errorOut(e, "FlowData", "findDeadSpot");
exit(1);
}
}
//**********************************************************************************************************************
//TATGCT
//1 0 0 0 0 1
//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
//Becomes TNT
void FlowData::translateFlow(){
try{
sequence = "";
set<char> charInMiddle;
int oldspot = -1;
bool updateOld = false;
for(int i=0;i<endFlow;i++){
int intensity = (int)(flowData[i] + 0.5);
char base = baseFlow[i % baseFlow.length()];
if (intensity == 0) { //are we in the middle
if (oldspot != -1) { charInMiddle.insert(base); }
}else if (intensity >= 1) {
if (oldspot == -1) { updateOld = true; }
else { //check for bases inbetween two 1's
if (charInMiddle.count(base) != 0) { //we want to covert to an N
sequence = sequence.substr(0, oldspot+1);
sequence += 'N';
}
updateOld = true;
charInMiddle.clear();
}
}
for(int j=0;j<intensity;j++){
sequence += base;
}
if (updateOld) { oldspot = sequence.length()-1; updateOld = false; }
}
if(sequence.size() > 4){
sequence = sequence.substr(4);
}
else{
sequence = "NNNN";
}
}
catch(exception& e) {
m->errorOut(e, "FlowData", "translateFlow");
exit(1);
}
}
//**********************************************************************************************************************
void FlowData::capFlows(int mF){
try{
maxFlows = mF;
if(endFlow > maxFlows){ endFlow = maxFlows; }
translateFlow();
}
catch(exception& e) {
m->errorOut(e, "FlowData", "capFlows");
exit(1);
}
}
//**********************************************************************************************************************
bool FlowData::hasGoodHomoP(){
try{
float maxIntensity = (float) maxHomoP + 0.49;
for(int i=0;i<endFlow;i++){
if(flowData[i] > maxIntensity){
return 0;
}
}
return 1;
}
catch(exception& e) {
m->errorOut(e, "FlowData", "hasMinFlows");
exit(1);
}
}
//**********************************************************************************************************************
bool FlowData::hasMinFlows(int minFlows){
try{
bool pastMin = 0;
if(endFlow >= minFlows){ pastMin = 1; }
return pastMin;
}
catch(exception& e) {
m->errorOut(e, "FlowData", "hasMinFlows");
exit(1);
}
}
//**********************************************************************************************************************
Sequence FlowData::getSequence(){
try{
return Sequence(seqName, sequence);
}
catch(exception& e) {
m->errorOut(e, "FlowData", "getSequence");
exit(1);
}
}
//**********************************************************************************************************************
void FlowData::printFlows(ofstream& outFlowFile){
try{
// outFlowFile << '>' << seqName << locationString << " length=" << seqLength << " numflows=" << maxFlows << endl;
outFlowFile << seqName << ' ' << endFlow << ' ' << setprecision(2);
for(int i=0;i<maxFlows;i++){
outFlowFile << flowData[i] << ' ';
}
outFlowFile << endl;
}
catch(exception& e) {
m->errorOut(e, "FlowData", "printFlows");
exit(1);
}
}
//**********************************************************************************************************************
void FlowData::printFlows(ofstream& outFlowFile, string scrapCode){
try{
outFlowFile << seqName << '|' << scrapCode << ' ' << endFlow << ' ' << setprecision(2);
for(int i=0;i<numFlows;i++){
outFlowFile << flowData[i] << ' ';
}
outFlowFile << endl;
}
catch(exception& e) {
m->errorOut(e, "FlowData", "printFlows");
exit(1);
}
}
//**********************************************************************************************************************
string FlowData::getName(){
try{
return seqName;
}
catch(exception& e) {
m->errorOut(e, "FlowData", "getName");
exit(1);
}
}
//**********************************************************************************************************************
|