help with arrays and functions program

I'm writing this program for a class, Im suppose to be passing arrays through functions. I've been staring at it for FAR too long and forget why I did some of the things I did, and nothing is passing to one another. I could really use some help...

the input file contains
"
ATGCCTGAAGCTTGTGAAGCTAATGATCATGCTCCTCCTATTAATGAATCTTCTTGA
ATACAGGCACCTCCTATTAATGAATCTTCTGCTAATGATCCTGAAGCTTGTGAATGA
ATGCATGCTCCTCCTATTAATGAATCTTCTGCTAATGATCCTGAAGCTTGTGAATGA
"


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
  //
// input file to DNA original array
// send array to function to make uppercase
// make a compliment of DNA
//      change
//      (T -> A, A -> T, G -> C, C -> G)
// send compliment to to fucntion transcrition
//      change
//      (T -> A, A -> U, G -> C, C -> G)
// send transcription to function translation
//      use if else to check for start codon
//      compare array triplets to codons and change them
//      break when stop codon is reached
// output to file

#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
using namespace std;

void uppercase(char original[], int& length);
void DNAcompliment(char original[], char compliment[], int& length);
void transcription(char compliment[], char mRNA[], int& length);

bool translation(char mRNA[], char codons[], int& length);


int main(int argc, char *argv[]){
    
    ifstream in_stream;
    
    bool debug = true;
    const int N = 82;
    int length = 0, nlength = 0;
    char DNA_original[N] = {'\0'}, compliment[N] = {'\0'}, mRNA[N] = {'\0'}, amino_acid[N] = {'\0'};
    
    in_stream.open(argv[1]);
    if (in_stream.fail())
    cout << "File failed to open. \n";
    
    ofstream out_stream(argv[2]);
    
    while (in_stream >> DNA_original) {
        length = strlen(DNA_original);
        
        uppercase(DNA_original, length);
        if (debug) { cout << "original= " << DNA_original << endl; }
        
        DNAcompliment(DNA_original, compliment, length);
        if (debug) { cout << "DNAcompliment= " << DNAcompliment << endl; }
        
        transcription(compliment, mRNA, length);
        if (debug) { cout << "Transcription= " << transcription << endl; }
        
        translation(mRNA, amino_acid, length);
        if (debug) { cout << "Translation= " << translation << endl; }
        
        out_stream << "strand DNA=" << DNA_original;
        out_stream << ", strand mRNA=";
        
        for (int i = 0; i < length; i++){
            out_stream << mRNA[i];
        }
        
        out_stream << ", amino_acid=";
        nlength = strlen(amino_acid);
        
        for (int i = 0; i < nlength; i++){
            out_stream << amino_acid[i];
        }
        
        out_stream << endl;
        DNA_original[N] = '\0';
        compliment[N] = '\0';
        amino_acid[N] = '\0';
        mRNA[N] = '\0';
    }
    
    in_stream.close();
    out_stream.close();
    return 0;
}


void uppercase(char original[], int& length){
    for (int i = 0; i < length; i++) {
        original[i] = toupper(original[i]);
    }
}

void DNAcompliment(char original[], char compliment[], int& length){
    for (int i = 0; i < length; i++)
        switch (original[i]){
            case 'T': compliment[i] = 'A'; break;
            case 'A': compliment[i] = 'T'; break;
            case 'G': compliment[i] = 'C'; break;
            case 'C': compliment[i] = 'G'; break;
            default: compliment[i] = '?';
        }
}

void transcription(char compliment[], char mRNA[], int& length){
    for (int i = 0; i < length; i++)
        switch (compliment[i]){
            case 'T': compliment[i] = 'A'; break;
            case 'A': compliment[i] = 'U'; break;
            case 'G': compliment[i] = 'C'; break;
            case 'C': compliment[i] = 'G'; break;
            default: compliment[i] = '?';
        }
}

bool translation(char mRNA[], char amino_acid[], int& length){
    bool var = true;
    for (int i = 0; i < length; i++){
        if (mRNA[i] == 'A' && mRNA[i+1] == 'U' && mRNA[i+2] == 'G'){
            for (int i = 3, account = 0; i < length; i+=3, account++){
                if (mRNA[i] == 'G' && mRNA[i+1] == 'C' && mRNA[i+2] == 'U'){
                amino_acid[account] = 'A';
                }
                else if (mRNA[i] == 'C' && mRNA[i+1] == 'A' && mRNA[i+2] == 'U'){
                    amino_acid[account] = 'H';
                }
                else if (mRNA[i] == 'A' && mRNA[i+1] == 'A' && mRNA[i+2] == 'U'){
                    amino_acid[account] = 'I';
                }
                else if (mRNA[i] == 'C' && mRNA[i+1] == 'C' && mRNA[i+2] == 'U'){
                    amino_acid[account] = 'P';
                }
                else if (mRNA[i] == 'G' && mRNA[i+1] == 'A' && mRNA[i+2] == 'U'){
                    amino_acid[account] = 'D';
                }
                else if (mRNA[i] == 'A' && mRNA[i+1] == 'A' && mRNA[i+2] == 'U'){
                    amino_acid[account] = 'N';
                }
                else if (mRNA[i] == 'G' && mRNA[i+1] == 'A' && mRNA[i+2] == 'A'){
                    amino_acid[account] = 'E';
                }
                else if (mRNA[i] == 'U' && mRNA[i+1] == 'C' && mRNA[i+2] == 'U'){
                    amino_acid[account] = 'S';
                }
                else if (mRNA[i] == 'U' && mRNA[i+1] == 'G' && mRNA[i+2] == 'U'){
                    amino_acid[account] = 'S';
                }
                else if (mRNA[i] == 'U' && mRNA[i+1] == 'G' && mRNA[i+2] == 'A'){
                    break;
                }
                else cout << '?';
            }
            break;
        }
    }
    return (true);
}
Topic archived. No new replies allowed.