Next version of JABA
[jabaws.git] / binaries / src / tcoffee / t_coffee_source / util_analyse_constraints_list.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <math.h>
4 #include <stdarg.h>
5 #include <string.h>
6
7 #include "io_lib_header.h"
8 #include "util_lib_header.h"
9 #include "define_header.h"
10
11
12 void print_list(Constraint_list *CL)
13      {
14
15      fprintf ( stderr, "\nPRINT LIST");
16      output_list ( CL, stderr);
17      }
18 void save_full_list (Constraint_list *CL, char*fname)
19      {
20      FILE *fp;
21      fp=vfopen ( fname, "w");
22      fp=output_list ( CL, fp);
23      fclose ( fp);
24      }
25 FILE * output_list ( Constraint_list *CL, FILE *fp)
26      {
27      int a;
28      
29      fprintf ( fp, "\nPRINT LIST: %d Elements\n", CL->ne);
30      for ( a=0; a<CL->ne; a++)fp=output_pair(CL, a, fp);
31      fprintf (fp, "\n");
32      return fp;
33      }
34 FILE * output_pair (Constraint_list *CL,int p, FILE *fp)
35         {       
36         int a;
37         fprintf (fp, "\n");
38         for ( a=0; a<CL->entry_len; a++)
39                 {
40                 fprintf (fp, "%4d ", vread_clist(CL,p,a));
41                 }
42         return fp;
43         }
44 void print_pair (Constraint_list *CL,int p)
45         {       
46         int a;
47         fprintf ( stderr, "\n");
48         for ( a=0; a<CL->entry_len; a++)
49                 {
50                 fprintf ( stderr, "%d ", vread_clist(CL,p,a));
51                 }
52         fprintf ( stderr, "\n");
53         }
54
55 int** bin_list (Constraint_list *CL,int field, int Threshold)
56         {
57         int  a, c;
58         int max;
59         int **bin_list;
60         CLIST_TYPE x;
61         
62         max=return_max_constraint_list (CL, CONS);
63         
64         bin_list=declare_int (max+1, 5);
65         for (c=0,a=0; a<(CL->ne); a++)
66             if ( vread_clist(CL,a,field)!=UNDEFINED && vread_clist(CL,a,field)>Threshold )
67                 {
68                 x=vread_clist(CL,a,CONS);
69                 bin_list[x][0]=x;
70                 bin_list[x][1]++;
71                 bin_list[x][2]+=vread_clist(CL, a, field);
72                 c++;
73                 }
74         
75         for ( a=0; a<= max; a++)
76             {
77             if (bin_list[a][0]>0)
78                 {
79                 bin_list[a][3]=bin_list[a][2]/bin_list[a][1];
80                 bin_list[a][4]=(a==0)?0:(bin_list[a][3]/a);
81                 }
82             }
83
84         return bin_list;
85         }
86   
87 /*********************************COPYRIGHT NOTICE**********************************/
88 /*© Centro de Regulacio Genomica */
89 /*and */
90 /*Cedric Notredame */
91 /*Tue Oct 27 10:12:26 WEST 2009. */
92 /*All rights reserved.*/
93 /*This file is part of T-COFFEE.*/
94 /**/
95 /*    T-COFFEE is free software; you can redistribute it and/or modify*/
96 /*    it under the terms of the GNU General Public License as published by*/
97 /*    the Free Software Foundation; either version 2 of the License, or*/
98 /*    (at your option) any later version.*/
99 /**/
100 /*    T-COFFEE is distributed in the hope that it will be useful,*/
101 /*    but WITHOUT ANY WARRANTY; without even the implied warranty of*/
102 /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the*/
103 /*    GNU General Public License for more details.*/
104 /**/
105 /*    You should have received a copy of the GNU General Public License*/
106 /*    along with Foobar; if not, write to the Free Software*/
107 /*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/
108 /*...............................................                                                                                      |*/
109 /*  If you need some more information*/
110 /*  cedric.notredame@europe.com*/
111 /*...............................................                                                                                                                                     |*/
112 /**/
113 /**/
114 /*      */
115 /*********************************COPYRIGHT NOTICE**********************************/