testSourceSeq.cpp Source File

Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members

# testSourceSeq.cpp

Go to the documentation of this file.

    00001 #include <iostream>
    00002 #include "gn/gnSequence.h"
    00003 #include <fstream>
    00004
    00005 #include "gn/gnFilter.h"
    00006 #include "gn/gnFASSource.h"
    00007
    00008 int32 main( int32 argc, char* argv[])
    00009 {
    00010         argc; argv;
    00011         gnSequence gps;
    00012
    00013         string filename;
    00014         cout << "Enter a filename to compute a base composition.\n";
    00015         cin >> filename;
    00016         cout << "Opening " + filename + "\n";
    00017         gps.LoadSource(filename);
    00018         cout << "Genome Length: " << gps.length() << " in " << gps.contigListLength() << " contigs\n";
    00019
    00020         cout << "Give a file name to output composition data: ";
    00021         string outfilename;
    00022         cin >> outfilename;
    00023         ofstream outfile(outfilename.c_str(), ios::out);
    00024         outfile << "Contig_Name A_count C_count G_count T_count\n";
    00025
    00026         ofstream ambig("ambigs.txt", ios::out);
    00027
    00028         gnSeqI a_total = 0, c_total = 0, g_total = 0, t_total = 0, ambiguities = 0;
    00029         for(int contigI=0; contigI < gps.contigListLength(); contigI++){
    00030                 gnSeqI seqLength = gps.contig(contigI).length();
    00031                 gnSeqC *bases = new gnSeqC[seqLength];
    00032                 gps.contig(contigI).ToArray(bases, seqLength);
    00033                 string contigName = gps.contigName(contigI);
    00034
    00035                 gnSeqI a = 0, c = 0, g = 0, t = 0;
    00036                 for(int i=0; i < seqLength; i++){
    00037                         if((bases[i] == 'a')||(bases[i] == 'A'))
    00038                                 a++;
    00039                         else if((bases[i] == 'c')||(bases[i] == 'C'))
    00040                                 c++;
    00041                         else if((bases[i] == 'g')||(bases[i] == 'G'))
    00042                                 g++;
    00043                         else if((bases[i] == 't')||(bases[i] == 'T'))
    00044                                 t++;
    00045                         else{
    00046                                 ambiguities++;
    00047                                 ambig << bases[i];
    00048                         }
    00049                 }
    00050                 delete[] bases;
    00051                 outfile << contigName << "      " << a << "     " << c << "     " << g << "     " << t << "\n";
    00052                 a_total += a; c_total += c; g_total += g; t_total += t;
    00053         }
    00054         outfile.close();
    00055         ambig.close();
    00056         cout << "Enter a file for me to write to: ";
    00057         cin >> outfilename;
    00058         gnFASSource::Write(gps, outfilename);
    00059         cout << "A: " << a_total << "\nC: " << c_total << "\nG: " << g_total << "\nT: " << t_total << "\n";
    00060         cout << "Ambiguities: " << ambiguities << "\n";
    00061         cout << "For a total of: " << a_total + c_total + g_total + t_total + ambiguities << "\n";
    00062         cout << "Base comp. completed.  Results are in " << outfilename << "\n";
    00063         char bubba[50];
    00064         cin >> bubba;
    00065 }