Ejemplo n.º 1
0
/*}}}*/
int main(int argc, char** argv)/*{{{*/
{

    if (argc < 2)
    {
        PrintHelp();
        return -1;
    }
    int i = 0;
    int j = 0;
    char outpath[MAX_PATH+1] = "./";
    char listfile[MAX_PATH+1] = "";
    char outAlphabet[NUM_BLOSUM+1] = ""; //if outAlphabet not set, using the default BLOSUM alphabet
    double scale = 100.0;
    //char **filenamelist = NULL;
    bool isOutputLast2Col = false;
    bool isQuietMode = false;

    set <string> filenamelist_set;
    set <string> ::iterator iss;

    int numfile = 0;
    
    int errmsg = 0;
    
    i = 1;
    while(i < argc)/*{{{*/
    {
        if(strcmp(argv[i], "-h") == 0|| strcmp(argv[i], "--help") == 0)
        {
            PrintHelp();
            errmsg = 1;
            break;
        }
        else if (strcmp(argv[i], "-d") == 0)
        {
            my_strcpy(outpath,argv[i+1], MAX_PATH);
            i += 2;
        }
        else if (strcmp(argv[i], "-s") == 0)
        {
            scale = atof(argv[i+1]);
            i += 2;
        }
        else if (strcmp(argv[i], "-i") == 0)
        {
            isOutputInteger = true;
            i ++;
        }
        else if (strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "--list") == 0)
        {
            my_strcpy(listfile,argv[i+1], MAX_PATH);
            i += 2;
        }
        else if (strcmp(argv[i], "--alphabet") == 0 || strcmp(argv[i], "-a") == 0)
        {
            my_strcpy(outAlphabet,argv[i+1], NUM_BLOSUM);
            if(!IsValidAlphabet(outAlphabet))
            {
                errmsg  = -1;
                break;
            }
            i += 2;
        }
        else if (strcmp(argv[i], "-q") == 0)
        {
            isQuietMode = true;
            i ++;
        }
        else if (strcmp(argv[i], "--pssm") == 0)
        {
            isOutputLast2Col = true;
            i ++;
        }
        else
        {
            filenamelist_set.insert(argv[i]);
            i ++;
        }
    }/*}}}*/
    numfile = filenamelist_set.size();

    if(errmsg != 0)
    {
        return errmsg;
    }
    if(strcmp(listfile,"") == 0 && filenamelist_set.size() == 0)
    {
        fprintf(stderr,"Error! neither listfile nor mtx file in the argument list are set\n");
        return -1;
    }
    else if(strcmp(listfile,"") != 0)
    {
        FILE *fpin;
        fpin = fopen(listfile,"r");
        checkfilestream(fpin,listfile,"r");
        int linesize;
        int maxline = 300;
        Array1D <char> line_1darray(maxline+1);
        char *line = line_1darray.array1D;
        while((linesize = fgetline(fpin, line , maxline)) != EOF)
        {
            if(linesize > 0) filenamelist_set.insert(line);
        }
        fclose(fpin);
    }
        
    VerifyFolder(outpath);

    Array1D <char> aaSeq_1darray(LONGEST_SEQ+1);
    Array2D <double> profile_2darray(LONGEST_SEQ, NUM_BLOSUM);
    Array1D <double> parameter_1darray(NUM_PARAMETER);
    char *aaSeq = aaSeq_1darray.array1D;
    double **profile = profile_2darray.array2D;
    double *parameter = parameter_1darray.array1D;
    double *score1 = NULL;
    double *score2 = NULL;
    char modmfile[MAX_PATH+1] = "";
    char pssmfile[MAX_PATH+1] = "";
    char mtxfile[MAX_PATH+1] = "";
    char rtname[MAX_PATH+1] = "";
    char filepath[MAX_PATH+1] = "";
    int length;
    int lengthpssm;

    int cntfile = 0;
    for(iss = filenamelist_set.begin() ; iss !=  filenamelist_set.end(); iss ++)
    {
        score1 = NULL;
        score2 = NULL;

        my_strcpy(mtxfile, (*iss).c_str(), MAX_PATH);
        rootname(mtxfile, rtname);
        getfilepath(mtxfile, filepath);
        if(getmtx(mtxfile, length, aaSeq, parameter, profile, scale) <= 0)
        {
            fprintf(stderr, "%d \t %s getting mtx file error!",cntfile+1, mtxfile);
            continue;
        }
        lengthpssm = length ;

        int profileIndex[NUM_BLOSUM]; //order the profile according to the outAlphabet
        for(j = 0; j < NUM_BLOSUM; j ++) profileIndex[j] = j;
        if(strcmp(outAlphabet,"") != 0)
        {
            for(i = 0 ; i < NUM_AA; i++)
            {
                profileIndex[i] = Char2Digit(outAlphabet[i],  BLOSUM1D_alphabet);
            } 
        }
        else
        {
            my_strcpy(outAlphabet, BLOSUM1D_alphabet, NUM_BLOSUM);
        }


        if(isOutputLast2Col)
        {
            score1 = new double [LONGEST_SEQ];
            score2 = new double [LONGEST_SEQ];
            sprintf(pssmfile, "%s/%s.pssm", filepath, rtname);
            lengthpssm = GetPSSM(pssmfile, lengthpssm, NULL, NULL, NULL, score1, score2);
        }
        if ( length != lengthpssm)
        {
            fprintf(stderr,"Error! length of mtx file and pssm not the same for %s", rtname);
        }
        else
        {
            sprintf(modmfile, "%s/%s.modm", outpath, rtname);
            WriteMODMFile(modmfile, aaSeq, length, profile, profileIndex, outAlphabet, score1, score2, parameter, isOutputInteger);
            if(!isQuietMode) fprintf(stdout,"%d  %s output\n", cntfile+1, modmfile);
        }
        if (score1 != NULL) delete [] score1;
        if (score2 != NULL) delete [] score2;
    }
    //
    return 0;
}
Ejemplo n.º 2
0
void KeyPad::ProcessKey()
{
   char K=ReadKey();
   KD = Char2Digit(K);
   
   

   
   
//   if (K!=NoKeyChar)
   {  
     switch (CurrState)
     {  
       case 0:
       
         LCDRow1 = "A-Sch/B-SetUp";
       
         switch (K)
         {
           case FKeySetCurrSched:
             CurrState = KSTATE_SETCURRSCHED;
             break;
           
           case FKeySetUpSched:
             CurrState = KSTATE_SETUPSCHED;
             CurrSubState = 0;
             break;  
           
           
         }
         break; 
       
       case KSTATE_SETCURRSCHED :
         
         LCDRow1 = "Choose Schedule";
         
         if (KD>=0 && KD < ScheduleSets)
         {
           //Set Current Schedule KD
           (*mFeedSch).ActiveSet=KD;
           CurrState = 0;
         }  
         break;
       
       case KSTATE_SETUPSCHED :
         
         LCDRow1 = "S"+String((*mFeedSch).ActiveSet,DEC)+"~";
         
         switch (CurrSubState)
         {
           case 0:  //Choose Sched Type - Cyclic (1) or OnTime (2),
                    //Cyclic : 1 / OnTime : 4
             
             LCDRow1 += "1Cycl/2OnTime";
                    
             CurrNumber = 0;
             CurrSubState = KD==1 ? 1 : (KD==2 ? 4 : 0) ;
             P1 = 0;
             P2 = 0;
             P3 = 0; 
             break; 
             
           case 1:  //Cyclic Chosen, Choose FeedsCount
           
             LCDRow1 += "Count";
           
             NumbEntering (K,2,0,&P1);
             break;
             
           case 2:  //Cyclic Chosen, Choose FeedsInterval
           
             LCDRow1 += "Interval";
           
             NumbEntering (K,3,1,&P2);
             break;
            
           case 3:  //Cyclic Chosen, Choose FeedDur
           
             LCDRow1 += "Duration";
           
             NumbEntering (K,0,2,&P3);
             if (CurrSubState == 0)
             {
               InitCyclicSchedule(P1,P2*60,P3); 
               CurrState = 0;
             }
             break;

//           case 4:  //OnTime Chosen, Choose FeedN
//           
//           case 5:  //OnTime Chosen, Choose FeedTime
//           
//           case 6:  //OnTime Chosen, Choose FeedDur
           
         }
       
         
         break;
       
        
       default :
         break;
         
     } 
   }
  
   if (CurrState == KSTATE_SETUPSCHED)
   {
     LCDRow2="";
     
     if (CurrSubState >= 1)
       LCDRow2 = "C";
     if (CurrSubState >= 2)  
       LCDRow2 += String(P1,DEC) + "|I";
     if (CurrSubState >= 3)
       LCDRow2 += String(P2,DEC) + "|D";

   
     LCDRow2 += CurrString;
     
 //    LCDRow2 +=".";
     
   }  
   else 
     LCDRow2= ""; //CurrString;
     
}