source: tags/initial/GDE/LOOPTOOL/ReadData.c

Last change on this file was 2, checked in by oldcode, 23 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1#include <xview/xview.h>
2#include <xview/canvas.h>
3#include <stdio.h>
4#include <string.h>
5#include <malloc.h>
6#include "loop.h"
7#include "globals.h"
8
9ReadSeqSet(dataset)
10DataSet *dataset;
11{
12        int i,j,taxanum=0,len,pos,flag=TRUE;
13        char inlin[132],temp[132],seq[20000],*name;
14
15        for(i=0;fgets(inlin,132,infile);i++)
16        {
17                for(;(pos=Find("LOCUS",inlin)) == -1 && flag;
18                        flag = (int)fgets(inlin,132,infile));
19                sscanf((inlin+5+pos),"%s",temp);
20                name=malloc(strlen(temp));
21                strcpy(name,temp);
22                len=0;
23                for(;flag && Find("ORIGIN",inlin) == -1;
24                        flag =(int)fgets(inlin,132,infile));
25                for(fgets(inlin,132,infile);
26                        flag && Find("//",inlin)== -1;
27                        flag = (int)fgets(inlin,132,infile))
28                {
29                        for(j=0;inlin[j]!='\0';j++)
30                                if(inlin[j] != ' ' && inlin[j]!='\t'
31                                 && (inlin[j] <'0' || inlin[j] >'9') &&
32                                inlin[j] != '\n')
33                                        seq[len++]=inlin[j];
34                }
35                seq[len]='\0';
36                if(Find(temp,"HELIX")!= -1 ||
37                        Find("Helix",temp)!= -1 ||
38                        Find(temp,"helix")!= -1 )
39                {
40                        dataset->helix.name=name;
41                        ErrorOut("malloc failed in ReadData",
42                        dataset ->helix.sequence = malloc(len));
43                        strcpy(dataset->helix.sequence,seq);
44                        dataset->helix.len=len;
45                }
46                else
47                {
48                        ErrorOut("malloc failed in ReadData",
49                        dataset ->taxa[taxanum].sequence = malloc(len));
50                        strcpy(dataset->taxa[taxanum].sequence,seq);
51                        dataset->taxa[taxanum].len=len;
52                        dataset->taxa[taxanum++].name=name;
53                }
54        }
55        dataset->siz = taxanum;
56        dataset->len = dataset -> helix.len;
57}
58
59Find(a,b)
60char a[],b[];
61{
62        int i,j,range,fail=TRUE;
63        range=strlen(b)-strlen(a);
64        if(range<0)
65                return(-1);
66        for(j=0;j<=range && fail;j++)
67        {
68                fail=FALSE;
69                for(i=0;(a[i] != '\0') && (fail == FALSE);i++)
70                        if (a[i] != b[j+i])
71                                fail=TRUE;
72        }
73        return(fail ? -1:j);
74}
75
76
77
78Translate(dset,seqnum,blist,seqlen)
79DataSet *dset;
80Base **blist;
81int seqnum,*seqlen;
82{
83        int pos=0,j,pair;
84        char *helix,*seq;
85        int stk[10000],stkp;
86
87        Mxdepth = 0;
88        *seqlen=dset->taxa[seqnum].len;
89        ErrorOut("Error in malloc (Translate)",
90        (*blist)=(Base*)calloc(*seqlen, sizeof(Base)));
91        helix=dset->helix.sequence;
92        seq=dset->taxa[seqnum].sequence;
93        seqname=dset->taxa[seqnum].name;
94        for(j=0;j<dset->taxa[seqnum].len;j++)
95                if((seq[j]!='-') && (seq[j] != '.'))
96                {
97                        (*blist)[pos].pair= -1;
98                        if(j<dset->len)
99                        {
100                                (*blist)[pos].depth=stkp;
101                                if(helix[j] =='[')
102                                {
103                                        stk[stkp++]=pos;
104                                        (*blist)[pos].depth=stkp;
105                                }
106                                if(helix[j] == ']')
107                                {
108                                        pair=stk[--stkp];
109                                        (*blist)[pair].pair=pos;
110                                        (*blist)[pos].pair=pair;
111                                }
112                                if(stkp>Mxdepth)
113                                        Mxdepth = stkp;
114                        }
115                        (*blist)[pos].known=FALSE;
116                        (*blist)[pos].dir=CW;
117                        (*blist)[pos].attr=0;
118                        (*blist)[pos].size=9;
119                        (*blist)[pos].dforw.pair= -1;
120                        (*blist)[pos].dback.pair= -1;
121                        (*blist)[pos].pos=NULL;
122                        (*blist)[pos].posnum= -1;
123                        (*blist)[pos].rel_loc=j;
124                        (*blist)[pos++].nuc=seq[j];
125                }
126        (*blist)[0].x=0.0;
127        (*blist)[0].y=0.0;
128        (*blist)[0].known=TRUE;
129        (*blist)[pos-1].x=3.0;
130        (*blist)[pos-1].y=0.0;
131        (*blist)[pos-1].known=TRUE;
132       
133        *seqlen=pos;
134        for(j=19;j<pos;j+=20)
135        {
136                baselist[j].label = (Label*)malloc(sizeof(Label));
137                baselist[j].label->dist = 1.5;
138                baselist[j].label->distflag = TRUE;
139                sprintf(baselist[j].label->text,"%d",j+1);
140                baselist[j].attr |= BOLD;
141        }
142        baselist[0].label = (Label*)malloc(sizeof(Label));
143        baselist[0].label->dist = 1.5;
144        baselist[0].label->distflag = TRUE;
145        sprintf(baselist[0].label->text,"%d",1);
146        baselist[0].attr |= BOLD;
147
148        ddepth = Mxdepth+5;
149        return;
150}
Note: See TracBrowser for help on using the repository browser.