Sequence *free_constraint_list (Constraint_list *CL) { Sequence *S; int a, b; Constraint_list *pCL; /*Prepare the selective freeing of the CL data structure: If the CL has been obtained from copy, every pointer that is identical to the parent CL (CL->pCL) will not be saved. */ if ( !CL)return NULL; else S=CL->S; if ( CL->copy_mode==SOFT_COPY && !CL->pCL) {vfree(CL); return S;} else if ( CL->copy_mode==SOFT_COPY) { pCL=CL->pCL; CL->residue_index=NULL; if ( CL->M ==pCL->M )CL->M=NULL; if (CL->start_index ==pCL->start_index )CL->start_index=NULL; if (CL->end_index ==pCL->end_index )CL->end_index=NULL; if ( CL->fp ==pCL->fp )CL->fp=NULL; if ( CL->matrices_list ==pCL->matrices_list )CL->matrices_list=NULL; if ( CL->STRUC_LIST ==pCL->STRUC_LIST )CL->STRUC_LIST=NULL; if ( CL->W ==pCL->W )CL->W=NULL; if ( CL->DM ==pCL->DM )CL->DM=NULL; if ( CL->ktupDM ==pCL->ktupDM )CL->ktupDM=NULL; if ( CL->translation ==pCL->translation )CL->translation=NULL; if ( CL->moca ==pCL->moca )CL->moca=NULL; if ( CL->Prot_Blast ==pCL->Prot_Blast )CL->Prot_Blast=NULL; if ( CL->DNA_Blast ==pCL->DNA_Blast )CL->DNA_Blast=NULL; if ( CL->Pdb_Blast ==pCL->Pdb_Blast )CL->Pdb_Blast=NULL; if ( CL->seq_for_quadruplet ==pCL->seq_for_quadruplet )CL->seq_for_quadruplet=NULL; if ( CL->TC ==pCL->TC )CL->TC=NULL; } /*End of selective freeing of the CL data structure*/ if ( CL->residue_index)free_arrayN(CL->residue_index, 3); if ( CL->M)free_int (CL->M, -1); if ( CL->fp)vfclose (CL->fp); if ( CL->matrices_list)free_char(CL->matrices_list,-1); if ( CL->start_index)free_int ( CL->start_index,-1); if ( CL->end_index)free_int ( CL->end_index,-1); if ( CL->STRUC_LIST)free_sequence ( CL->STRUC_LIST, (CL->STRUC_LIST)->nseq); if ( CL->W)free_weights (CL->W); CL->DM=free_distance_matrix (CL->DM); CL->ktupDM=free_distance_matrix (CL->ktupDM); if ( CL->translation)vfree(CL->translation); if ( CL->moca)free_moca (CL->moca); if ( CL->Prot_Blast)free_blast_param ( CL->Prot_Blast); if ( CL->DNA_Blast) free_blast_param ( CL->DNA_Blast); if ( CL->Pdb_Blast) free_blast_param ( CL->Pdb_Blast); if ( CL->TC) free_TC_param ( CL->TC); if (CL->seq_for_quadruplet)vfree (CL->seq_for_quadruplet); vfree(CL); return S; }
int main(int argc, char *argv[]) { int n,i,j,l; int intty; int outtty; char *mask, junk[20]; char **s; char **ss[4]; float *B; float **dm; Split *S; Union *U; char DistAlgorithm='H'; int nn[4]; short Do_Split=0, Do_Wards=0, Do_Stg=1, Do_4_Stg=0, Do_Nj=0, Do_Mat=0; float per_digit, per_gap; mask = vrna_alloc(sizeof(char)*54); strcpy (mask,"%ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); for (i=1; i<argc; i++) { if (argv[i][0]=='-') { switch ( argv[i][1] ) { case 'X': if (argv[i][2]=='\0') { Do_Stg = 1 ; break; } Do_Split = 0; Do_Wards = 0; Do_Stg = 0; Do_Nj = 0; for(j=2;j<strlen(argv[i]);j++) { switch(argv[i][j]) { case 's' : Do_Split = 1; break; case 'w' : Do_Wards = 1; break; case 'b' : Do_Stg = 1; break; case 'n' : Do_Nj = 1; break; case 'm' : Do_Mat = 1; break; default : usage(); } } break; case 'Q': Do_4_Stg = 1; break; case 'M': if(mask) { free(mask); mask = NULL; } switch (argv[i][2] ) { case '\0' : usage(); break; case 'a' : mask = vrna_alloc(sizeof(char)*54); strcpy(mask, "%ABCDEFGHIJKLMNOPQRSTUVWabcdefghijklmnopqrstuvwxyz"); if(argv[i][3]=='+') mask[0] = '~'; /* make case sensitive */ break; case 'u' : mask = vrna_alloc(sizeof(char)*28); strcpy(mask,"~ABCDEFGHIJKLMNOPQRSTUVW"); break; case 'l' : mask = vrna_alloc(sizeof(char)*28); strcpy(mask,"~abcdefghijklmnopqrstuvwxyz"); break; case 'c' : mask = vrna_alloc(sizeof(char)*12); strcpy(mask,"~1234567890"); break; case 'n' : mask = vrna_alloc(sizeof(char)*64); strcpy (mask, "%ABCDEFGHIJKLMNOPQRSTUVWabcdefghijklmnopqrstuvwxyz1234567890"); if(argv[i][3]=='+') mask[0] = '~'; /* make case sensitive */ break; case 'R' : /* RNA */ mask = vrna_alloc(sizeof(char)*10); strcpy(mask,"%GCAUgcau"); if(argv[i][3]=='+') mask[0] = '~'; /* make case sensitive */ break; case 'D' : /* DNA */ mask = vrna_alloc(sizeof(char)*10); strcpy (mask,"%GCATgcat"); if(argv[i][3]=='+') mask[0] = '~'; /* make case sensitive */ break; case 'A' : /* AMINOACIDS */ mask = vrna_alloc(sizeof(char)*42); strcpy(mask,"%ACDEFGHIKLMNPQRSTVWYacdefghiklmnpqrstvwy"); if(argv[i][3]=='+') mask[0] = '~'; /* make case sensitive */ break; case 'S' : /* SECONDARY STRUCTURES */ mask = vrna_alloc(sizeof(char)*6); strcpy(mask,"~().^"); break; case '%' : /* ARBITRARY ALPHABETS */ l = strlen(argv[i]); if(argv[i][l] == '+'){ mask = vrna_alloc(sizeof(char)*(l-2)); mask[0] = '~'; for(j=1;j<=l-4;j++) mask[j] = argv[i][j+2]; mask[l-3]='\0'; } if(argv[i][l] == '!'){ mask = vrna_alloc(sizeof(char)*(l-2)); mask[0] = '!'; for(j=1;j<=l-4;j++) mask[j] = argv[i][j+2]; mask[l-3]='\0'; } else { mask = vrna_alloc(sizeof(char)*(l-1)); mask[0] = '%'; for(j=1;j<=l-3;j++) mask[j] = argv[i][j+2]; mask[l-2]='\0'; } break; default : usage(); } break; case 'D' : /* choose algorithm */ switch(argv[i][2]) { case '\0' : usage(); break; case 'H' : DistAlgorithm = 'H'; break; case 'A' : DistAlgorithm = 'A'; if(argv[i][3]==',') { per_digit=-1.; sscanf(argv[i],"%[^,],%g",junk,&per_digit); if(per_digit<0.) usage(); per_gap = per_digit; Set_StrEdit_GapCosts(per_digit,per_gap); } break; case 'G' : DistAlgorithm = 'G'; if(argv[i][3]==',') { per_digit=-1.; per_gap =-1.; sscanf(argv[i]+4,"%f,%f",&per_digit,&per_gap); if((per_digit<0.)||(per_gap<0)) usage(); Set_StrEdit_GapCosts(per_digit,per_gap); } break; default: usage(); } break; case 'd' : /* choose distance matrix */ switch(argv[i][2]) { case 'D' : /* Dayhoff Distances */ case 'A' : /* Aminoacid Distance (Hofacker & Borstnik) */ case 'B' : /* RY distances for nucleotides */ case 'H' : /* Hogeweg's Distance for Secondary Structures */ case 'S' : /* Simple Distance (superfluous option) */ Set_StrEdit_CostMatrix(argv[i][2]); break; default : usage(); } break; default : usage(); } } } /* END PARSING OF COMMAND LINE */ intty = isatty(fileno(stdin)); outtty= isatty(fileno(stdout)); if(intty){ if(outtty) { printf("Input sequences; @ to mark end of input\n"); printf("%s%s\n", scale1, scale2); } else { fprintf(stderr,"Input sequences; @ to mark end of input\n"); fprintf(stderr,"%s%s\n", scale1, scale2); } } while ((s=read_sequence_list(&n,mask))!=NULL) { dm = NULL; if(Do_4_Stg) { ss[0] = s; nn[0] = n; for(i=1;i<4;i++) { ss[i] = read_sequence_list(&n,mask); if(ss[i]==NULL) vrna_message_error("read_sequences: wrong or insufficient data."); nn[i] = n; } printf_taxa_list(); B = statgeom4(ss,nn); printf_stg(B); SimplifiedBox(B,"box.ps"); /* This is preliminary !!! */ free(B); for(i=0;i<4;i++){ for(j=0;j<nn[i];j++) free(ss[i][j]); free(ss[i]); } /* free(ss); */ /* attempt to free a non-heap object */ } else { printf_taxa_list(); if(Do_Stg) { B = statgeom(s,n); if (B) { printf_stg(B); SimplifiedBox(B,"box.ps"); free(B); } } if((Do_Split)||(Do_Wards)||(Do_Nj)||(Do_Mat)) { switch(DistAlgorithm) { case 'H' : dm = Hamming_Distance_Matrix(s,n); printf("> %s\n","H (Hamming Distance)"); break; case 'A' : dm = StrEdit_SimpleDistMatrix(s,n); printf("> %s\n","A (Needleman-Wunsch Distance)"); break; case 'G' : dm = StrEdit_GotohDistMatrix(s,n); printf("> %s\n","G (Gotoh Distance)"); break; default: vrna_message_error("This can't happen."); } } if(Do_Split) { S = split_decomposition(dm); sort_Split(S); print_Split(S); free_Split(S); } if(Do_Wards) { U = wards_cluster(dm); printf_phylogeny(U,"W"); PSplot_phylogeny(U,"wards.ps","Ward's Method"); free(U); } if(Do_Nj) { U = neighbour_joining(dm); printf_phylogeny(U,"Nj"); PSplot_phylogeny(U,"nj.ps","Neighbor Joining"); free(U); } if(Do_Mat) printf_distance_matrix(dm); } if (dm!=NULL) free_distance_matrix(dm); for(i=0;i<n;i++) free(s[i]); free(s); } return 0; }