Esempio n. 1
0
File: g22.c Progetto: 8l/csolve
void ldndate(int dnptr){
   int i,s,sn,lptr,c,g,splflag,ptr,tmp,ldtmp,g2;
   kosquare = kosave[dnptr];
   s = mvs[dnptr];
   if(s == PASS){  /* pass */
      return;
      }
   g = board[s];
   c = grcolor[g];
   splflag = FALSE;
   board[s] = NOGROUP;
   if(mvconn[dnptr] != EOL){
      ptr = mvconn[dnptr];      /* bring back combined groups */
      g = lsplit(ptr,g);
      splflag = TRUE;
      }
   for(ptr = mvcapt[dnptr]; ptr != EOL; ptr = links[ptr]){
         g2 = list[ptr]; /* bring back killed groups */
             lresurrect(g2);  /* resurrect enemy group */
         }
  
   if(!splflag){        /* remove piece from group */
      grsize[g]--;
      if(grsize[g] == 0){  /* only one piece in group */
         --maxgr;           /* delete group */
         killist(&grlbp[g]);     /* return liberties to free list */
         lptr = grnbp[g];
         while(lptr != EOL){
            dellist(g,&grnbp[list[lptr]]);
            lptr = links[lptr];
            }
         if(grnbp[g] != EOL)
		 killist(&grnbp[g]); /* return neighbors to free list */
         }
      else {                  /* take piece away from group */
         grpieces[g] = mvnext[grpieces[g]]; 
         ptr = lbply[dnptr];
         while(ptr != EOL){ 
            dellist(list[ptr],&grlbp[g]); 
            --grlibs[g];
            ptr = links[ptr];
            } 
         killist(&lbply[dnptr]); 
         ptr = nbply[dnptr];
         while(ptr != EOL){ 
            tmp = list[ptr];
            dellist(tmp,&grnbp[g]); 
            dellist(g,&grnbp[tmp]); 
            ptr = links[ptr];
            } 
         if(nbply[dnptr] != EOL)
		 killist(&nbply[dnptr]); 
         }
      if(edge[s] < 2){
         i = fdir[s]; 
         for(ldtmp = ldir[i]; i < ldtmp; ++i){
            sn = s + nbr[i];
            --lnbf[sn][c];
            ++lnbn[sn]; 
            addlist(s,&nblbp[sn]);
            g = board[sn];
            if(g == NOGROUP)continue;
            if(addlist(s,&grlbp[g])){
              ++grlibs[g];
              }
            }
         }
      else{
         --lnbf[s+1][c];
         ++lnbn[s+1];
         addlist(s,&nblbp[s+1]);
         --lnbf[s-1][c];
         ++lnbn[s-1];
         addlist(s,&nblbp[s-1]);
         --lnbf[s+boardsize][c];
         ++lnbn[s+boardsize];
         addlist(s,&nblbp[s+boardsize]);
         --lnbf[s-boardsize][c];
         ++lnbn[s-boardsize];
         addlist(s,&nblbp[s-boardsize]);
         g = board[s+1];
         if(g != NOGROUP )
            if(addlist(s,&grlbp[g]))++grlibs[g];
         g = board[s-1];
         if(g != NOGROUP )
            if(addlist(s,&grlbp[g]))++grlibs[g];
         g = board[s+boardsize];
         if(g != NOGROUP )
            if(addlist(s,&grlbp[g]))++grlibs[g];
         g = board[s-boardsize];
         if(g != NOGROUP )
            if(addlist(s,&grlbp[g]))++grlibs[g];
         }
      }
   else {
      if(edge[s] < 2){
         i = fdir[s];
         for(ldtmp = ldir[i]; i < ldtmp; ++i){
            sn = s + nbr[i];
            --lnbf[sn][c];
            ++lnbn[sn];
            addlist(s,&nblbp[sn]);
            g = board[sn];
            if(grcolor[g] != 1-c)continue;
            if(addlist(s,&grlbp[g])){
              ++grlibs[g];
              }
            }
         }
      else{
         --lnbf[s+1][c];
         ++lnbn[s+1];
         addlist(s,&nblbp[s+1]);
         --lnbf[s-1][c];
         ++lnbn[s-1];
         addlist(s,&nblbp[s-1]);
         --lnbf[s+boardsize][c];
         ++lnbn[s+boardsize];
         addlist(s,&nblbp[s+boardsize]);
         --lnbf[s-boardsize][c];
         ++lnbn[s-boardsize];
         addlist(s,&nblbp[s-boardsize]);
         g = board[s+1];
         if(grcolor[g] == 1-c)
            if(addlist(s,&grlbp[g]))++grlibs[g];
         g = board[s-1];
         if(grcolor[g] == 1-c)
            if(addlist(s,&grlbp[g]))++grlibs[g];
         g = board[s+boardsize];
         if(grcolor[g] == 1-c)
            if(addlist(s,&grlbp[g]))++grlibs[g];
         g = board[s-boardsize];
         if(grcolor[g] == 1-c)
            if(addlist(s,&grlbp[g]))++grlibs[g];
         }
      }
   }
