Question: What is the DNA sequence matching code below do and how it is working? public class Sequence_Match { public static void main(String args[]){ int matchLength
What is the DNA sequence matching code below do and how it is working?
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");
}
}
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);
}
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);
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);
}
}
/*
if(j==26669){
System.out.println("");
System.out.println("key = "+key+" StringTable.toHashKey(key) = "+StringTable.toHashKey(key));
System.out.println("rec.key = "+rec.key+" StringTable.toHashKey(rec.key) = "+StringTable.toHashKey(rec.
}
}
}
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
