| 1 |
package pp2.datahandler.blast; |
| 2 |
|
| 3 |
import java.io.*; |
| 4 |
import java.util.*; |
| 5 |
|
| 6 |
public class BlastPerformer { |
| 7 |
|
| 8 |
private File database; |
| 9 |
private String formatdbPath = "formatdb"; |
| 10 |
private String blastPath = "blastpgp"; |
| 11 |
|
| 12 |
public BlastPerformer(File database) { |
| 13 |
this.database = database; |
| 14 |
} |
| 15 |
|
| 16 |
public BlastPerformer(String database) { |
| 17 |
this.database = new File(database); |
| 18 |
} |
| 19 |
|
| 20 |
public Process startBLAST(File queryfile, String[] parameters) throws IOException, InterruptedException { |
| 21 |
|
| 22 |
//check if database is already formatted |
| 23 |
if(!databaseReady()) { |
| 24 |
|
| 25 |
//format database using formatdb |
| 26 |
String format = formatdbPath+" -i "+database; |
| 27 |
Runtime rt1 = java.lang.Runtime.getRuntime(); |
| 28 |
Process proc1 = rt1.exec(format); |
| 29 |
int exitVal1 = proc1.waitFor(); |
| 30 |
System.err.println("Formatdb exit value: "+exitVal1); |
| 31 |
} |
| 32 |
|
| 33 |
StringBuffer param = new StringBuffer(); |
| 34 |
for(String p : parameters) { |
| 35 |
param.append(p+" "); |
| 36 |
} |
| 37 |
|
| 38 |
//start the BLAST command |
| 39 |
String command = blastPath+" "+param+"-d "+database.getAbsolutePath()+" -i "+queryfile.getAbsolutePath(); |
| 40 |
Runtime rt = java.lang.Runtime.getRuntime(); |
| 41 |
Process proc = rt.exec(command); |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
return proc; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Checks if database is already formatted |
| 50 |
* @return TRUE if database is formatted |
| 51 |
*/ |
| 52 |
private boolean databaseReady() { |
| 53 |
File directory = database.getParentFile(); |
| 54 |
String stem = database.getName(); |
| 55 |
String[] files = directory.list(); |
| 56 |
List<String> names = Arrays.asList(files); |
| 57 |
//check if all files generated by formatdb are available |
| 58 |
if(names.contains(stem+".phr") |
| 59 |
&& names.contains(stem+".pin") |
| 60 |
&& names.contains(stem+".psq")) { |
| 61 |
System.err.println("Database is already formatted."); |
| 62 |
return true; |
| 63 |
} else { |
| 64 |
return false; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
public void setBlastPath(String blastPath) { |
| 70 |
this.blastPath = blastPath; |
| 71 |
} |
| 72 |
|
| 73 |
public void setFormatdbPath(String formatdbPath) { |
| 74 |
this.formatdbPath = formatdbPath; |
| 75 |
} |
| 76 |
|
| 77 |
} |