Ver código fonte

blastdb INSERT, UPDATE, DELETE fixed

Amir Zadeh 11 anos atrás
pai
commit
8ad12e9df6

+ 39 - 1
blast_ui/blast_ui.install

@@ -5,4 +5,42 @@
  * Contains hooks to handle installation of this module
  */
 
-tripal_create_files_dir('tripal_blast');
+function blast_ui_install() {
+   tripal_create_files_dir('tripal_blast');
+}
+
+function blast_ui_schema(){
+    $schema['blastdb'] = array(
+    'description' => t('The base table for blastdb node'),
+    'fields' => array(
+     'nid' => array(
+      'description' => t('The primary identifier for a node.'),
+      'type' => 'serial',
+      'unsigned' => true,
+      'not null' => true,
+      ), 
+     'name' => array(
+       'description' => t('The name of the blast database'),
+       'type' => 'varchar',
+       'length' => 255,
+       'not null' => true,
+      ),
+      'path' => array(
+        'description' => t('The address of the blast database'),
+        'type' => 'varchar',
+         'length' => 1023,
+        'not null' => true,
+      ),
+    ),
+    'indexes' => array(
+      'name' => array('name'),
+    ),
+    'primary key' => array('nid'),
+    'unique keys' => array(
+       'nid' => array('nid'),
+    ),
+    );
+
+    return $schema;
+    
+}

+ 0 - 238
blast_ui/includes/blast_ui.blastn.inc_COPY

