1 /* FASTAtoText.c FASTA to Text
3 Copyright 2004, Wong Chi Kwong, all rights reserved.
5 This module convert FASTA DNA format to plain text format.
7 This software may be used freely for any purpose. However, when distributed,
8 the original source must be clearly stated, and, when the source code is
9 distributed, the copyright notice must be retained and any alterations in
10 the code must be clearly marked. No warranty is given regarding the quality
16 #include "TypeNLimit.h"
20 int main(int argc
, char** argv
) {
27 char dna
[4] = {'A', 'C', 'G', 'T'};
29 if (argc
!= 3 && argc
!= 4) {
30 fprintf(stderr
, "%s <input> <output>\n", argv
[0]);
31 fprintf(stderr
, "%s <input> <output> a\n", argv
[0]);
32 fprintf(stderr
, "%s <input> <output> n\n", argv
[0]);
33 fprintf(stderr
, "%s <input> <output> r\n", argv
[0]);
36 inputFile
= (FILE*)fopen64(argv
[1], "r");
37 if (inputFile
== NULL
) {
38 fprintf(stderr
, "Input file not exists!\n");
41 outputFile
= (FILE*)fopen64(argv
[2], "r");
42 if (outputFile
!= NULL
) {
43 fprintf(stderr
, "Output file exists!\n");
46 outputFile
= (FILE*)fopen64(argv
[2], "wb");
50 for (c
=0; c
<256; c
++) {
51 uppercase
[c
] = (char)c
;
53 for (c
='a'; c
<='z'; c
++) {
54 uppercase
[c
] = (char)c
+ 'A' - 'a';
56 for (c
=0; c
<256; c
++) {
57 lowercase
[c
] = (char)c
;
59 for (c
='A'; c
<='Z'; c
++) {
60 lowercase
[c
] = (char)c
+ 'a' - 'A';
64 while (c
== '\n' || c
== '\r') {
68 while (c
!= '\n' && c
!= '\r' && c
!= EOF
) {
71 while (c
== '\n' || c
== '\r') {
77 if (argc
== 4 || (c
!= 'n' && c
!= 'N')) {
78 if ((c
== 'n' || c
== 'N') && (argc
== 4 && argv
[3][0] == 'a')) {
80 fputc('a', outputFile
);
82 fputc('A', outputFile
);
85 if ((c
== 'n' || c
== 'N') && (argc
== 4 && argv
[3][0] == 'r')) {
87 fputc(lowercase
[dna
[rand() % 4]], outputFile
);
89 fputc(uppercase
[dna
[rand() % 4]], outputFile
);
97 while (c
== '\n' || c
== '\r') {
101 while (c
!= '\n' && c
!= '\r' && c
!= EOF
) {
102 c
= fgetc(inputFile
);
104 while (c
== '\n' || c
== '\r') {
105 c
= fgetc(inputFile
);