Assignment 

Introduction
For this assignment, you will construct classes allowing the manipulation of RNA chain
(ribonucleic acid). The objectives of the assignment are:
• The use of inheritance. Specifically, you will need to implement a class that inherits from the
ArrayList class.
• The construction of method header comment.
In the following sections, we will describe the interactions that your software will have to offer,
the values it will evaluate, the outputs it will produce, the points that will be used to evaluate
your work and the delivery methods of your project.

Interactions
Here are the different steps of interaction that your software must follow:
1. Request an RNA chain.
2. Validate this string.
3. Display metrics.
4. Request a search request.
5. Validate the request.
6. Display the results of this query.
7. The program ends.
In steps 2 and 5, if an item is invalid, a descriptive error message is displayed and the program
ends immediately.

1: REQUEST AN RNA CHAIN.
Your software will ask the user for inputs an RNA string. The user will have to use the keyboard
in order to input a sequence of characters. For this step, you can not use the Clavier class seen
during inf1120. Use SCANNER.

2: VALIDATE THIS CHAIN.
The string of characters entered by the user must be composed exclusively of uppercase
characters. In addition, only characters ‘A’, ‘C’, ‘G’ and ‘U’ are accepted. The string must contain
at least 6 characters and the number of characters entered must be a multiple of 3. If at least
one of these rules is not verified, then an error message is displayed using the following
method call:
System.err.println (“Your message here.”);
Then the program ends using the following method call:
System.exit (n);
Replace the ‘n’ with an integer value that is not zero (0).

3: DISPLAY METRICS.
Then, your software must display metrics describing the RNA. An RNA is composed of
Nucleotides. Here is a brief description of the nucleotides we use.
Nucleotide
Nucleotides are basic molecules for the construction of RNA. We will use four nucleotides:
adenine (A), cytosine (C), guanine (G) and uracil (U). These molecules are composed of carbon
atoms, hydrogen, oxygen and nitrogen (azote in french). They also have a molar mass (masse
molaire in french) (g / mol). The following table gives the number of atoms that each nucleotide
contains with its molar mass:

Your software will have to calculate the total number of each type of atom that contains the
RNA entered by the user. It should also calculate the total molar mass for the RNA. For
example, the ACGUGC RNA contains 27 carbon atoms, 29 hydrogen atoms, 23 nitrogen (azote)
atoms, 6 oxygen atoms and a molar mass of 771.68 g / mol. Your software will then display
these values.

4: REQUESTS A RESEARCH REQUEST.
At this step, the software requests a search request from the user. The query is read from the
keyboard, as in step 1. This query indicates what the user wants to find in the RNA string.

5: VALIDATE THE REQUEST.
There are two possible types of queries, the software must recognize the type of query by
analyzing the characters entered:
a) The user enters one of the following words (the box is important): Ala, Arg, Asn, Asp, Cys,
Glu, Gln, Gly, His, Ile, Leu, Lys, Met, Phe, Pro, , Ser, Thr, Trp, Tyr, Val. In this case, the user
searches for an amino acid in the RNA.
b) The user enters a sequence of a capital letter. In this case, it must enter a number of letters
divisible by 3 and which is greater than zero (0). Only the following letters are allowed: A, B, C,
D, G, H, K, M, N, R, S, U, V, W, Y. In this case the user searches for a sequence of nucleotides in
RNA.
If there is an error in the query, then a relevant error message is displayed and the program
ends.

6: DISPLAY THE RESULTS OF THIS APPLICATION.
The software must then browse the RNA to find all occurrences of the element requested by
the user. You must display the position of the first nucleotide of each occurrence. The first
nucleotide of an RNA chain is at position 1.
a) For the first type of query, your software must find the occurrences of the requested amino
acid. An amino acid is represented by one (1) to six (6) instances of a sequence of three (3)
nucleotides.
Amino acid
In a nucleotide chain (RNA), the elements are divided into a sequence of three called codon.
Each codon represents a proteinogenic amino acid. The following table contains the 22 possible
amino acids with the different sequences that they represent. Note that some amino acids are
represented by several sequences.

For example, the ACGUCUUGCAGU RNA contains the amino acid Serat positions 4 and 10. It
should be noted that the possible results can be found only every three (3) nucleotides **
which means if the code is ACGUCU, the CGU is not an Arg because the actual aminoacids in
that sequence are ACG, then UCU.
b) For the second type of request, your software must find the occurrences of an RNA
subsequence. As for the first query, the possible results can only be found every three (3)
nucleotides. Some letters of the query represent a set of nucleotides. In this case, the
nucleotide present in the RNA must correspond to one of the nucleotides of the set.
IUPAC Codes
IUPAC (International Union of Pure and Applied Chemistry) has defined codes for grouping sets
of nucleotides. For example, the letter R represents an assembly containing an adenine and a
guanine. The following table contains these codes with their set.

