C++ Incompatible types: calculating allele frequencies

Here is what the input file looks like:

1-1_Sample 1 GCCCATGGCT
2-1_Sample 1 GAGTGTATGT
3-1_Sample 1 TGTTCTATCT
1-1_Sample 2 GCTTAGCCAT
2-1_Sample 2 TGTAGTCAGT
3-1_Sample 2 GGGAACCAAG
1-1_Sample 3 TGGAAGCGGT
2-1_Sample 3 CGGGAGGAGA
3-1_Sample 3 CTTCAGTTTT


#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <stdlib.h>

using namespace std;

const int pops = 10;
const int sequence = 100;
string w;
string popname;
string lastpop;
int totalpops;
string ind;
int i;
int j;
char c;
float dna[pops][4][sequence];
float Af[1][1][1];

int main(int argc, char *argv[])
ifstream fin0("dnatest.txt");
lastpop = "nonsense";
totalpops = -1;

if (fin0)
getline(fin0, w);
cout << w<<endl;
ind = "";
popname = "";

do {c = w [i];
if ((c != '>')&(c!='-')) ind=ind+c; } while (c != '-');
do {c = w [i];
i++; } while (c != ' ');
do {c = w [i];
if (c!= '\n') popname=popname+c; } while (i< w.length());
if (popname != lastpop) { totalpops++;

getline (fin0, w);
cout << w<<endl << w.length()<<endl;
for (i=0; i<w.length(); i++)
{if (w[i]=='A') dna[totalpops][0][i]++;
if (w[i]=='C') dna[totalpops][1][i]++;
if (w[i]=='G') dna[totalpops][2][i]++;
if (w[i]=='T') dna[totalpops][3][i]++;

for(int k=0;k<1;k++)
{for(int j=0; j<1;j++)
{for (int i=0;i<1;i++)

while (!fin0.eof());



Background: I am very new to C++ and trying to teach myself to use it to supplement my graduate research. I am genetics PhD candidate trying to model different evolutionary histories, and how they affect the frequency of alleles across populations.

Question: I am trying to extract certain portions of data from the "dna" array that I created from the input file. For example, here I have created another array "Af" where I am trying to extract counts for the first "cell," so to speak, of the dna array. The purpose of doing this, is so that I can calculate a frequency by comparing the counts in certain groups of cells to the entire dna array. I can't figure out how to do this. I keep getting the error message: "INCOMPATIBLE TYPES IN ASSIGNMENT OF 'FLOAT' TO 'FLOAT[1][1]'"

I have spent a great deal of time researching this on different forums, but I cannot seem to understand what this error means, and how else to achieve what I'm trying to achieve.

So the dna array I'm visualizing is a made from the input file such that there are 4 rows (A,C,G,T). and then 10 columns (one column for each nucleotide in the series). This "grid" is then stacked 3 times (one "sheet" for each Sample (here sample means population, and there are three individuals per population) as listed on the input file). So from this stack of grids I want to extract, for example, the first cell (the number of A's in Sample 1 at position 1. I would then want to compare this number to the total number of A's at position 1 across all samples. This frequency would then be a meaningful number for the model I'm testing. The problem is, I don't know how to extract portions of the dna array - once I figure out this condensed example, I will be applying it to very large input files, and will want to extract more than one cell at a time. Please help, I've been pouring over my teach yourself C++ books and looking through forums online, but I cannot make sense of this problem. Thanks!
Topic archived. No new replies allowed.