oo Verizon LTE 6:08 AM 55% Done 3 of 3 CSCI392 (Fall 2015) Programming Project #
ID: 3769964 • Letter: O
Question
oo Verizon LTE 6:08 AM 55% Done 3 of 3 CSCI392 (Fall 2015) Programming Project #4 Due Friday, Dec 4th 11:59 PM A key element in many bioinformatics problems is the biological sequence. A biological sequence is just a list of characters chosen from some alphabet. Two of the common biological sequences are DNA (composed of the four characters A, C, G, and T) and RNA (composed of the four characters A. C, G, and U)in this project, you will implement some basic functionality for manipulating DNA and RNA sequences Project #4 is an extension of Project 3, You will be asked to handle 4 more user You will implement sequences using linked lists, storing one leter of the In addition to the linked lists of sequences, you will maintain a "sequence array sequence per linked list node which stores the various sequences. Commands that manipulate sequences will refer directly to entries in the sequence array. The sequence array will store the sequence type (RNA or DNA) and a pointer or other form of access to the linked list that stores the sequence itself. The type field should also be able to indicate that a given position in the sequence array is unused Many of the commands that you will process require you to create and delete inked-ist nodes All indexing (both for the sequence array and for positions in a sequence) will begin with position zero. It is mandatory that your inked-ist remain application independent Input and Output: The program will be invoked from the command-line as: bi04 array size> The name of the program is blo4. Command-file is the name of the input file that holds the commands to be processed by the program. The input for this project will consist of a series of commands (some with associated parameters, separated by spaces), one command for each line. You need not worry about checking for syntactic emors. That is, only the specified commands will appear in the fie, and the specified parameters will always appear. However, you must check for logical errors. These include attempts to access out-of bounds positions in the sequence array or in a sequence. The commands will be read from standard input, and the output from the commands will be written to standard output. The program should terminate after reading the EOF mark. The commands are as follows: (from Hw3) insert pos type sequenceExplanation / Answer
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
class LL
{
char CH;
LL next;
public LL()
{
CH=' ';
next=null;
}
public LL(char ch)
{
CH=ch;
next=null;
}
public void setNext(LL n)
{
next=n;
}
public void setCH(char ch)
{
CH=ch;
}
public char getCH()
{
return CH;
}
public LL getNext()
{
return next;
}
}
public class BioInformatics {
public static void main(String[] args) {
// getting arraysize from command line arguement 0
int arraySize=Integer.parseInt(args[0]);
// getting filename from command line arguement 1
String filename=args[1];
//creating sequence array to store type and pointers to linked list
String SequenceArray[][]=new String[arraySize][arraySize];
for(int i=0;i<arraySize;i++)
{
SequenceArray[i][0]="";
}
//file read
File file = new File(filename);
try {
//
// Here we use the Scanner class to read file content line-by-line.
//
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
//
// From the above line of code we got a line from the file
// content. Now we want to split the line with comma as the
// charater delimiter.
//
Scanner lineScanner = new Scanner(line);
lineScanner.useDelimiter(",");
String cmd = lineScanner.next();
int pos=lineScanner.nextInt();
String type=lineScanner.next();
String seq=lineScanner.next();
if(cmd.equals("insert"))
{
insert(pos,type,seq,SequenceArray);
}
else if(cmd.equals("print"))
{
}
else if(cmd.equals("remove"))
{
}
else if(cmd.equals("copy"))
{
}
else if(cmd.equals("swap"))
{
}
else if(cmd.equals("transcribe"))
{
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
static boolean checkDNA(char str[])
{
boolean flag=true;
for(int i=0;i<str.length;i++)
{
if(!(str[i]=='A'||str[i]=='C'||str[i]=='G'||str[i]=='T'))
{
flag=false;
break;
}
}
return flag;
}
static boolean checkRNA(char str[])
{
boolean flag=true;
for(int i=0;i<str.length;i++)
{
if(!(str[i]=='A'||str[i]=='C'||str[i]=='G'||str[i]=='U'))
{
flag=false;
break;
}
}
return flag;
}
static void insert(int pos, String type, String seq,String SequenceArray[][])
{
SequenceArray[pos][0]=type;
LL start,ptr;
char Seq[]=seq.toCharArray();
if(checkDNA(Seq))
{
start=new LL(Seq[0]);
ptr=start.next;
for(int i=1;i<Seq.length;i++)
{
ptr=new LL(Seq[i]);
ptr=ptr.next;
}
SequenceArray[pos][1]=start.toString();
}
}
static void print(String SequenceArray[][])
{
for(int i=0;i<SequenceArray.length;i++)
{
if(!(SequenceArray[i][0].equals("")))
{
System.out.println("Sequence "+i);
System.out.println("Type: "+SequenceArray[i][0]);
System.out.println("Representation: ");
int x=Integer.parseInt(SequenceArray[i][1]);
LL ptr=x;
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.