Example, if the query entered is RYS, the code that we are looking for can be ACC, AUC, ACG,
AUG, GCC, GUC, GCG, or GUG, Because R can be A or G, Y can be C or U, etc..we need to look
for all combinations.

Instructions
1. The tp is to be done alone or in a team of two.
2. Your code must contain a class that inherits from the ArrayList class.
3. Comments:
at. Comment on the heading of each class and method. These comments should
contain a description of the method and the role of these parameters.
b. A line contains either a comment or a code, not both.
c. Use meaningful identifier names.
d. Use French (I will take care of translating)
4. Code:
a. No goto, no continue.
b. The breaks can only appear in the switches.
c. Only one return per method.
5. Indent your code. Make sure the indentation is done with spaces.

 Start of Assignment.rtf 

importjava.util.Scanner;

importjava.util.ArrayList;

public class Principale<E> extends ArrayList<E> {

private static final String Demande = “Veuillezentrerunechained’ARN. (Plz enter an ARN chain)”;

private static final String Erreur = “Erreur, entree incorrecte. (Error code)”;

static Scanner s = new Scanner(System.in);

public static void main(String[] args) {

String arn = Lecture();

System.out.println(Validation(arn));

}

public static String Lecture() {

System.out.println(Demande);

String arn = s.nextLine();

returnarn;

}

public static String Validation(String arn) {

booleanvalide = false;

while (valide == false) {

booleanverif = true;

for (int i = 0; i <arn.length(); i++) {

if (arn.charAt(i) != ‘A’ &&arn.charAt(i) != ‘C’ &&arn.charAt(i) != ‘G’ &&arn.charAt(i) != ‘U’) {

verif = false;

} // if

} // for

if ( verif&&arn.length() % 3 == 0 &&arn.length() >= 6) {

valide = true;

} else {

System.err.println(Erreur);

System.exit(1);

arn = Lecture();

}

} // while

returnarn;

}

publicint[] infoARN (String arn) {

int[] tab = new int[4];

for (int i = 0; i <arn.length(); i++) {

switch (arn.charAt(i)) {

case ‘A’ : tab[0]++; //l’indice 0 estreservéa la molecule A

break;

case ‘G’ : tab[1]++; //l’indice 1 est reservea la molecule G

break;

case ‘C’ : tab[2]++; // l’indice 2 est reserve a la molecule C

break;

case ‘U’ : tab[3]++; // l’indice 3 est reserve a la molecule U

break;

}//switch

}//for

return tab;

}//infoARN

} 

Solution 

Principale.java 

importjava.util.*;

