// This software is Copyright (C) 2005 by Andrew Firth, University of Otago, // Dunedin, New Zealand. All rights reserved. // Programming to return tracks to zero for long gaps. // Assumes input file is in nucleotide order. // Column 1 is nucleotide ID. Columns 2 and 3 are some statistic. // At start and end of any long gaps, writes an extra line "nuc_ID 0 0" to // output file. #include #include #include #include #include #include using namespace std; int main(int argc, char* argv[]) { if (2 != argc) { cerr << "Aborting; use '" << argv[0] << " logfile'.\n"; exit(EXIT_FAILURE); } int k, nlines, col1prev, col1, gapsize; double col2, col3; gapsize = 3; // zeros any gaps > gapsize nucleotides long // Open log file. ifstream logfile(argv[1]); if (!logfile) { cerr << "Aborting: can't find log file '" << argv[1] << "'.\n"; exit(EXIT_FAILURE); } // Number of lines in log file nlines = -1; while (logfile.ignore(1000, '\n')) { ++nlines; } logfile.clear(); logfile.seekg(0); // Work through logfile if (nlines > 0) { logfile >> col1; logfile >> col2; logfile >> col3; logfile.ignore(1000, '\n'); cout << col1 << " " << col2 << " " << col3 << "\n"; for (k = 1; k < nlines; ++k) { col1prev = col1; logfile >> col1; logfile >> col2; logfile >> col3; logfile.ignore(1000, '\n'); if (col1 - col1prev > gapsize) { cout << col1prev << " " << 0 << " " << 0 << "\n"; cout << col1 << " " << 0 << " " << 0 << "\n"; } cout << col1 << " " << col2 << " " << col3 << "\n"; } } }