source: tags/arb-6.0/GDE/MAFFT/mafft-7.055-with-extensions/core/setdirection.c

Last change on this file was 10371, checked in by aboeckma, 11 years ago

updated mafft version. Added extensions (no svn ignore, yet)

File size: 2.4 KB
Line 
1#include "mltaln.h"
2
3#define DEBUG 0
4
5char *directionfile;
6
7void arguments( int argc, char *argv[] )
8{
9    int c;
10
11        inputfile = NULL;
12        directionfile = NULL;
13
14    while( --argc > 0 && (*++argv)[0] == '-' )
15        {
16        while ( (c = *++argv[0]) )
17                {
18            switch( c )
19            {
20                                case 'd':
21                                        directionfile = *++argv;
22                                        fprintf( stderr, "directionfile = %s\n", directionfile );
23                                        --argc;
24                                        goto nextoption;
25                                case 'i':
26                                        inputfile = *++argv;
27                                        fprintf( stderr, "inputfile = %s\n", inputfile );
28                                        --argc;
29                                        goto nextoption;
30                default:
31                    fprintf( stderr, "illegal option %c\n", c );
32                    argc = 0;
33                    break;
34            }
35                }
36                nextoption:
37                        ;
38        }
39    if( argc != 0 ) 
40    {
41        fprintf( stderr, "options: Check source file !\n" );
42        exit( 1 );
43    }
44}
45
46
47
48int main( int argc, char *argv[] )
49{
50        FILE *infp;
51        FILE *difp;
52        int nlenmin;
53        char **name;
54        char **seq;
55        char *tmpseq;
56        char line[100];
57        int *nlen;
58        int i;
59
60        arguments( argc, argv );
61
62        if( inputfile )
63        {
64                infp = fopen( inputfile, "r" );
65                if( !infp )
66                {
67                        fprintf( stderr, "Cannot open %s\n", inputfile );
68                        exit( 1 );
69                }
70        }
71        else
72                infp = stdin;
73
74        if( directionfile )
75        {
76                difp = fopen( directionfile, "r" );
77                if( !difp )
78                {
79                        fprintf( stderr, "Cannot open %s\n", directionfile );
80                        exit( 1 );
81                }
82        }
83        else
84        {
85                fprintf( stderr, "Give directionfile!\n" );
86        }
87
88
89        dorp = NOTSPECIFIED;
90        getnumlen_casepreserve( infp, &nlenmin );
91
92        fprintf( stderr, "%d x %d - %d %c\n", njob, nlenmax, nlenmin, dorp );
93
94        seq = AllocateCharMtx( njob, nlenmax+1 );
95        tmpseq = AllocateCharVec( MAX( B, nlenmax )+1 );
96        name = AllocateCharMtx( njob, B+1 );
97        nlen = AllocateIntVec( njob );
98
99        readData_pointer_casepreserve( infp, name, nlen, seq );
100
101        for( i=0; i<njob; i++ )
102        {
103                fgets( line, 99, difp );
104                if( line[0] != '_' )
105                {
106                        fprintf( stderr, "Format error!\n" );
107                        exit( 1 );
108                }
109                if( line[1] == 'R' )
110                {
111                        sreverse( tmpseq, seq[i] );
112                        strcpy( seq[i], tmpseq );
113
114                        strncpy( tmpseq, name[i]+1, B-3 );
115                        tmpseq[B-3] = 0;
116                        strcpy( name[i]+1, "_R_" );
117                        strcpy( name[i]+4, tmpseq );
118                }
119                else if( line[1] == 'F' )
120                {
121                        ;
122                }
123                else
124                {
125                        fprintf( stderr, "Format error!\n" );
126                        exit( 1 );
127                }
128        }
129
130
131        for( i=0; i<njob; i++ )
132        {
133                fprintf( stdout, ">%s\n", name[i]+1 );
134                fprintf( stdout, "%s\n", seq[i] );
135        }
136
137        free( nlen );
138        FreeCharMtx( seq );
139        FreeCharMtx( name );
140        free( tmpseq );
141
142        return( 0 );
143}
Note: See TracBrowser for help on using the repository browser.