Mercurial > repos > nick > duplex
comparison mafft/core/setdirection.c @ 18:e4d75f9efb90 draft
planemo upload commit b'4303231da9e48b2719b4429a29b72421d24310f4\n'-dirty
author | nick |
---|---|
date | Thu, 02 Feb 2017 18:44:31 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:836fa4fe9494 | 18:e4d75f9efb90 |
---|---|
1 #include "mltaln.h" | |
2 | |
3 #define DEBUG 0 | |
4 | |
5 char *directionfile; | |
6 static int show_R_ = 1; | |
7 | |
8 void arguments( int argc, char *argv[] ) | |
9 { | |
10 int c; | |
11 | |
12 inputfile = NULL; | |
13 directionfile = NULL; | |
14 show_R_ = 1; | |
15 | |
16 while( --argc > 0 && (*++argv)[0] == '-' ) | |
17 { | |
18 while ( (c = *++argv[0]) ) | |
19 { | |
20 switch( c ) | |
21 { | |
22 case 'd': | |
23 directionfile = *++argv; | |
24 fprintf( stderr, "directionfile = %s\n", directionfile ); | |
25 --argc; | |
26 goto nextoption; | |
27 case 'i': | |
28 inputfile = *++argv; | |
29 fprintf( stderr, "inputfile = %s\n", inputfile ); | |
30 --argc; | |
31 goto nextoption; | |
32 case 'r': | |
33 show_R_ = 0; | |
34 break; | |
35 default: | |
36 fprintf( stderr, "illegal option %c\n", c ); | |
37 argc = 0; | |
38 break; | |
39 } | |
40 } | |
41 nextoption: | |
42 ; | |
43 } | |
44 if( argc != 0 ) | |
45 { | |
46 fprintf( stderr, "options: Check source file !\n" ); | |
47 exit( 1 ); | |
48 } | |
49 } | |
50 | |
51 | |
52 | |
53 int main( int argc, char *argv[] ) | |
54 { | |
55 FILE *infp; | |
56 FILE *difp; | |
57 int nlenmin; | |
58 char **name; | |
59 char **seq; | |
60 char *tmpseq; | |
61 char line[100]; | |
62 int *nlen; | |
63 int i; | |
64 | |
65 arguments( argc, argv ); | |
66 | |
67 if( inputfile ) | |
68 { | |
69 infp = fopen( inputfile, "r" ); | |
70 if( !infp ) | |
71 { | |
72 fprintf( stderr, "Cannot open %s\n", inputfile ); | |
73 exit( 1 ); | |
74 } | |
75 } | |
76 else | |
77 infp = stdin; | |
78 | |
79 if( directionfile ) | |
80 { | |
81 difp = fopen( directionfile, "r" ); | |
82 if( !difp ) | |
83 { | |
84 fprintf( stderr, "Cannot open %s\n", directionfile ); | |
85 exit( 1 ); | |
86 } | |
87 } | |
88 else | |
89 { | |
90 fprintf( stderr, "Give directionfile!\n" ); | |
91 } | |
92 | |
93 | |
94 dorp = NOTSPECIFIED; | |
95 getnumlen_casepreserve( infp, &nlenmin ); | |
96 | |
97 fprintf( stderr, "%d x %d - %d %c\n", njob, nlenmax, nlenmin, dorp ); | |
98 | |
99 seq = AllocateCharMtx( njob, nlenmax+1 ); | |
100 tmpseq = AllocateCharVec( MAX( B, nlenmax )+1 ); | |
101 name = AllocateCharMtx( njob, B+1 ); | |
102 nlen = AllocateIntVec( njob ); | |
103 | |
104 readData_pointer_casepreserve( infp, name, nlen, seq ); | |
105 | |
106 for( i=0; i<njob; i++ ) | |
107 { | |
108 fgets( line, 99, difp ); | |
109 if( line[0] != '_' ) | |
110 { | |
111 fprintf( stderr, "Format error!\n" ); | |
112 exit( 1 ); | |
113 } | |
114 if( line[1] == 'R' ) | |
115 { | |
116 sreverse( tmpseq, seq[i] ); | |
117 strcpy( seq[i], tmpseq ); | |
118 | |
119 strncpy( tmpseq, name[i]+1, B-3 ); | |
120 tmpseq[B-3] = 0; | |
121 if( show_R_ ) | |
122 { | |
123 strcpy( name[i]+1, "_R_" ); | |
124 strcpy( name[i]+4, tmpseq ); | |
125 } | |
126 else | |
127 { | |
128 strcpy( name[i]+1, tmpseq ); | |
129 } | |
130 } | |
131 else if( line[1] == 'F' ) | |
132 { | |
133 ; | |
134 } | |
135 else | |
136 { | |
137 fprintf( stderr, "Format error!\n" ); | |
138 exit( 1 ); | |
139 } | |
140 } | |
141 | |
142 | |
143 for( i=0; i<njob; i++ ) | |
144 { | |
145 fprintf( stdout, ">%s\n", name[i]+1 ); | |
146 fprintf( stdout, "%s\n", seq[i] ); | |
147 } | |
148 | |
149 free( nlen ); | |
150 FreeCharMtx( seq ); | |
151 FreeCharMtx( name ); | |
152 free( tmpseq ); | |
153 | |
154 return( 0 ); | |
155 } |