36a306f99953e3a0483cb3c84235e1b3093cbcc3
[jabaws.git] / runner / compbio / runner / _impl / BlastAll.java
1 /* Copyright (c) 2011 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 package compbio.runner._impl;\r
19 \r
20 import static compbio.runner._impl.BlastParameters.parAlView;\r
21 import static compbio.runner._impl.BlastParameters.parDatabase;\r
22 import static compbio.runner._impl.BlastParameters.parDel;\r
23 import static compbio.runner._impl.BlastParameters.parEvalue;\r
24 import static compbio.runner._impl.BlastParameters.parInput;\r
25 import static compbio.runner._impl.BlastParameters.parOutput;\r
26 \r
27 import java.io.File;\r
28 import java.util.Arrays;\r
29 import java.util.List;\r
30 \r
31 import compbio.runner._SkeletalCommandBuilder;\r
32 \r
33 public class BlastAll extends _SkeletalCommandBuilder {\r
34 \r
35         static final String command = "blastall";\r
36 \r
37         enum blastType {\r
38                 blastp, tbastn, blastn\r
39         }\r
40 \r
41         enum dataBase {\r
42                 pdb\r
43         }\r
44 \r
45         static double default_evalue = 0.001d;\r
46         static final String parBlastType = "-p";\r
47 \r
48         private final String workDirectory;\r
49 \r
50         public BlastAll(String workDirectory) {\r
51                 this.workDirectory = workDirectory;\r
52         }\r
53 \r
54         // Resulting command:\r
55         // /fc_gpfs/gjb_lab/www-refine/bin/blast_32bit/blast-2.2.17/bin/blastall -p\r
56         // blastp -i $input -d $dbnam -e $evalue -m 9 -o $outfile\r
57 \r
58         String getCommand(blastType btype, dataBase database, String input,\r
59                         String output) {\r
60                 return Environment.getBlastBinDir() + command + parDel + parBlastType\r
61                                 + blastType.blastp + parDel + parInput + input + parDel\r
62                                 + parDatabase + Environment.getBlastDatabasesDir() + database\r
63                                 + parDel + parEvalue + default_evalue + parAlView + parOutput\r
64                                 + output;\r
65         }\r
66 \r
67         String getFullTestCommand(String test_input, String test_outfile) {\r
68                 return Environment.getBlastBinDir() + command + parDel + parBlastType\r
69                                 + blastType.blastp + parDel + parInput + test_input + parDel\r
70                                 + parDatabase + Environment.getBlastDatabasesDir()\r
71                                 + dataBase.pdb + parDel + parEvalue + default_evalue\r
72                                 + parAlView + parOutput + test_outfile;\r
73         }\r
74 \r
75         static String getTestCommand() {\r
76                 return Environment.getBlastBinDir() + command;\r
77         }\r
78 \r
79         static List<String> getTestArgs() {\r
80                 return Arrays\r
81                                 .asList(new String[]{\r
82                                                 parBlastType + blastType.blastp,\r
83                                                 parDatabase + Environment.getBlastDatabasesDir()\r
84                                                                 + dataBase.pdb, parEvalue + default_evalue,\r
85                                                 parAlView});\r
86         }\r
87 \r
88         public boolean removeOutput(String outfile) {\r
89                 File out = new File(outfile);\r
90                 if (out.exists()) {\r
91                         if (out.canWrite()) {\r
92                                 return out.delete();\r
93                         }\r
94                 }\r
95                 return false;\r
96         }\r
97 \r
98         public String getCommand(ExecProvider provider) {\r
99                 return Environment.getBlastBinDir() + command;\r
100         }\r
101 \r
102         public String getCommandName() {\r
103                 return command;\r
104         }\r
105 \r
106         @Override\r
107         public List<String> getCreatedFiles() {\r
108                 // TODO Auto-generated method stub\r
109                 return null;\r
110         }\r
111 \r
112         @Override\r
113         public String getInput() {\r
114                 // TODO Auto-generated method stub\r
115                 return null;\r
116         }\r
117 \r
118 }\r