NCBI C++ ToolKit
inputs.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: inputs.cpp 33815 2007-05-04 17:18:18Z kazimird $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Richard Desper
27 *
28 * File Description: inputs.cpp
29 *
30 * A part of the Miminum Evolution algorithm
31 *
32 */
33 
34 #include <ncbi_pch.hpp>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <math.h>
38 #include "fastme.h"
39 #include "graph.h"
40 
42 BEGIN_SCOPE(fastme)
43 
44 boolean leaf(meNode *v);
45 
47 
48 void compareSets(meTree *T, meSet *S, FILE *ofile)
49 {
50  meEdge *e;
51  meNode *v,*w;
52  meSet *X;
54  while (NULL != e)
55  {
56  v = e->head;
57  for(X = S; NULL != X; X = X->secondNode)
58  {
59  w = X->firstNode;
60  if (0 == strcmp(v->label,w->label))
61  {
62  v->index2 = w->index2;
63  w->index2 = -1;
64  break;
65  }
66  }
67  e = depthFirstTraverse(T,e);
68  }
69  v = T->root;
70  for(X = S; NULL != X; X = X->secondNode)
71  {
72  w = X->firstNode;
73  if (0 == strcmp(v->label,w->label))
74  {
75  v->index2 = w->index2;
76  w->index2 = -1;
77  break;
78  }
79  }
80  if (-1 == v->index2)
81  {
82  fprintf(stderr,"Error leaf %s in meTree not in distance matrix.\n",v->label);
84 }
86  while (NULL != e)
87  {
88  v = e->head;
89  if ((leaf(v)) && (-1 == v->index2))
90  {
91  fprintf(stderr,"Error leaf %s in meTree not in distance matrix.\n",v->label);
93  }
94  e = depthFirstTraverse(T,e);
95  }
96  for(X = S; NULL != X; X = X->secondNode)
97  if (X->firstNode->index2 > -1)
98  {
99  fprintf(ofile,"(v1:0.0)v2;");
100  fclose(ofile);
101  fprintf(stderr,"Error meNode %s in matrix but not a leaf in tree.\n",X->firstNode->label);
103  }
104 }
105 
106 void freeMatrix(double **D, int size)
107 {
108  int i;
109  for(i=0;i<size;i++)
110  free(D[i]);
111  free(D);
112 }
113 
114 double **loadMatrix(double **table_in, char **labels, int *size_in, meSet *S)
115 {
116 /* char nextString[MAX_EVENT_NAME]; */
117  meNode *v;
118  double **table;
119  int *size;
120  int i,j;
121 
122  size = size_in;
123  if ((*size < 0) || (*size > MAXSIZE))
124  {
125  printf("Problem inputting size.\n");
127  }
128  table = (double **) malloc(*size*sizeof(double *));
129  for(i=0;i<*size;i++)
130  {
131  j = 0;
132  table[i] = (double *) malloc(*size*sizeof(double));
133 /* if (!(fscanf(ifile,"%s",nextString))) */
134 /* { */
135 /* fprintf(stderr,"Error loading label %d.\n",i); */
136 /* exit(EXIT_FAILURE); */
137 /* } */
138 /* v = makeNewNode(nextString,-1); */
139  v = makeNewNode(labels[i],-1);
140  v->index2 = i;
141  S = addToSet(v,S);
142  while (j < *size)
143  {
144 /* if (!(fscanf(ifile,"%s",nextString))) */
145 /* { */
146 /* fprintf(stderr,"Error loading (%d,%d)-entry.\n",i,j); */
147 /* exit(EXIT_FAILURE); */
148 /* } */
149 /* table[i][j++] = atof(nextString); */
150  table[i][j] = table_in[i][j];
151  j++;
152  }
153  }
154  return(table);
155 }
156 
157 double **loadMatrixOLD(FILE *ifile, int *size, meSet *S)
158 {
159  char nextString[MAX_EVENT_NAME];
160  meNode *v;
161  double **table;
162  int i,j;
163  if (!(fscanf(ifile,"%s",nextString)))
164  {
165  fprintf(stderr,"Error loading input matrix.\n");
167  }
168  *size = atoi(nextString);
169  if ((*size < 0) || (*size > MAXSIZE))
170  {
171  printf("Problem inputting size.\n");
173  }
174  table = (double **) malloc(*size*sizeof(double *));
175  for(i=0;i<*size;i++)
176  {
177  j = 0;
178  table[i] = (double *) malloc(*size*sizeof(double));
179  if (!(fscanf(ifile,"%s",nextString)))
180  {
181  fprintf(stderr,"Error loading label %d.\n",i);
183  }
184  v = makeNewNode(nextString,-1);
185  v->index2 = i;
186  S = addToSet(v,S);
187  while (j < *size)
188  {
189  if (!(fscanf(ifile,"%s",nextString)))
190  {
191  fprintf(stderr,"Error loading (%d,%d)-entry.\n",i,j);
193  }
194  table[i][j++] = atof(nextString);
195  }
196  }
197  return(table);
198 }
199 
201 {
202  meEdge *e;
204  while (NULL != e)
205  {
206  if (leaf(e->head))
207  e->bottomsize = 1;
208  else
210  + e->head->rightEdge->bottomsize;
211  e->topsize = (T->size + 2)/2 - e->bottomsize;
212  e = depthFirstTraverse(T,e);
213  }
214 }
215 
216 
217 END_SCOPE(fastme)
#define T(s)
Definition: common.h:230
#define MAXSIZE
Definition: fastme.h:84
#define EXIT_FAILURE
Definition: fastme.h:73
#define MAX_EVENT_NAME
Definition: fastme.h:43
meSet * addToSet(meNode *v, meSet *X)
Definition: graph.cpp:60
meNode * makeNewNode(const char *label, int i)
Definition: graph.cpp:164
#define NULL
Definition: ncbistd.hpp:225
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
void freeMatrix(double **D, int size)
Definition: inputs.cpp:106
void partitionSizes(meTree *T)
Definition: inputs.cpp:200
void compareSets(meTree *T, meSet *S, FILE *ofile)
Definition: inputs.cpp:48
boolean leaf(meNode *v)
Definition: graph.cpp:44
double ** loadMatrix(double **table_in, char **labels, int *size_in, meSet *S)
Definition: inputs.cpp:114
double ** loadMatrixOLD(FILE *ifile, int *size, meSet *S)
Definition: inputs.cpp:157
meEdge * depthFirstTraverse(meTree *T, meEdge *e)
Definition: traverse.cpp:65
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
exit(2)
int i
#define S(x, n)
const struct ncbi::grid::netcache::search::fields::SIZE size
int strcmp(const char *str1, const char *str2)
Definition: odbc_utils.hpp:160
Definition: graph.h:84
int topsize
Definition: graph.h:89
struct meNode * head
Definition: graph.h:87
int bottomsize
Definition: graph.h:88
Definition: graph.h:74
struct meEdge * rightEdge
Definition: graph.h:79
int index2
Definition: graph.h:81
char label[50]
Definition: graph.h:75
struct meEdge * leftEdge
Definition: graph.h:77
Definition: graph.h:102
struct meSet * secondNode
Definition: graph.h:104
struct meNode * firstNode
Definition: graph.h:103
Definition: graph.h:94
void free(voidpf ptr)
voidp malloc(uInt size)
Modified on Sat Dec 09 04:46:30 2023 by modify_doxy.py rev. 669887