Question
Draw flow chart for this algorithm and process current model public class Sequence_Match { public static void main(String args[]){ int matchLength = 0; String corpusSeq
Draw flow chart for this algorithm and process current model
public class Sequence_Match {
public static void main(String args[]){
int matchLength = 0;
String corpusSeq = null;
String patternSeq = null;
String maskSeq = null;
if (args.length < 3)
{
System.out.println("Syntax: java Sequence_Match
"
"[
return;
}
else
{
matchLength = Integer.parseInt(args[0]);
corpusSeq = SeqReader.readSeq(args[1]);
patternSeq = SeqReader.readSeq(args[2]);
Terminal.println("M = " + matchLength);
Terminal.println("CORPUS: " + corpusSeq.length() + " bases");
Terminal.println("PATTERN: " + patternSeq.length()+" bases");
if (args.length > 3)
{
maskSeq = SeqReader.readSeq(args[3]);
Terminal.println("MASK: "+maskSeq.length()+" bases");
}
}
//COMMENT OUT BEFORE SUBMITTING
/*
matchLength = 1;
corpusSeq = SeqReader.readSeq("test-corpus.txt");
patternSeq = SeqReader.readSeq("test-pattern.txt");
//maskSeq = SeqReader.readSeq("test2-mask.txt");
//*/
StringTable table = createTable(patternSeq, matchLength);
if (maskSeq != null)
maskTable(table, maskSeq, matchLength);
// table.printTable(); System.out.println("");
findMatches(table, corpusSeq, matchLength);
}
// Create a new StringTable containing all substrings of the pattern
// sequence.
//
public static StringTable createTable(String patternSeq, int matchLength)
{
StringTable table = new StringTable(patternSeq.length());
for (int j = 0; j < patternSeq.length() - matchLength + 1; j++)
{
String key = patternSeq.substring(j, j + matchLength);
/*
if(j==38397){
System.out.println("key is "+key);
}
*/
Record rec = table.find(key);
if (rec == null) // not found -- need new Record
{
rec = new Record(key);
if (!table.insert(rec))
System.out.println("Error (insert): hash table is full! ");
}
rec.positions.add(new Integer(j));
}
return table;
}
// Remove all substrings in the mask sequence from a StringTable.
//
public static void maskTable(StringTable table, String maskSeq,
int matchLength)
{
for (int j = 0; j < maskSeq.length() - matchLength + 1; j++)
{
String key = maskSeq.substring(j, j + matchLength);
Record rec = table.find(key);
if (rec != null)
table.remove(rec);
}
}
// Find and print all matches between the corpus sequence and any
// string in a StringTable.
//
public static void findMatches(StringTable table, String corpusSeq,
int matchLength)
{
for (int j = 0; j < corpusSeq.length() - matchLength + 1; j++)
{
String key = corpusSeq.substring(j, j + matchLength);
Record rec = table.find(key);
if (rec != null)
{
for (int k = 0; k < rec.positions.size(); k++)
{
Terminal.println(j + " " +
rec.positions.get(k) +" "+
key);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started