@@ -1,238 +0,0 @@
-<?php
-
-function blast_nucleotide_form($form, &$form_state) {
-  
-//Nucleotide BLAST
-
-$form['nBLAST'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Standard Nucleotide BLAST'),
-    '#collapsible' => TRUE, 
-    '#collapsed' => FALSE,  
-  );
-$form['nBLAST']['FASTA'] = array(
-    '#type' => 'textarea',
-    '#title' => t('Enter FASTA sequence(s)'),
-    '#description'=>t('Enter query sequence(s) in the text area.'),
-  );
-
-// Upload a file as an alternative to enter a query sequence 
-$form['#attributes']['enctype'] = 'multipart/form-data';
-$form['nBLAST']['UPLOAD'] = array(
-  	'#prefix' => 'Or upload your query files:	',
-  	'#type' => 'file',
-  	'#description' => t('Please give a text a FASTA file, not a MS-Word or other document, you can upload up to 10 Mb.'),
-  );
-
-
-//DATABASE//
-
-	$form['DB'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('BLAST Assembled KnowPulse Genomes'),
-    '#collapsible' => TRUE, 
-    '#collapsed' => FALSE,  
-  );
-  
-//  //$options =  _DB_options(); 
-//  $form['DB']['SELECT_DB'] = array(
-//       '#type' => 'select',
-//       '#title' => t('KnowPulse Databases:'),
-//       '#options' => $options,
-//       '#default_value' => NULL,
-//   );
-  
-// Upload a file as an alternative to enter a query sequence 
-  $form['#attributes']['enctype'] = 'multipart/form-data';
-  $form['DB']['DBUPLOAD'] = array(
-  	'#prefix' => 'Or upload your own dataset:	',
-  	'#type' => 'file',
-  	'#description' => t('Please give a text or a FASTA file, not a MS-Word or other document, you can upload up to 10 Mb.'),
-  );
-  
-//Algorithm parameters
-
-	$form['ALG'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Algorithm parameters'),
-    '#collapsible' => TRUE, 
-    '#collapsed' => TRUE,  
-  );
-
-//General parameters  
-
-  $form['ALG']['GParam'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('General parameters'),
-    '#collapsible' => FALSE,
-  );
-  
-  $form['ALG']['GParam']['maxTarget'] = array(
-       '#type' => 'select',
-       '#title' => t('Max target sequences:'),
-       '#options' => array(
-          0 => t('10'),
-          1 => t('50'),
-          2 => t('100'),
-          3 => t('250'),
-          4 => t('500'),
-          5 => t('1000'),
-          6 => t('5000'),
-          7 => t('10000'),
-          8 => t('20000'),
-       ),
-       '#default_value' => 2,
-       '#description' => t('Select the maximum number of aligned sequences to display'),
-   );
-  
-  $form['ALG']['GParam']['shortQueries'] = array(
-   '#type' => 'checkbox', 
-   '#title' => t('Automatically adjust parameters for short input sequences'),
-   '#default_value' => TRUE,
-);
-	
-	$form['ALG']['GParam']['eVal'] = array(
-  '#type' => 'textfield', 
-  '#title' => t('Expect threshold'), 
-  '#default_value' => 10, 
-  '#size' => 12, 
-  '#maxlength' => 20, 
-  '#description' => t('Expected number of chance matches in a random model.'),
-);
-	
-	 $form['ALG']['GParam']['wordSize'] = array(
-       '#type' => 'select',
-       '#title' => t('Word size:'),
-       '#options' => array(
-          0 => t('16'),
-          1 => t('20'),
-          2 => t('24'),
-          3 => t('28'),
-          4 => t('32'),
-          5 => t('48'),
-          6 => t('64'),
-          7 => t('128'),
-          8 => t('256'),
-       ),
-       '#default_value' => 3,
-       '#description' => t('The length of the seed that initiates an alignment'),
-   );
-  
-$form['ALG']['GParam']['qRange'] = array(
-  '#type' => 'textfield', 
-  '#title' => t('Max matches in a query range'), 
-  '#default_value' => 0, 
-  '#size' => 12, 
-  '#maxlength' => 20, 
-  '#description' => t('Limit the number of matches to a query range. This option is useful if many strong matches to one part of a query may prevent BLAST from presenting weaker matches to another part of the query.'),
-);
- 
-// Scoring parameters
-
-  $form['ALG']['SParam'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Scoring parameters'),
-    '#collapsible' => FALSE, 
-  );
-  
-  $form['ALG']['SParam']['M&MScores'] = array(
-       '#type' => 'select',
-       '#title' => t('Match/Mismatch Scores:'),
-       '#options' => array(
-          0 => t('1,-2'),
-          1 => t('1,-3'),
-          2 => t('1,-4'),
-          3 => t('2,-3'),
-          4 => t('4,-5'),
-          5 => t('1,-1'),
-       ),
-       '#default_value' => 0,
-       '#description' => t('Reward and penalty for matching and mismatching bases.'),
-   );
-  
-  $form['ALG']['SParam']['gapCost'] = array(
-       '#type' => 'select',
-       '#title' => t('Gap Costs:'),
-       '#options' => array(
-          0 => t('Linear'),
-          1 => t('Extension: 5 Extension: 2'),
-          2 => t('Extension: 2 Extension: 2'),
-          3 => t('Extension: 1 Extension: 2'),
-          4 => t('Extension: 0 Extension: 2'),
-          5 => t('Extension: 3 Extension: 1'),
-          6 => t('Extension: 2 Extension: 1'),
-          7 => t('Extension: 1 Extension: 1'),
-       ),
-       '#default_value' => 0,
-       '#description' => t('Cost to create and extend a gap in an alignment. Linear costs are available only with megablast and are determined by the match/mismatch scores.'),
-   );
-  
-//Submit 
-
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#default_value' => ' BLAST ',
-  );
-  
-  return $form;
-}
-
-function blast_nucleotide_form_validate($form, &$form_state) {
-   $fastaSeq = $form_state['input']['FASTA'];
-   dpm($form_state, $name = NULL);
-   if (isset($fastaSeq)) {
-      if(_validateFasta($fastaSeq)){
-          form_set_error('nBLAST', t('Error: Failed to read the Blast query: Wrong format provided for FASTA nucleotide sequence'));
-      } else {
-         //
-      }  
-   }
-   $upQuery = file_save_upload('UPLOAD', array('file_validate_extensions' => array('txt fasta fa fna')), FILE_EXISTS_RENAME);
-   if ($upQuery) {
-      $upQuery_uri = $upQuery->uri;
-      $upQuery_path = drupal_realpath($upQuery_uri);
-      $upQuery_content = file_get_contents($upQuery_path);
-      if(_validateFasta($upQuery_content)){
-          form_set_error('nBLAST', t('Error: Failed to upload the Blast query: Wrong format provided for FASTA nucleotide sequence'));
-      } else {
-         //
-      }
-   }
-   
-   $upDB = file_save_upload('DBUPLOAD', array('file_validate_extensions' => array('txt fasta fa fna')), FILE_EXISTS_RENAME);
-   if ($upDB) {
-      $upDB_uri = $upDB->uri;
-      $upDB_path = drupal_realpath($upDB_uri);
-      $upDB_content = file_get_contents($upDB_path); 
-      if(_validateFasta($upDB_content)){
-          form_set_error('DB', t('Error: Failed to upload the Blast reference file: Wrong format provided for FASTA nucleotide sequence'));
-      } else {
-         //Build a Blast DB?
-      }
-   }
-   
-}
-
-function blast_nucleotide_form_submit($form, &$form_state) {
-  //dpm($form_state['values'], $name = NULL);
-  //$output = shell_exec("water -asequence $aSeq -bsequence $selectedDB -gapopen 10 -gapextend 2 -outfile /tmp/$jobID.water ");
-}
-
-function _validateFasta($sequence) {
-	$fastaIdRegEx = '/^>.*(\\n|\\r)/';
-	$fastaSeqRegEx = '/[^acgntuACGNTU\n\r]/';
-	if ( preg_match($fastaSeqRegEx,$sequence) && !(preg_match($fastaIdRegEx,$sequence)) ) {
-      $flag = 1;
-  } else {
-   $flag = 0;
-  }
-	
-  return $flag;
-}
-
-function _DB_options() {
-  $type = 'BLASTDB';
-  $nodes  = node_load_multiple(array(), array('type' => $type));
-  return $nodes;
-
-}

