Beispiel #1
0
/*************************************************************************
*   Check options and allocate / set mask if needed
*/
int HandleFilterMaskingI(FILTER *filtPO)
{
    int block;
    DOUB fracD;

    if( NeedFilterMaskingI(filtPO) ) {
        if( IsFileStdinI(filtPO->in) ) {
            PROBLINE;
            printf("Options not compatible with stdin\n\n");
            return(FALSE);
        }
        /***
        *   Last two args mean ignore comments and blanks
        *   Then rewind file and allocate space for line mask
        */
        filtPO->n_mask = FileLinesI(filtPO->in,TRUE,TRUE);
        filtPO->n_block = INT((filtPO->n_mask - filtPO->l_bof) / filtPO->l_blk);
        rewind(filtPO->in);
        filtPO->mask = (char *)ALLOC(filtPO->n_mask, sizeof(char));
        if(!filtPO->mask) {
            PROBLINE;
            printf("Can't allocate mask for %d input lines\n",filtPO->n_mask);
            return(FALSE);
        }
        /***
        *   If doing random fraction, calc frac and set
        */
        fracD = -1.0;
        if( filtPO->rann > 0) {
            if( filtPO->l_blk > 1) {
                block = BlockForFiltLineI(filtPO, filtPO->n_mask);
                fracD = RNUM(filtPO->rann) / RNUM(block);
            }
            else {
                fracD = RNUM(filtPO->rann) / RNUM(filtPO->n_mask);
            }
        }
        else if( filtPO->ranf >= 0.0) {
            fracD = filtPO->ranf;
        }
        if(fracD >= 0.0) {
            SetRandFilterMaskingI(filtPO, fracD);
        }
/*
DumpArray(filtPO->mask, IS_CHAR, 0, filtPO->n_mask, " M=%d\n", NULL);
*/
    }
    return(TRUE);
}
Beispiel #2
0
void init_boards(void) {
   int i, j , fatal_error = 0;
   char buf[100];

   for (i = 0; i < INDEX_SIZE; i++) {
	msg_storage[i] = 0;
	msg_storage_taken[i] = 0;
   }

    for (i = 0; i < NUM_OF_BOARDS; i++) {
	if ((RNUM(i) = real_object(VNUM(i))) == -1) {
		sprintf(buf, "Fatal board error: board vnum %d does not exist!", VNUM(i));
		log(buf);
		fatal_error = 1;
	}  
	num_of_msgs[i] = 0;
	for(j = 0; j < MAX_BOARD_MESSAGES; j++) {
		memset(&(msg_index[i][j]), '\0', sizeof(struct board_msginfo));
		msg_index[i][j].slot_num = -1;
	}
	Board_load_board(i);
   }

   if (fatal_error)
	exit(0);
}
Beispiel #3
0
/* search the room ch is standing in to find which board he's looking at */
int find_board(struct char_data *ch) {
   struct obj_data *obj;
   int i;

   for (obj = world[ch->in_room].contents; obj; obj = obj->next_content)
	for (i = 0; i < NUM_OF_BOARDS; i++)
		if (RNUM(i) == obj->item_number)
			return i;

   return -1;
}
Beispiel #4
0
/************************************************************************
*   Set random mask; Handles lines and blocks
*/
int SetRandFilterMaskingI(FILTER *filtPO, DOUB fracD)
{
    int i, line;
    char *tmaskPC;

    LIMIT_NUM(fracD, 0.0, 1.0);
    if( filtPO->l_blk > 1) {
        tmaskPC = (char *)ALLOC(filtPO->n_block, sizeof(char));
        MaskRandSubsetI(tmaskPC, filtPO->n_block, RNUM(fracD));
        for(i=0; i<filtPO->n_block; i++)
        {
            line = filtPO->l_bof + (filtPO->l_blk * i);
            BOG_CHECK(line >= filtPO->n_mask);
            if(tmaskPC[i]) {
                filtPO->mask[line] = 1;
            }
        }
        CHECK_FREE(tmaskPC);
    }
    else {
        MaskRandSubsetI(filtPO->mask, filtPO->n_mask, RNUM(fracD));
    }
    return(TRUE);
}
Beispiel #5
0
/***************************************************************************
*   Calculates Tm for a sequence seqS[len]
*   Will set Tm, G, H, and S if var pointers are non-NULL
*
*   Returns TRUE if good calculation
*   FALSE if some problem
*/
int SeqTmThermI(TM_PARS *tmPO, char *seqS, int len, DOUB *tPR, DOUB *gPR,
    DOUB *hPR, DOUB *sPR)
{
    int ok;
    DOUB hiD,siD,hD,sD,tmD;
    DOUB tmDA[DSET_EV_NUM], dgDA[DSET_EV_NUM];
    DOUB dhDA[DSET_EV_NUM], dsDA[DSET_EV_NUM];
    char tS[MAX_TM_LEN+1];

    DB_DNA_TM
    { 
        DB_PrI(">> SeqTmThermI algo=%d len=%d\n",tmPO->algo,len);
        PrintString(seqS,len,outfileGPF); DB_PrI("\n");
    }
    /***
    *   Check and initialize passed in args
    */
    VALIDATE(tmPO,TM_PARS_ID);
    if(tPR)
    {   *tPR = BAD_R;   }
    if(gPR)
    {   *gPR = BAD_R;   }
    if(hPR)
    {   *hPR = BAD_R;   }
    if(sPR)
    {   *sPR = BAD_R;   }
    /***
    *   Check length
    */
    if(len>MAX_TM_LEN)
    {
        printf("Too long for Tm: %d (max=%d)\n",len,MAX_TM_LEN);
        ERR("SeqTmThermI","Too long, too long, too long");
        return(FALSE);
    }
    /***
    *   Different plans for different algorithms
    */
    ok = FALSE;
    switch(tmPO->algo)
    {
        case ALGO_24:
            DB_DNA_TM DB_PrI("+ simple composition algorithm; ALGO_24\n");
            tmD = TmFromGCContD(tmPO,seqS,len);
            if(tPR) {
                *tPR = tmD;
            }
            ok = TRUE;
            break;
        /***
        *   PNA 
        */
        case ALGO_PNA:
            tmD = CalcPNATmI(tmPO,seqS,len);
            if(tPR) {
                *tPR = tmD;
            }
            ok = TRUE;
            break;
        /***
        *   PEYRET
        */
        case ALGO_PEYRET:
            /***
            *   Nic Peyret's code call.
            *   This code sets values in passed arrays, so recover after
            *
            *   Here only single sequence, which must be copied to 
            *   it's own null-terminates string
            *
            *   SeqDsetEnergyI(TM_PARS *tmPO, char *seqtopPC,
            *       char *seqbotPC, int verboseI, int modeI, DOUB *tPD, 
            *       DOUB *gPD, DOUB *hPD, DOUB *sP, DOUB *xPD);
            */
            strncpy(tS,seqS,len);
            tS[len]='\0';
            DB_DNA_TM DB_PrI("+ Calling Peyret's Dset\n");
            ok = SeqDsetEnergyI(tmPO, tS, NULL, TRUE, DSET_IMP,
                tmDA, dgDA, dhDA, dsDA, NULL);
            if(!ok) {
                break;
            }
            if(tPR) {
                *tPR = tmDA[0];
            }
            if(gPR) {   
                *gPR = dgDA[0]; 
            }
            if(hPR) {   
                *hPR = dhDA[0]; 
            }
            if(sPR) {   
                *sPR = dsDA[0]; 
            }
            DB_DNA_TM DB_PrI("+ ok=%d Tm=%f dG=%f dH=%f dS=%f\n",ok,tmDA[0],dgDA[0],dhDA[0],dsDA[0]);
            break;
        /***
        *   "Normal" nearesst neighbor case(s)
        *   Locally coded SantaLucia algorithm ...
        *   Or the "Oligo" or "Melting" program variants
        */
        case ALGO_SANTA:
        case ALGO_OLIGO:
        case ALGO_MELTING:
            /***
            *   Get enthalpy and entropy for sequence
            *   Initialization thermo terms then nearest neighbors
            */
            if(!SetSeqTmInitTermsI(tmPO,seqS,len,&hiD,&siD)) {
                return(FALSE);
            }
            if(!TallySeqTmNNTermsI(tmPO,seqS,len,&hD,&sD)) {
                return(FALSE);
            }
            DB_DNA_TM {
                DB_PrI("+ H = %f (Tally %f + Init %f)\n",hD+hiD,hD,hiD);
                DB_PrI("+ S = %f (Tally %f + Init %f)\n",sD+siD,sD,siD);
            }
            hD += hiD;
            sD += siD;
            /***
            *   SantaLucia length-dependent salt correction term
            */
            if(tmPO->algo == ALGO_SANTA) {
                sD += (0.368 * log(tmPO->salt) * RNUM(len));
            }
            /***
            *   Calculate Tm and set other vars if pointers really passed
            */
            if(tPR) {   
                *tPR = TmFromThermoSumsD(tmPO,hD,sD,len);
                DB_DNA_TM DB_PrI("+ Tm=%f\n",*tPR);
            }
            if(gPR) {   
                *gPR = (hD - ((tmPO->tp+273.15) * sD) ) / 1000.0;
                DB_DNA_TM DB_PrI("+ dG=%f\n",*gPR);
            }
            if(hPR) {   
                *hPR = hD/1000.0;   
            }
            if(sPR) {   
                *sPR = sD;  
            }
            ok = TRUE;
            break;
        default:
            printf("Bogus algorithm code=%d\n",tmPO->algo);
            ERR("SeqTmThermI","Bogus alg code");
    }
    DB_DNA_TM DB_PrI("<< SeqTmThermI %d\n",ok);
    return(ok);
}
Beispiel #6
0
/**************************************************************************
*   Block-weighted match between letters
*/
REAL AlignedSeqBmatchScoreR(PPARS *ppPO,char *fS,int fi,char *sS,int si,int n)
{
    int i,j,mat,c;
    REAL scR;

    DB_PAIRLO DB_PrI(">> AlignedSeqBmatchScoreR fi=%d si=%d n=%d\n",fi,si,n);
    scR = 0.0;
    mat = 0;
    switch(ppPO->ctype)
    {
        case PP_COM_SIM:
            for(i=0;i<n;i++)
            {
                /***
                *   Self then one-back, one-up
                */
                if(TOUPPER(fS[fi+i]) != TOUPPER(sS[si+i]))
                {
                    continue;
                }
                mat += 2;
                if(i>0)
                {
                    if(TOUPPER(fS[fi+i-1]) == TOUPPER(sS[si+i-1]))
                        mat++;
                }
                if(i<(n-1))
                {
                    if(TOUPPER(fS[fi+i+1]) == TOUPPER(sS[si+i+1]))
                        mat++;
                }
            }
            break;
        case PP_COM_PCOM:
            for(i=0;i<n;i++)
            {
                c = 0;
                switch(TOUPPER(fS[fi+i]))
                {
                    case 'A': if(TOUPPER(sS[si+i])=='T') c++; break;
                    case 'C': if(TOUPPER(sS[si+i])=='G') c++; break;
                    case 'G': if(TOUPPER(sS[si+i])=='C') c++; break;
                    case 'T': if(TOUPPER(sS[si+i])=='A') c++; break;
                }
                if(!c)
                {
                    continue;
                }
                mat += 2;
                if(i>0)
                {
                    switch(TOUPPER(fS[fi+i-1]))
                    {
                        case 'A': if(TOUPPER(sS[si+i-1])=='T') mat++; break;
                        case 'C': if(TOUPPER(sS[si+i-1])=='G') mat++; break;
                        case 'G': if(TOUPPER(sS[si+i-1])=='C') mat++; break;
                        case 'T': if(TOUPPER(sS[si+i-1])=='A') mat++; break;
                    }
                }
                if(i<(n-1))
                {
                    switch(TOUPPER(fS[fi+i+1]))
                    {
                        case 'A': if(TOUPPER(sS[si+i+1])=='T') mat++; break;
                        case 'C': if(TOUPPER(sS[si+i+1])=='G') mat++; break;
                        case 'G': if(TOUPPER(sS[si+i+1])=='C') mat++; break;
                        case 'T': if(TOUPPER(sS[si+i+1])=='A') mat++; break;
                    }
                }
            }
            break;
        case PP_COM_COM:
            j = si+n-1;
            for(i=0;i<n;i++)
            {
                c = 0;
                switch(TOUPPER(fS[fi+i]))
                {
                    case 'A': if(TOUPPER(sS[j])=='T') c++;    break;
                    case 'C': if(TOUPPER(sS[j])=='G') c++;    break;
                    case 'G': if(TOUPPER(sS[j])=='C') c++;    break;
                    case 'T': if(TOUPPER(sS[j])=='A') c++;    break;
                }
                if(!c)
                {
                    j--;
                    continue;
                }
                mat += 2;
                if( (i>0) && (j<(n-1)) )
                {
                    switch(TOUPPER(fS[fi+i-1]))
                    {
                        case 'A': if(TOUPPER(sS[j+1])=='T') mat++;    break;
                        case 'C': if(TOUPPER(sS[j+1])=='G') mat++;    break;
                        case 'G': if(TOUPPER(sS[j+1])=='C') mat++;    break;
                        case 'T': if(TOUPPER(sS[j+1])=='A') mat++;    break;
                    }
                }
                if( (i<(n-1)) && (j>0) )
                {
                    switch(TOUPPER(fS[fi+i+1]))
                    {
                        case 'A': if(TOUPPER(sS[j-1])=='T') mat++;    break;
                        case 'C': if(TOUPPER(sS[j-1])=='G') mat++;    break;
                        case 'G': if(TOUPPER(sS[j-1])=='C') mat++;    break;
                        case 'T': if(TOUPPER(sS[j-1])=='A') mat++;    break;
                    }
                }
                j--;
            }
            break;
        default:
            printf("Bad ctype code = %d\n",ppPO->ctype);
            ERR("AlignedSeqWmatchScoreR","Bogus ctype code");
    }
    scR = RNUM(mat)/4.0;
    DB_PAIRLO DB_PrI("<< AlignedSeqBmatchScoreR %2.3f\n",scR);
    return(scR);
}