Esempio n. 2
0
int main(int argc,char* argv[])
{
    list<string> genes;
    DictStringSet gene_mutatedSamples;
    ifstream     sample_mut_f;
    ifstream     analyzed_genes_file;
    ofstream     most_visited_file;
    ofstream     highest_weight_file;
    int K;
    int mAS_perGene;
    int num_iterations;
    set<string> all_samples;
    DictStringSet sample_mutatedGenes;
    int num_exper;
    int step_length;
    string sampleID;

    if(argc < 8)
        {
            cout << "Usage: python Dendrix.py mutations_file K minFreqGene number_iterations analyzed_genes_file num_exper step_length\n";
            cout << "mutations_file: input file with mutation matrix (see README.txt for description)\n";
            cout << "K: size of the sets to be sampled\n";
            cout << "minFreqGene: minimum frequency of mutation for a gene to be considered in the analysis\n";
            cout << "number_iterations: number of iterations of the MCMC\n";
            cout << "analyzed_genes_file: file with list of analyzed genes (see README.txt for description)\n";
            cout << "num_exper: number of times the experiment is going to be run (see README.txt for description)\n";
            cout << "step_length: number of iterations of the MCMC between two samples\n";
            exit(0);
        }

    genes.clear();
    gene_mutatedSamples.clear();
    sample_mut_f.open(argv[1]);
    K = atoi(argv[2]);
    mAS_perGene = atoi(argv[3]);
    num_iterations = atoi(argv[4]);
    analyzed_genes_file.open(argv[5]);
    all_samples.clear();
    sample_mutatedGenes.clear();
    num_exper = atoi(argv[6]);
    step_length = atoi(argv[7]);

    printf("Load genes...\n");

    string line;
    list<string> v;
    
    while(!analyzed_genes_file.eof())
        {
	    getline(analyzed_genes_file,line);
	    lsplit(line,v);
	    if(!v.empty())
		{
		    genes.push_back(v.front());
		    gene_mutatedSamples[v.front()] = set<string>();
		}
       	    v.clear();
        }
    //    genes.pop_back();
    gene_mutatedSamples.erase("");
    analyzed_genes_file.close();
    
    printf("Loading Mutations...\n");

    vector<string> vv;

    while(!sample_mut_f.eof())
	{
	    getline(sample_mut_f,line);
	    if(line.empty())
		break;
	    vsplit(line,vv);
	    sampleID = vv[0];
	    all_samples.insert(sampleID);
	    sample_mutatedGenes[sampleID] = set<string>();
	    
	    for (int i = 0; i < (sz(vv) - 1); ++i)
		{
		    string gene = vv[i+1];
		    
		    if(cpresent(genes,gene))
			{
			    if(!present(gene_mutatedSamples,gene))
				gene_mutatedSamples[gene] = set<string>();
			    gene_mutatedSamples[gene].insert(sampleID);
			    sample_mutatedGenes[sampleID].insert(gene);
			}
		}
	    vv.clear();
	}
    
    sample_mut_f.close();
    
    DictStringDouble sample_numMut;
    
    tr(sample_mutatedGenes,it)
	{
	    // it->first refers to the sampleID or PatientID
	    unsigned tmp_numMut = sample_mutatedGenes[it->first].size();
	    sample_numMut[it->first] = (double)tmp_numMut;
	    
	}