source: tags/arb-6.0/GDE/SUPPORT/varpos.c

Last change on this file was 11815, checked in by westram, 10 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.7 KB
Line 
1#include <stdlib.h>
2#include "Flatio.c"
3#define MAX(a,b) ((a)>(b)?(a):(b))
4 
5/*
6*       Varpos.c- An extremely simple program for showing which positions
7*       are varying in an alignment.  Use this as a model for other
8*       external functions.
9*
10*       Read in a flat file alignment, pass back an alignment color
11*       mask.
12*
13*       Copyright 1991/1992 Steven Smith, Harvard Genome lab.
14*
15*/ 
16
17main(ac,av)
18int ac; 
19char **av; 
20{
21        struct data_format data[10000];
22        int i,j,k,numseqs,rev = FALSE;
23        int maxlen = -99999,
24        score = 0,
25        minoffset = 99999;
26        char ch; 
27        if(ac>2) 
28        {
29                fprintf(stderr,"Usage %s [-rev]<gde_flat_file>gde_color_mask\n",                av[0]); 
30                exit(1); 
31        } 
32        if(ac == 2)
33                if(strcmp(av[1],"-rev") == 0) 
34                        rev = TRUE;
35
36        numseqs = ReadFlat(stdin,data,10000);
37
38        if(numseqs == 0)
39                exit(1);
40
41        for(j=0;j<numseqs;j++)
42        {
43                if(data[j].length+data[j].offset > maxlen)
44                        maxlen = data[j].length+data[j].offset;
45                if(data[j].offset < minoffset)
46                        minoffset = data[j].offset;
47        }
48
49        printf("length:%d\n",maxlen);
50        printf("offset:%d\n",minoffset);
51        printf("start:\n");
52        for(j=0;j<maxlen;j++)
53        {
54                int a=0,c=0,g=0,u=0;
55
56                for(k=0;k<numseqs;k++)
57                        if(data[k].length+data[k].offset > j)
58                        {
59                                if(j>data[k].offset)
60                                        ch=data[k].nuc[j-data[k].offset] | 32;
61                                else
62                                        ch = '-';
63
64                                if(ch=='a')a++;
65                                if(ch=='c')c++;
66                                if(ch=='g')g++;
67                                if(ch=='u')u++;
68                                if(ch=='t')u++;
69                        }
70
71                score=MAX(a,c);
72                score=MAX(score,g);
73                score=MAX(score,u);
74                if(a+c+g+u)
75                {
76                        if(rev)
77                                score=(score*6/(a+c+g+u)+8);
78                        else
79                                score=((8-score*6/(a+c+g+u))+8);
80                }
81                else
82                        score=8;
83                printf("%d\n",score);
84        }
85        exit(0);
86}
Note: See TracBrowser for help on using the repository browser.