1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// A utility for converting Pose indices of a clustering run
// into pdb files
//
#include <BALL/KERNEL/system.h>
#include <BALL/DATATYPE/string.h>
#include <BALL/FORMAT/PDBFile.h>
#include <BALL/FORMAT/lineBasedFile.h>
#include <BALL/DOCKING/COMMON/poseClustering.h>
#include <BALL/FORMAT/commandlineParser.h>
#include <iostream>
#include "version.h"
using namespace BALL;
using namespace std;
int main(int argc, char** argv)
{
CommandlineParser parpars("PoseIndices2PDB", "converts pose indices into PDB files ", VERSION, String(__DATE__), "Convert, combine and store");
parpars.registerMandatoryInputFile("i_clust", "input cluster index file");
parpars.registerMandatoryInputFile("i_trans", "input tranformation file");
parpars.registerMandatoryInputFile("i_pdb", "input reference pdb file");
parpars.registerMandatoryOutputFile("o", "output file name prefix for resulting pdb files");
parpars.setParameterAsHidden("o");
// parameters for galaxy for handling multiple output files
parpars.registerOptionalGalaxyOutputId("o_id", "output file name prefix for 2nd to last pdb file", "$o.id");
// need to be hidden in command line mode
parpars.setParameterAsHidden("o_id");
parpars.setParameterAsAdvanced("o_id");
// parameters for galaxy for handling multiple output files
parpars.registerOptionalGalaxyOutputFolder("o_dir", "output directory for 2nd to last pdb file", "$__new_file_path__");
// need to be hidden in command line mode
parpars.setParameterAsHidden("o_dir");
parpars.setParameterAsAdvanced("o_dir");
// the manual
String man = "This tool converts all pose indices from a given transformation file and the corresponding reference PDBFile into separate PDBFiles.\n\nParameters are the input pose index file (-i_clust), the original transformation file (-i_trans), the corresponding reference pdb file (-i_pdb) and a naming schema for the resulting pdb files (-o). \n\nOutput of this tool is a set of PDBFiles representing the docking poses belonging to the given input cluster.";
parpars.setToolManual(man);
// here we set the types of I/O files
parpars.setSupportedFormats("i_clust","txt");
parpars.setSupportedFormats("i_trans","dcd");
parpars.setSupportedFormats("i_pdb","pdb");
parpars.setSupportedFormats("o","pdb");
parpars.parse(argc, argv);
//////////////////////////////////////////////////
// read the input
PDBFile pdb;
pdb.open(parpars.get("i_pdb"));
System sys;
pdb.read(sys);
PoseClustering pc;
if (parpars.has("i_trans"))
{
pc.options.set(PoseClustering::Option::RMSD_TYPE, PoseClustering::RIGID_RMSD);
pc.setBaseSystemAndTransformations(sys, parpars.get("i_trans"));
}
//std::vector< std::set<Index> > clusters;
LineBasedFile file(parpars.get("i_clust"), std::ios::in);
vector<String> fields;
String cluster_id = -1;
String pose_id = -1;
// called as command line or e.g. via galaxy?
bool is_cmd = !parpars.has("env")
|| ((parpars.has("env") && parpars.get("env")=="cmdline"));
bool first_sol = true;
while (file.LineBasedFile::readLine())
{
// get the line
String current_cluster = file.getLine();
if (current_cluster.getField(1) == "cluster")
{
cluster_id = current_cluster.getField(2);
pose_id = -1;
if (file.LineBasedFile::readLine())
{
current_cluster = file.getLine();
fields.clear();
current_cluster.split(fields);
for (Size i=0; i < fields.size(); i++)
{
System new_pose_sys(sys);
pose_id = fields[i];
pc.applyTransformation2System(pose_id.toInt(), new_pose_sys);
// create the output name
String outfile_name = String(parpars.get("o"))
+ "_clust_" + cluster_id
+ "_pose_" + String(pose_id) + ".pdb";
if (parpars.has("o_dir") && is_cmd && (parpars.get("o_dir") != "$__new_file_path__"))
{
outfile_name = String(parpars.get("o_dir")) + "/" + outfile_name;
}
// NOTE: Galaxy requires this strange naming convention
// including the fact, that zero-th element has a different name
if (!is_cmd)
{
outfile_name = (first_sol) ? String(parpars.get("o"))
: String(parpars.get("o_dir")) + "/primary_"
+ String(parpars.get("o_id")) + "_clust_" + cluster_id
+ "_pose_" + String(pose_id)
+ "_visible_pdb";
}
PDBFile file(outfile_name, ios::out);
if (file.bad())
{
Log.error() << "cannot write file " << outfile_name << endl;
return 2;
}
file << new_pose_sys;
file.close();
// needed for galaxy output
if (first_sol)
first_sol = false;
Log << "wrote file " << outfile_name << endl;
}
}
}
}
Log << "done." << endl;
return 0;
}
|