00001 <?php
00002
00003
00004
00028 function dbsf_install() {
00029 global $db_url;
00030 if (strpos($db_url['default'], 'pgsql://') === FALSE && strpos($db_url, 'pgsql://') === FALSE) {
00031 drupal_set_message("The dbsf module was not installed: it requires a PostgreSQL database due to data integrity issues with MySQL and also PostgreSQL is need for integration with GMOD and chado.", 'error', FALSE);
00032 return FALSE;
00033 }
00034
00035 drupal_install_schema('dbsf');
00036 db_query('ALTER TABLE {ic_software} ADD active boolean NOT NULL');
00037 db_query('ALTER TABLE {ic_software} ALTER active set default false');
00038
00039 icbasic_add_cv('software_type', array('similarity search', 'de-novo prediction'));
00040 icbasic_add_cv('dataset_type', array('protein', 'nucleotide', 'both'));
00041 icbasic_add_cv('resource_type', array('software option', 'dataset', 'dataset_group', 'directory', 'filename'));
00042 icbasic_add_cv('software path', array('executable', 'data'));
00043 icbasic_add_cv('input type', array('select', 'textfield', 'textarea', 'checkbox', 'checkboxes', 'radio', 'radios'));
00044
00045
00046 $add_software_sql = "INSERT INTO {ic_software} (uniquename,description) VALUES ('%s','%s')";
00047 $software_core_avail = array(
00048 'blastall' => "BLAST from NCBI implementation from the C toolkit (BLASTALL)",
00049 'condor' => "If installed, searches will be launched via Condor",
00050 );
00051 foreach ($software_core_avail as $software_name => $description) {
00052 db_query($add_software_sql, $software_name, $description);
00053 }
00054 dbsf_add_software_blast();
00055
00056
00057 $plugin_path = drupal_get_path('module', 'dbsf') .'/';
00058 $plugins = array();
00059
00060 if (file_exists($plugin_path .'dbsf_ssaha2.inc')) {
00061 $plugins['ssaha2']['file'] = $plugin_path .'dbsf_ssaha2.inc';
00062 $plugins['ssaha2']['desc'] = "SSAHA2 rapidly aligns reads of most sequencing platforms (ABI-Sanger, Roche 454, Illumina-Solexa) to reference databases";
00063 }
00064 foreach ($plugins as $plugin_name => $plugin_data) {
00065 require_once ($plugin_data['file']);
00066 switch ($plugin_name) {
00067 case 'ssaha2':
00068 db_query($add_software_sql, $plugin_name, $plugin_data['desc']);
00069 dbsf_add_software_ssaha2();
00070 break;
00071 }
00072 drupal_set_message($plugin_name .' plugin found and installed.', 'warning');
00073 }
00074
00075
00076
00077 $dirpath = file_create_path() .'/dbsf';
00078 file_check_directory($dirpath, FILE_CREATE_DIRECTORY);
00079
00080 touch($dirpath .'/index.html');
00081 touch($dirpath .'/index.php');
00082
00083 }
00084
00088 function dbsf_uninstall() {
00089 drupal_uninstall_schema('dbsf');
00090 }
00091
00100 function dbsf_schema() {
00101
00102 $schema['ic_resource_role'] = array(
00103 'fields' => array(
00104 'resource_role_id' => array(
00105 'type' => 'serial',
00106 'not null' => TRUE,
00107 ),
00108 'role_id' => array(
00109 'type' => 'int',
00110 'not null' => TRUE,
00111 ),
00112 'resource_id' => array(
00113 'type' => 'int',
00114 'not null' => TRUE,
00115 ),
00116 ),
00117 'unique keys' => array('ic_role_uidx' => array('resource_id', 'role_id')),
00118 'primary key' => array('resource_role_id'),
00119 );
00120 $schema['ic_software'] = array(
00121 'fields' => array(
00122 'software_id' => array(
00123 'type' => 'serial',
00124 'not null' => TRUE,
00125 ),
00126 'uniquename' => array(
00127 'type' => 'varchar',
00128 'length' => 15,
00129 'not null' => TRUE,
00130 ),
00131 'description' => array(
00132 'type' => 'text',
00133 ),
00134 ),
00135 'unique keys' => array('ic_software_uidx' => array('uniquename')),
00136 'primary key' => array('software_id'),
00137 );
00138 $schema['ic_softwareprop'] = array(
00139 'fields' => array(
00140 'softwareprop_id' => array(
00141 'type' => 'serial',
00142 'not null' => TRUE,
00143 ), 'software_id' => array(
00144 'type' => 'int',
00145 'not null' => TRUE,
00146 ), 'type_id' => array(
00147 'type' => 'int',
00148 'not null' => TRUE,
00149 ), 'value' => array(
00150 'type' => 'text',
00151 ), 'rank' => array(
00152 'type' => 'int',
00153 'default' => 0,
00154 ),
00155 ),
00156 'unique keys' => array('ic_softwareprop_uidx' => array('software_id', 'type_id', 'rank')),
00157 'primary key' => array('softwareprop_id'),
00158 );
00159 $schema['ic_software_resource'] = array(
00160 'fields' => array(
00161 'software_resource_id' => array(
00162 'type' => 'serial',
00163 'not null' => TRUE,
00164 ), 'software_id' => array(
00165 'type' => 'int',
00166 'not null' => TRUE,
00167 ), 'resource_id' => array(
00168 'type' => 'int',
00169 'not null' => TRUE,
00170 ),
00171 ),
00172 'unique keys' => array('ic_software_resource_uidx' => array('software_id', 'resource_id')),
00173 'primary key' => array('software_resource_id'),
00174 );
00175 return $schema;
00176 }
00177
00193 function dbsf_add_software_option($name, $dbxref_id, $cvterm_id, $description = NULL) {
00194 if (empty($name) || empty($dbxref_id) || empty($cvterm_id)) {
00195 return FALSE;
00196 }
00197 db_query("DELETE FROM {ic_resource} where uniquename='%s'", $name);
00198 if (empty($description)) {
00199 db_query("INSERT INTO {ic_resource} (uniquename,organism_id,dbxref_id,type_id) " . "VALUES ('%s',1,%d,%d)", $name, $dbxref_id, $cvterm_id);
00200 }
00201 else {
00202 db_query("INSERT INTO {ic_resource} (uniquename,organism_id,dbxref_id,type_id,description) " . "VALUES ('%s',1,%d,%d,'%s')", $name, $dbxref_id, $cvterm_id, $description);
00203 }
00204
00205 $res = db_fetch_array(db_query("SELECT resource_id from {ic_resource} where uniquename='%s' AND dbxref_id=%d and type_id=%d", $name, $dbxref_id, $cvterm_id));
00206 if (empty($res['uniquename'])) {
00207 drupal_set_message(t('Failed to add software option ') . $name .'.');
00208 return FALSE;
00209 }
00210 return TRUE;
00211 }
00212
00219 function dbsf_add_software_blast() {
00220 db_query("INSERT INTO {ic_software} (uniquename,description) VALUES ('formatdb','Format reference sequence as a BLAST database - NCBI C toolkit. Required for blastall to work properly.')");
00221 db_query("INSERT INTO {ic_software} (uniquename,description) VALUES ('fastacmd','Retrieve data from formatted BLAST databases - NCBI C toolkit. Required for blastall to work properly.')");
00222
00223 $dbxref_id = icbasic_get_add_dbxref_withnames('NCBI', 'BLASTALL');
00224 $cvterm_id = icbasic_get_add_cv_withnames('resource_type', 'software option');
00225 $link_sql = 'INSERT INTO {ic_software_resource} (software_id,resource_id) VALUES (' . "(SELECT software_id from {ic_software} where uniquename='blastall')" . ",(SELECT resource_id from {ic_resource} where uniquename='%s')" . ')';
00226
00227 $options_array = array(
00228 'Scoring matrix' => '',
00229 'Filtering' => '',
00230 'E-value cutoff' => '',
00231 'Advanced BLAST options' => '',
00232 'query genetic code' => '',
00233 'DB genetic code' => '',
00234 'Frame shift penalty' => '',
00235 'Number of results' => '',
00236 );
00237 foreach ($options_array as $option => $description) {
00238 dbsf_add_software_option($option, $dbxref_id, $cvterm_id, $description);
00239 switch ($option) {
00240 case 'Scoring matrix':
00241 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00242 'BLOSUM62', 'PAM30', 'PAM70', 'BLOSUM80', 'BLOSUM45',
00243 ));
00244 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('select'));
00245 break;
00246
00247 case 'Filtering':
00248 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00249 'Low complexity regions', 'Lower-case letters',
00250 ));
00251 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('checkboxes'));
00252 break;
00253
00254 case 'E-value cutoff':
00255 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00256 '1e-3', '1e-30', '1e-10', '1e-5', '0.1', '0', '10',
00257 ));
00258 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('select'));
00259 break;
00260
00261 case 'Advanced BLAST options':
00262 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00263 'ungapped', 'megablast',
00264 ));
00265 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('checkboxes'));
00266 break;
00267
00268 case 'query genetic code':
00269 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00270 'Standard', 'Vertebrate Mitochondrial', 'Yeast Mitochondrial', 'Mold, Protozoan, and Coelocoel Mitochondrial'
00271 , 'Invertebrate Mitochondrial', 'Ciliate Nuclear', 'Echinoderm Mitochondrial', 'Euplotid Nuclear'
00272 , 'Bacterial', 'Alternative Yeast Nuclear', 'Ascidian Mitochondrial', 'Flatworm Mitochondrial'
00273 , 'Blepharisma Macronuclear',
00274 ));
00275 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('select'));
00276 break;
00277
00278 case 'DB genetic code':
00279 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00280 'Standard', 'Vertebrate Mitochondrial', 'Yeast Mitochondrial', 'Mold, Protozoan, and Coelocoel Mitochondrial'
00281 , 'Invertebrate Mitochondrial', 'Ciliate Nuclear', 'Echinoderm Mitochondrial', 'Euplotid Nuclear'
00282 , 'Bacterial', 'Alternative Yeast Nuclear', 'Ascidian Mitochondrial', 'Flatworm Mitochondrial'
00283 , 'Blepharisma Macronuclear',
00284 ));
00285 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('select'));
00286 break;
00287
00288 case 'Frame shift penalty':
00289 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00290 '0',
00291 ));
00292 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('textfield'));
00293 break;
00294
00295 case 'Number of results':
00296 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00297 '10', '100', '1', '50',
00298 )
00299 );
00300 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('select'));
00301 break;
00302 }
00303
00304 db_query($link_sql, $option);
00305 }
00306 return TRUE;
00307 }
00308