Example #1
0
void tree2dataS(FILE * tree,int n,int m,int* &P,double* &B,string* &Support,string* &leaves){
      int inode = 0;//number of internal nodes;
      stack<int> pileNode;    
      char c = readBracket(tree,"input tree");
      int a=1;
      int countleaf=n;
      P[0]=-1;
      B[0]=-1;
      do{
             c = readChar(tree,"input tree");
                   if (c==')'){    
                        a--;inode++;
                        int s1=pileNode.top();pileNode.pop();
                        int s2=pileNode.top();pileNode.pop();                   
                        P[s1]=n-inode;
                        P[s2]=n-inode;
                        if (a>0){                      
                           Support[n-inode]=readSupport(tree,"input tree");  
                           B[n-inode]=readdouble(tree,"input tree");                                       
                        }
                        else while (!pileNode.empty()){
                             int s=pileNode.top();pileNode.pop();
                             P[s]=n-inode;                                
                        }  
                        pileNode.push(n-inode);                  
                   }
                   else if (c!='(' && c!=',' && c!=-1 && c!=';' && c!='\n'){
                       string lb=readLabel(c,tree);
                        pileNode.push(countleaf);                        
                        leaves[countleaf]=lb;
                        B[countleaf]=readdouble(tree,"input tree");
                        Support[countleaf]="";
                        countleaf++;
                   }                    
                   else if (c=='(') {a++;}
           }  while (a>0);
}
Example #2
0
void counting(string fn,int &n,int &m,int nb_tree){
     FILE * tree = fopen(fn.c_str(),"rt");
     if (tree==NULL) cout<<"Impossible to open tree file"<<endl;
     else{ 
          int n1,m1; 
          for (int i=0;i<nb_tree;i++){ 
              char c = readBracket(tree,fn); 
              n=0;//internal nodes
              int l=0;//leaves
              int a=0;
              while (c!=';'){
                 if (c=='(') {n++;a++;}
                 if (c==':' && a>0) l++;
                 if (c==')') {
                    a--;
                    if (a>0) read2P(tree,fn);
                 }       
                 c=readChar(tree,fn); 
              }
              if (a!=0) {
                  cout<<"Errors in the input trees"<<endl;
                  exit(EXIT_FAILURE);
              }
              m=n+l-1;//number of branches
              if (i>0 && n1!=n && m1!=m){ 
                 cout<<"The trees do not have the same size"<<endl;
                 exit (EXIT_FAILURE);
              }
              if (i==0){
                 n1=n;
                 m1=m;
              }
          }
          fclose(tree);
     }     
}
Example #3
0
bool tree2data(FILE * tree,string date,int n,int m,int* &P,double* &B,string* &Support,double* &T,string* &leaves){
      int inode = 0;//number of internal nodes;
      stack<int> pileNode;    
      char c = readBracket(tree,"input tree");
      int a=1;
      int countleaf=n;
      P[0]=-1;
      B[0]=-1;
      bool all=false;
      do{
             c = readChar(tree,"input tree");
                   if (c==')'){    
                        a--;inode++;
                        int s1=pileNode.top();pileNode.pop();
                        int s2=pileNode.top();pileNode.pop();                   
                        P[s1]=n-inode;
                        P[s2]=n-inode;
                        if (a>0){
                           Support[n-inode]=readSupport(tree,"input tree");  
                           B[n-inode]=readdouble(tree,"input tree");
                        }
                        else
                            while (!pileNode.empty()){
                             int s=pileNode.top();pileNode.pop();
                             P[s]=n-inode;                                
                        }  
                        pileNode.push(n-inode);                  
                   }
                   else if (c!='(' && c!=',' && c!=-1 && c!=';' && c!='\n'){
                        string lb=readLabel(c,tree);  
                        pileNode.push(countleaf);                        
                        leaves[countleaf]=lb;
                        B[countleaf]=readdouble(tree,"input tree");
                        Support[countleaf]="";
                        countleaf++;
                   }                    
                   else if (c=='(') {a++;}
           }  while (a>0);
           FILE * dateFile = fopen(date.c_str(),"rt");
           if (dateFile == NULL)  cout << "Can not open the file " <<date<< endl;
           else{
               int ino=readInt(dateFile,"Error in the date file, the file should begin with an integer (the number of dated tips)");
               for (int i=0;i<=m;i++) T[i]=-1;
              int count=0;
              double first=-1;
              for (int i=0;i<ino;i++){
                     string s=readWord(dateFile,date);
                     double lt=readdouble(dateFile,date);                    
                     int k = getPosition(leaves,s,n,m+1);
                     if (k!=-1) {
                         if (count==0) first=lt;
                         else if (lt!=first) all=true;                                
                         T[k]=lt;
                         count++;
                     }
              }       
              if (count<countleaf-n){
                 cout<<"The dates of some taxa are missing. If the input tree contains some outgroups, use option -g to specify the file name of outgroups. "<<endl;
                 exit(EXIT_FAILURE);
              }  
              fclose(dateFile);              
           }
      return all;
}
Example #4
0
void checkRooted(Pr* opt){
    FILE * tree = fopen(opt->inFile.c_str(),"rt");
    if (tree==NULL){
        cout<<"Error: can not open the input file"<<endl;
        exit(EXIT_FAILURE);
    }
    stack<int> pileNode;
    char c = readBracket(tree,"input tree");
    int a=1;
    int s=0;
    int nbChild=0;
    int n=0;
    int m=0;
    do{
        c = readChar(tree,"input tree");
        if (c==')'){
            a--;
            s=0;
            nbChild=0;
            while (!pileNode.empty() && s!=-1) {
                s=pileNode.top();pileNode.pop();
                if (s!=-1){
                    nbChild++;
                }
            }
            string sp=readSupport(tree,"input tree");
            if (a>0) {
                double d = readdouble(tree,"input tree");
            }
            pileNode.push(1);
            n++;
            m++;
        }
        else if (c!='(' && c!=',' && c!=-1 && c!=';' && c!='\n'){
            string s= readLabel(c,tree,a);
            pileNode.push(1);
            double d =readdouble(tree,"input tree");
            m++;
        }
        else if (c=='(') {a++;pileNode.push(-1);}
        else if (c=='\n') {
            c=readChar(tree,"input tree");
        }
    }  while (a>0);
    fclose(tree);
    m--;
    opt->nbINodes=n;
    opt->nbBranches=m;
    if (m==2*n) {
        opt->rooted=true;
    }
    else if (m==2*n+1 && nbChild==3){
        opt->rooted=false;
    }
    else if (nbChild==2) {
        opt->rooted=true;
    }
    else{
        opt->rooted=false;
    }
}