public class Principale<E> extends ArrayList<E> {

private static final String Demande = “Enter”;//”Veuillezentrerunechained’ARN. (Plz enter an ARN chain)”;

private static final String Erreur = “Error code”;//”Erreur, entree incorrecte. (Error code)”;

private static Map<String, List<String>>aminoAcids = new HashMap<>(); // dictionary for amino acids abreviations

private static Map<String, List<String>>iupacCodes = new HashMap<>();// dictionary for IUPAC codes

static Scanner s = new Scanner(System.in);

public static void main(String[] args) {

initialise();

String arn = Lecture();

System.out.println(Validation(arn));

displayMetrics(arn);

String req = makeRequest();

int type = validateRequest(req);//get type to chose method for looking for coincidences

String requestResult = null;

if(type == 4) { // code 4 for error in request

System.err.println(Erreur);

System.exit(1);

}

else if(type == 1)

requestResult = method1(arn, req);

else if(type == 2)

requestResult = method2(arn, req);

else if(type == 3)

requestResult = method3(arn, req);

System.out.println(requestResult);

}

public static String makeRequest() {

System.out.println(Demande + ” request”);

String arn = s.nextLine();

returnarn;

}

public static intvalidateRequest(String req) { //check type of request

booleanisCorrect = false;

int type = 4; // error code

if(req.length() % 3 == 0) {

if(aminoAcids.containsKey(req)) {

type = 1;

}

else if(req.contains(“A”) || req.contains(“C”) || req.contains(“G”) || req.contains(“U”)) {

type = 2;

for(char c: req.toCharArray())

if(!String.valueOf(c).equals(“A”) && !String.valueOf(c).equals(“C”) && !String.valueOf(c).equals(“G”) && !String.valueOf(c).equals(“U”))

type = 4;

}

else {

req.toUpperCase();

type = 3;

for(char c: req.toCharArray()) {

if (!iupacCodes.containsKey(String.valueOf(c))) {

type = 4;

}

}

}

}

return type;

}

public static String method1(String arn, String req) { // method for amino acids

String result = “Resultat : “;

List<String> codons = aminoAcids.get(req);

System.out.println(req);

for (String s: codons)

System.out.println(s);

for (int i = 0; i <arn.length(); i+=3) {

String part = arn.substring(i, i + 3);

System.out.println(part);

if(codons.contains(part))

result += ” ” + (i+1);

}

if(result == “Resultat : “)

result += “aucun element trouve”;

return result;

}

public static String method2(String arn, String req) { // method for request that contain A, C, G, U

String result = “Resultat : “;

for (int i = 0; i <arn.length(); i+=3) {

String part = arn.substring(i, i + 3);

if(part.equals(req))

result += ” ” + (i+1);

}

if(result == “Resultat : “)

result += “aucun element trouve”;

return result;

}

public static String method3(String arn, String req) { // method for IUPAC codes

String result = “Resultat : “;

ArrayList<String>arnList = new ArrayList<>();

for(String s1: iupacCodes.get(String.valueOf(req.charAt(0)))) { //get list of amino acids by request value

for(String s2: iupacCodes.get(String.valueOf(req.charAt(1)))) {

for(String s3: iupacCodes.get(String.valueOf(req.charAt(2))))

arnList.add(s1 + s2 + s3);

}

}

for (int i = 0; i <arn.length(); i += 3) {

String part = arn.substring(i, i + 3);

if(arnList.contains(part))

result += ” ” + (i+1);

}

if(result == “Resultat : “)

result += “aucun element trouve”;

return result;

}

public static String Lecture() {

System.out.println(Demande + ” ARN: “);

String arn = s.nextLine();

returnarn;

}

public static String Validation(String arn) {

booleanvalide = false;

while (valide == false) {

booleanverif = true;

for (int i = 0; i <arn.length(); i++) {

if (arn.charAt(i) != ‘A’ &&arn.charAt(i) != ‘C’ &&arn.charAt(i) != ‘G’ &&arn.charAt(i) != ‘U’) {

verif = false;

} // if

} // for

if ( verif&&arn.length() % 3 == 0 &&arn.length() >= 6) {

valide = true;

} else {

System.err.println(Erreur);

System.exit(1);

arn = Lecture();

}

} // while

returnarn;

}

public static void displayMetrics(String arn) {

int a = 0, c = 0, g = 0, u = 0;

for (int i = 0; i <arn.length(); i++) {

if(arn.charAt(i) == ‘A’)

a++;

else if(arn.charAt(i) == ‘C’)

c++;

else if(arn.charAt(i) == ‘G’)

g++;

else if(arn.charAt(i) == ‘U’)

u++;

}

System.out.println(“Nombred’hydrogene: ” + (a*5 + c*5 + g*5 + u*4));

System.out.println(“Nombre de carbone: ” + (a*5 + c*4 + g*5 + u*4));

System.out.println(“Nombred’azote: ” + (a*5 + c*3 + g*5 + u*2));

System.out.println(“Nombred’oxygene: ” + (a*0 + c*1 + g*5 + u*2));

System.out.println(“Masse molaie: ” + (a*135.13 + c*111.10 + g*151.13 + u*112.09) + ” g/mol”);

}

publicint[] infoARN (String arn) {

int[] tab = new int[4];

for (int i = 0; i <arn.length(); i++) {

switch (arn.charAt(i)) {

case ‘A’ : tab[0]++; //l’indice 0 estreservé a la molecule A

break;

case ‘G’ : tab[1]++; //l’indice 1 est reserve a la molecule G

break;

case ‘C’ : tab[2]++; // l’indice 2 est reserve a la molecule C

break;

case ‘U’ : tab[3]++; // l’indice 3 est reserve a la molecule U

break;

}//switch

}//for

return tab;

}//infoARN

public static void initialise() { // initialise our dictionaries

ArrayList<String> codons = new ArrayList<>();

codons.add(“GCU”);

codons.add(“GCC”);

codons.add(“GCA”);

codons.add(“GCG”);

aminoAcids.put(“Ala”, codons);

codons = new ArrayList<>();

codons.add(“CGU”);

codons.add(“CGC”);

codons.add(“CGA”);

codons.add(“CGG”);

codons.add(“AGA”);

codons.add(“AGG”);

aminoAcids.put(“Arg”, codons);

codons = new ArrayList<>();

codons.add(“AAU”);

codons.add(“AAC”);

aminoAcids.put(“Asn”, codons);

codons = new ArrayList<>();

codons.add(“GAU”);

codons.add(“GAC”);

aminoAcids.put(“Asp”, codons);

codons = new ArrayList<>();

codons.add(“UGU”);

codons.add(“UGC”);

aminoAcids.put(“Cys”, codons);

codons = new ArrayList<>();

codons.add(“GAA”);

codons.add(“GAG”);

aminoAcids.put(“Glu”, codons);

codons = new ArrayList<>();

codons.add(“CAA”);

codons.add(“CAG”);

aminoAcids.put(“Gln”, codons);

codons = new ArrayList<>();

codons.add(“GGU”);

codons.add(“GGC”);

codons.add(“GGA”);

codons.add(“GGG”);

aminoAcids.put(“Gly”, codons);

codons = new ArrayList<>();

codons.add(“CAU”);

codons.add(“CAC”);

aminoAcids.put(“His”, codons);

codons = new ArrayList<>();

codons.add(“AUU”);

codons.add(“AUC”);

codons.add(“AUA”);

aminoAcids.put(“Ile”, codons);

codons = new ArrayList<>();

codons.add(“UUA”);

codons.add(“UUG”);

codons.add(“CUU”);

codons.add(“CUC”);

codons.add(“CUA”);

codons.add(“CUG”);

aminoAcids.put(“Leu”, codons);

codons = new ArrayList<>();

codons.add(“AAA”);

codons.add(“AAG”);

aminoAcids.put(“Lys”, codons);

codons = new ArrayList<>();

codons.add(“AUG”);

aminoAcids.put(“Met”, codons);

codons = new ArrayList<>();

codons.add(“UUU”);

codons.add(“UUC”);

aminoAcids.put(“Phe”, codons);

codons = new ArrayList<>();

codons.add(“CCU”);

codons.add(“CCC”);

codons.add(“CCA”);

codons.add(“CCG”);

aminoAcids.put(“Pro”, codons);

codons = new ArrayList<>();

codons.add(“UAG”);

aminoAcids.put(“Pyl”, codons);

codons = new ArrayList<>();

codons.add(“UGA”);

aminoAcids.put(“Sec”, codons);

codons = new ArrayList<>();

codons.add(“UCU”);

codons.add(“UCC”);

codons.add(“UCA”);

codons.add(“UCG”);

codons.add(“AGU”);

codons.add(“AGC”);

aminoAcids.put(“Ser”, codons);

codons = new ArrayList<>();

codons.add(“ACU”);

codons.add(“ACC”);

codons.add(“ACA”);

codons.add(“ACG”);

aminoAcids.put(“Thr”, codons);

codons = new ArrayList<>();

codons.add(“UGG”);

aminoAcids.put(“Trp”, codons);

codons = new ArrayList<>();

codons.add(“UAU”);

codons.add(“UAC”);

aminoAcids.put(“Tyr”, codons);

codons = new ArrayList<>();

codons.add(“GUU”);

codons.add(“GUC”);

codons.add(“GUA”);

codons.add(“GUG”);

aminoAcids.put(“Val”, codons);

ArrayList<String> ensemble = new ArrayList<>();

ensemble.add(“A”);

ensemble.add(“G”);

iupacCodes.put(“R”, ensemble);

ensemble = new ArrayList<>();

ensemble.add(“C”);

ensemble.add(“U”);

iupacCodes.put(“Y”, ensemble);

ensemble = new ArrayList<>();

ensemble.add(“C”);

ensemble.add(“G”);

iupacCodes.put(“S”, ensemble);

ensemble = new ArrayList<>();

ensemble.add(“A”);

ensemble.add(“U”);

iupacCodes.put(“W”, ensemble);

ensemble = new ArrayList<>();

ensemble.add(“G”);

ensemble.add(“U”);

iupacCodes.put(“K”, ensemble);

ensemble = new ArrayList<>();

ensemble.add(“A”);

ensemble.add(“C”);

iupacCodes.put(“M”, ensemble);

ensemble = new ArrayList<>();

ensemble.add(“C”);

ensemble.add(“G”);

ensemble.add(“U”);

iupacCodes.put(“B”, ensemble);

ensemble = new ArrayList<>();

ensemble.add(“A”);

ensemble.add(“G”);

ensemble.add(“U”);

iupacCodes.put(“D”, ensemble);

ensemble = new ArrayList<>();

ensemble.add(“A”);

ensemble.add(“C”);

ensemble.add(“U”);

iupacCodes.put(“H”, ensemble);

ensemble = new ArrayList<>();

ensemble.add(“A”);

ensemble.add(“C”);

ensemble.add(“G”);

iupacCodes.put(“V”, ensemble);

ensemble = new ArrayList<>();

ensemble.add(“A”);

ensemble.add(“C”);

ensemble.add(“G”);

ensemble.add(“U”);

iupacCodes.put(“N”, ensemble);

}

}