9ef3bf79e8e2b5b943866ad8cf17336ca829161a
[jabaws.git] / runner / compbio / runner / _impl / PSIBlast.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 /*\r
34  * TODO look at how a command can be build with an argument list\r
35  */\r
36 public class PSIBlast extends _SkeletalCommandBuilder {\r
37 \r
38         private static final String command = "blastpgp";\r
39 \r
40         enum blastType {\r
41                 blastp, tbastn, blastn\r
42         }\r
43 \r
44         enum dataBase {\r
45                 pdb\r
46         }\r
47 \r
48         static double default_evalue = 0.001d;\r
49         static final String parBlastType = "-p";\r
50 \r
51         private final String workDirectory;\r
52 \r
53         public PSIBlast(String workDirectory) {\r
54                 this.workDirectory = workDirectory;\r
55         }\r
56 \r
57         // Resulting command:\r
58         // TODO lease note that the location seem to be different for 64 bit nodes\r
59         // fc_gpfs/gjb_lab/www-refine/bin/blast_32bit/blast-2.2.17/bin/blastpgp -i\r
60         // $input -d $dbnam -o $output_dir/$outfile.psiblastout.$clus -j $iterations\r
61         // -Q $output_dir/$outfile.PSImatrix.$clus -m $mo\r
62 \r
63         // BlastAll\r
64         // //fc_gpfs/gjb_lab/www-refine/bin/blast_32bit/blast-2.2.17/bin/blastall -p\r
65         // blastp -i $input -d $dbnam -e $evalue -m 9 -o $outfile\r
66 \r
67         String getCommand(blastType btype, dataBase database, String input,\r
68                         String output) {\r
69                 return Environment.getBlastBinDir() + command + parDel + parBlastType\r
70                                 + blastType.blastp + parDel + parInput + input + parDel\r
71                                 + parDatabase + Environment.getBlastDatabasesDir() + database\r
72                                 + parDel + parEvalue + default_evalue + parAlView + parOutput\r
73                                 + output;\r
74         }\r
75 \r
76         String getFullTestCommand(String test_input, String test_outfile) {\r
77                 return Environment.getBlastBinDir() + command + parDel + parBlastType\r
78                                 + blastType.blastp + parDel + parInput + test_input + parDel\r
79                                 + parDatabase + Environment.getBlastDatabasesDir()\r
80                                 + dataBase.pdb + parDel + parEvalue + default_evalue\r
81                                 + parAlView + parOutput + test_outfile;\r
82         }\r
83 \r
84         static String getTestCommand() {\r
85                 return Environment.getBlastBinDir() + command;\r
86         }\r
87 \r
88         static List<String> getTestArgs() {\r
89                 return Arrays\r
90                                 .asList(new String[] {\r
91                                                 parBlastType + blastType.blastp,\r
92                                                 parDatabase + Environment.getBlastDatabasesDir()\r
93                                                                 + dataBase.pdb, parEvalue + default_evalue,\r
94                                                 parAlView });\r
95         }\r
96 \r
97         public boolean removeOutput(String outfile) {\r
98                 File out = new File(outfile);\r
99                 if (out.exists()) {\r
100                         if (out.canWrite()) {\r
101                                 return out.delete();\r
102                         }\r
103                 }\r
104                 return false;\r
105         }\r
106 \r
107         public String getCommand(ExecProvider provider) {\r
108                 return Environment.getBlastBinDir() + command;\r
109         }\r
110 \r
111         public String getCommandName() {\r
112                 return command;\r
113         }\r
114 \r
115         @Override\r
116         public List<String> getCreatedFiles() {\r
117                 // TODO Auto-generated method stub\r
118                 return null;\r
119         }\r
120 \r
121         @Override\r
122         public String getInput() {\r
123                 // TODO Auto-generated method stub\r
124                 return null;\r
125         }\r
126 \r
127 }\r