+ 37 - 11
blast_ui/includes/blast_ui.node.inc

@@ -50,28 +50,54 @@ function blastdb_node_access($node, $op, $account) {
 
 function blastdb_form($node, &$form_state) {
   $form = array();
-
+  
   $form['db_name']= array(
     '#type' => 'textfield',
     '#title' => t('File Name'),
-    // Add a #description for each field
     '#required' => TRUE,
-    '#default_value' => NULL,
+    '#default_value' => isset($node->db_name) ? $node->db_name : '',
   );
   $form['db_path']= array(
     '#type' => 'textfield',
     '#title' => t('File Address'),
     '#required' => TRUE,
-    '#default_value' => NULL,
+    '#default_value' => isset($node->db_path) ? $node->db_path : '',
   );
 
-  $form['db_common_name']= array(
-    '#type' => 'textfield',
-    // this is a description; you want something more succint for a title such as File Name
-    '#title' => t('Pick a friendly name for your file'),
-    '#required' => TRUE,
-    '#default_value' => NULL,
-  );
+  dpm($node, $name = NULL);
 
   return $form;
 }
+
+function blastdb_insert($node) {
+ 
+  db_insert('blastdb')->fields(array(
+    'nid' => $node->nid,
+    'name' => $node->db_name,
+    'path' => $node->db_path,
+  ))->execute();
+
+}
+
+function blastdb_update($node) {
+    db_update('blastdb')->fields(array(
+    'name' => $node->db_name,
+    'path' => $node->db_path,
+  ))->condition('nid', $node->nid)->execute();
+}
+
+function blastdb_delete($node) {
+   db_delete('blastdb')->condition('nid',$node->nid)->execute();
+}
+
+function blastdb_load($nodes) {
+    
+  $result = db_query('SELECT nid, name, path FROM {blastdb} WHERE nid IN (:nids)', array(':nids' => array_keys($nodes)));
+  
+  foreach ($result as $record) {
+    $nodes[$record->nid]->db_name = $record->name;
+    $nodes[$record->nid]->db_path = $record->path;
+  }
+   
+}
+