blast_ui.blastp.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. <?php
  2. /**
  3. * @file
  4. * Contains all functions for the Protein BLAST
  5. */
  6. /**
  7. * Protein BLAST Submission Form
  8. *
  9. * @see blast_protein_form_validate()
  10. * @see blast_protein_form_submit()
  11. */
  12. function blast_protein_form($form, &$form_state) {
  13. // PROTEIN QUERY
  14. //.........................
  15. $form['query'] = array(
  16. '#type' => 'fieldset',
  17. '#title' => t('Enter Query Sequence'),
  18. '#description' => t('Enter one or more queries in the top text box or use the browse button to upload a file from your local disk. The file may contain a single sequence or a list of sequences. In both cases, the data must be in FASTA format. <a href="http://www.ncbi.nlm.nih.gov/BLAST/blastcgihelp.shtml" target="_blank">More information..</a> '),
  19. '#collapsible' => TRUE,
  20. '#collapsed' => FALSE,
  21. );
  22. $form['query']['FASTA'] = array(
  23. '#type' => 'textarea',
  24. '#title' => t('Enter FASTA sequence(s)'),
  25. '#description'=>t('Enter query sequence(s) in the text area.'),
  26. );
  27. // Upload a file as an alternative to enter a query sequence
  28. $form['#attributes']['enctype'] = 'multipart/form-data';
  29. $form['query']['UPLOAD'] = array(
  30. '#prefix' => 'Or upload your query files: ',
  31. '#type' => 'file',
  32. '#description' => t('The file should be a plain-text FASTA file and not a .doc, .docx, etc. It cannot be greater than 10 Mb in size.'),
  33. );
  34. // BLAST DATABASE
  35. //.........................
  36. $form['DB'] = array(
  37. '#type' => 'fieldset',
  38. '#title' => t('Choose Search Set'),
  39. '#description' => t('Choose from one of the protein BLAST databases listed below. You can also use the browse button to upload a file from your local disk. The file may contain a single sequence or a list of sequences. '),
  40. '#collapsible' => TRUE,
  41. '#collapsed' => FALSE,
  42. );
  43. $options = DB_options();
  44. $form['DB']['SELECT_DB'] = array(
  45. '#type' => 'select',
  46. '#title' => t('Protein BLAST Databases:'),
  47. '#options' => $options,
  48. '#default_value' => t('Select a database'),
  49. );
  50. // Upload a file as an alternative to enter a query sequence
  51. $form['#attributes']['enctype'] = 'multipart/form-data';
  52. $form['DB']['DBUPLOAD'] = array(
  53. '#prefix' => 'Or upload your own dataset: ',
  54. '#type' => 'file',
  55. '#description' => t('The file should be a plain-text FASTA file and not a .doc, .docx, etc. It cannot be greater than 10 Mb in size.'),
  56. );
  57. // ALGORITHM PARAMETERS
  58. //.........................
  59. $form['ALG'] = array(
  60. '#type' => 'fieldset',
  61. '#title' => t('Algorithm parameters'),
  62. '#collapsible' => TRUE,
  63. '#collapsed' => TRUE,
  64. );
  65. //General parameters
  66. $form['ALG']['GParam'] = array(
  67. '#type' => 'fieldset',
  68. '#title' => t('General parameters'),
  69. '#collapsible' => FALSE,
  70. );
  71. $form['ALG']['GParam']['maxTarget'] = array(
  72. '#type' => 'select',
  73. '#title' => t('Max target sequences:'),
  74. '#options' => array(
  75. 0 => t('10'),
  76. 1 => t('50'),
  77. 2 => t('100'),
  78. 3 => t('250'),
  79. 4 => t('500'),
  80. 5 => t('1000'),
  81. 6 => t('5000'),
  82. 7 => t('10000'),
  83. 8 => t('20000'),
  84. ),
  85. '#default_value' => 2,
  86. '#description' => t('Select the maximum number of aligned sequences to display'),
  87. );
  88. $form['ALG']['GParam']['shortQueries'] = array(
  89. '#type' => 'checkbox',
  90. '#title' => t('Automatically adjust parameters for short input sequences'),
  91. '#default_value' => TRUE,
  92. );
  93. $form['ALG']['GParam']['eVal'] = array(
  94. '#type' => 'textfield',
  95. '#title' => t('e-value(Expect threshold)'),
  96. '#default_value' => 10,
  97. '#size' => 12,
  98. '#maxlength' => 20,
  99. '#description' => t('Expected number of chance matches in a random model.'),
  100. );
  101. $form['ALG']['GParam']['wordSize'] = array(
  102. '#type' => 'select',
  103. '#title' => t('Word size:'),
  104. '#options' => array(
  105. 0 => t('2'),
  106. 1 => t('3'),
  107. ),
  108. '#default_value' => 1,
  109. '#description' => t('The length of the seed that initiates an alignment'),
  110. );
  111. $form['ALG']['GParam']['qRange'] = array(
  112. '#type' => 'textfield',
  113. '#title' => t('Max matches in a query range'),
  114. '#default_value' => 0,
  115. '#size' => 12,
  116. '#maxlength' => 20,
  117. '#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.'),
  118. );
  119. // Scoring parameters
  120. $form['ALG']['SParam'] = array(
  121. '#type' => 'fieldset',
  122. '#title' => t('Scoring parameters'),
  123. '#collapsible' => FALSE,
  124. );
  125. $options_first = _ajax_example_get_first_dropdown_options();
  126. $selected = isset($form_state['values']['MATRIX'] ) ? $form_state['values']['MATRIX'] : key($options_first);
  127. $form['ALG']['SParam']['MATRIX'] = array(
  128. '#type' => 'select',
  129. '#title' => 'Matrix',
  130. '#options' => $options_first,
  131. '#default_value' => $selected,
  132. '#description' => t('Assigns a score for aligning pairs of residues, and determines overall alignment score..'),
  133. '#ajax' => array(
  134. 'callback' => 'ajax_example_dependent_dropdown_callback',
  135. 'wrapper' => 'dropdown-second-replace',
  136. ),
  137. );
  138. $form['ALG']['SParam']['gapCost'] = array(
  139. '#type' => 'select',
  140. '#title' => t('Gap Costs:'),
  141. '#prefix' => '<div id="dropdown-second-replace">',
  142. '#suffix' => '</div>',
  143. '#options' => _ajax_example_get_second_dropdown_options($selected),
  144. '#default_value' => 2,
  145. '#description' => t('Cost to create and extend a gap in an alignment.'),
  146. );
  147. $form['ALG']['SParam']['M&MScores'] = array(
  148. '#type' => 'select',
  149. '#title' => t('Match/Mismatch Scores:'),
  150. '#options' => array(
  151. 0 => t('No adjustment'),
  152. 1 => t('Composition-based statistics'),
  153. 2 => t('Conditional compositional score matrix adjustment'),
  154. 3 => t('Universal composition score matrix adjustment '),
  155. ),
  156. '#default_value' => 2,
  157. '#description' => t('Matrix adjustment method to compensate for amino acid composition of sequences'),
  158. );
  159. //Submit
  160. $form['submit'] = array(
  161. '#type' => 'submit',
  162. '#default_value' => ' BLAST ',
  163. );
  164. return $form;
  165. }
  166. /**
  167. * Form validation handler for blast_protein_form().
  168. *
  169. * @see blast_protein_form_validate()
  170. */
  171. function blast_protein_form_validate($form, &$form_state) {
  172. // Validate query sequence
  173. $fastaSeq = $form_state['input']['FASTA'];
  174. if (isset($fastaSeq)) {
  175. if (validateFasta($fastaSeq)){
  176. form_set_error('pBLAST', t('Error: Failed to read the Blast query: Wrong format provided for FASTA protein sequence'));
  177. }
  178. else {
  179. $form_state['qFlag'] = 'seqQuery';
  180. }
  181. }
  182. // Validate Query Upload
  183. $upQuery = file_save_upload('UPLOAD', array('file_validate_extensions' => array('txt fasta fa fna')), FILE_EXISTS_RENAME);
  184. if ($upQuery) {
  185. $upQuery_uri = $upQuery->uri;
  186. $form_state['upQuery_path'] = drupal_realpath($upQuery_uri);
  187. $upQuery_content = file_get_contents($form_state['upQuery_path']);
  188. if(validateFasta($upQuery_content)){
  189. form_set_error('pBLAST', t('Error: Failed to upload the Blast query: Wrong format provided for FASTA protein sequence'));
  190. }
  191. else {
  192. $form_state['qFlag'] = 'upQuery';
  193. }
  194. }
  195. // Validate uploaded database
  196. $upDB = file_save_upload('DBUPLOAD', array('file_validate_extensions' => array('txt fasta fa fna')), FILE_EXISTS_RENAME);
  197. if ($upDB) {
  198. $upDB_uri = $upDB->uri;
  199. $form_state['upDB_path'] = drupal_realpath($upDB_uri);
  200. $upDB_content = file_get_contents($form_state['upDB_path']);
  201. if(validateFasta($upDB_content)){
  202. form_set_error('DB', t('Error: Failed to upload the Blast subject sequence file: Wrong format provided for FASTA protein sequence'));
  203. }
  204. else {
  205. $form_state['dbFlag'] = 'upQuery';
  206. }
  207. }
  208. else {
  209. $form_state['dbFlag'] = 'blastdb';
  210. }
  211. }
  212. /**
  213. * Form submition handler for blast_protein_form().
  214. *
  215. * @see blast_protein_form_submit()
  216. */
  217. function blast_protein_form_submit($form, &$form_state) {
  218. $eVal = $form_state['values']['eVal'];
  219. $trgtKey = $form_state['values']['maxTarget'];
  220. $numAlign = $form['ALG']['GParam']['maxTarget']['#options'][$trgtKey];
  221. $wsKey = $form_state['values']['wordSize'];
  222. $wordSize = $form['ALG']['GParam']['wordSize']['#options'][$wsKey];
  223. // Expand Gap Cost key into open and extend penalties
  224. $gapKey = $form_state['values']['MATRIX'];
  225. switch ($gapKey) {
  226. case 0:
  227. $matrix ="PAM30";
  228. $gapKey = $form_state['values']['gapCost'];
  229. switch ($gapKey) {
  230. case 0:
  231. $gapOpen = 7;
  232. $gapExtend = 2;
  233. break;
  234. case 1:
  235. $gapOpen = 6;
  236. $gapExtend = 2;
  237. break;
  238. case 2:
  239. $gapOpen = 5;
  240. $gapExtend = 2;
  241. break;
  242. case 3:
  243. $gapOpen = 10;
  244. $gapExtend = 1;
  245. break;
  246. case 4:
  247. $gapOpen = 9;
  248. $gapExtend = 1;
  249. break;
  250. case 5:
  251. $gapOpen = 8;
  252. $gapExtend = 1;
  253. break;
  254. }
  255. break;
  256. case 1:
  257. $matrix ="PAM70";
  258. $gapKey = $form_state['values']['gapCost'];
  259. switch ($gapKey) {
  260. case 0:
  261. $gapOpen = 8;
  262. $gapExtend = 2;
  263. break;
  264. case 1:
  265. $gapOpen = 7;
  266. $gapExtend = 2;
  267. break;
  268. case 2:
  269. $gapOpen = 6;
  270. $gapExtend = 2;
  271. break;
  272. case 3:
  273. $gapOpen = 11;
  274. $gapExtend = 1;
  275. break;
  276. case 4:
  277. $gapOpen = 10;
  278. $gapExtend = 1;
  279. break;
  280. case 5:
  281. $gapOpen = 9;
  282. $gapExtend = 1;
  283. break;
  284. }
  285. break;
  286. case 2:
  287. $matrix ="PAM250";
  288. $gapKey = $form_state['values']['gapCost'];
  289. switch ($gapKey) {
  290. case 0:
  291. $gapOpen = 15;
  292. $gapExtend = 3;
  293. break;
  294. case 1:
  295. $gapOpen = 14;
  296. $gapExtend = 3;
  297. break;
  298. case 2:
  299. $gapOpen = 13;
  300. $gapExtend = 3;
  301. break;
  302. case 3:
  303. $gapOpen = 12;
  304. $gapExtend = 3;
  305. break;
  306. case 4:
  307. $gapOpen = 11;
  308. $gapExtend = 3;
  309. break;
  310. case 5:
  311. $gapOpen = 17;
  312. $gapExtend = 2;
  313. break;
  314. case 6:
  315. $gapOpen = 16;
  316. $gapExtend = 2;
  317. break;
  318. case 7:
  319. $gapOpen = 15;
  320. $gapExtend = 2;
  321. break;
  322. case 8:
  323. $gapOpen = 14;
  324. $gapExtend = 2;
  325. break;
  326. case 9:
  327. $gapOpen = 13;
  328. $gapExtend = 2;
  329. break;
  330. case 10:
  331. $gapOpen = 21;
  332. $gapExtend = 1;
  333. break;
  334. case 11:
  335. $gapOpen = 20;
  336. $gapExtend = 1;
  337. break;
  338. case 12:
  339. $gapOpen = 19;
  340. $gapExtend = 1;
  341. break;
  342. case 13:
  343. $gapOpen = 18;
  344. $gapExtend = 1;
  345. break;
  346. case 14:
  347. $gapOpen = 17;
  348. $gapExtend = 1;
  349. break;
  350. }
  351. break;
  352. case 3:
  353. $matrix ="BLOSUM80";
  354. $gapKey = $form_state['values']['gapCost'];
  355. switch ($gapKey) {
  356. case 0:
  357. $gapOpen = 8;
  358. $gapExtend = 2;
  359. break;
  360. case 1:
  361. $gapOpen = 7;
  362. $gapExtend = 2;
  363. break;
  364. case 2:
  365. $gapOpen = 6;
  366. $gapExtend = 2;
  367. break;
  368. case 3:
  369. $gapOpen = 11;
  370. $gapExtend = 1;
  371. break;
  372. case 4:
  373. $gapOpen = 10;
  374. $gapExtend = 1;
  375. break;
  376. case 5:
  377. $gapOpen = 9;
  378. $gapExtend = 1;
  379. break;
  380. }
  381. break;
  382. case 4:
  383. $matrix ="BLOSUM62";
  384. $gapKey = $form_state['values']['gapCost'];
  385. switch ($gapKey) {
  386. case 0:
  387. $gapOpen = 11;
  388. $gapExtend = 2;
  389. break;
  390. case 1:
  391. $gapOpen = 10;
  392. $gapExtend = 2;
  393. break;
  394. case 2:
  395. $gapOpen = 9;
  396. $gapExtend = 2;
  397. break;
  398. case 3:
  399. $gapOpen = 8;
  400. $gapExtend = 2;
  401. break;
  402. case 4:
  403. $gapOpen = 7;
  404. $gapExtend = 2;
  405. break;
  406. case 5:
  407. $gapOpen = 6;
  408. $gapExtend = 2;
  409. break;
  410. case 6:
  411. $gapOpen = 13;
  412. $gapExtend = 1;
  413. break;
  414. case 7:
  415. $gapOpen = 12;
  416. $gapExtend = 1;
  417. break;
  418. case 8:
  419. $gapOpen = 11;
  420. $gapExtend = 1;
  421. break;
  422. case 9:
  423. $gapOpen = 10;
  424. $gapExtend = 1;
  425. break;
  426. case 10:
  427. $gapOpen = 9;
  428. $gapExtend = 1;
  429. break;
  430. }
  431. break;
  432. case 5:
  433. $matrix ="BLOSUM45";
  434. $gapKey = $form_state['values']['gapCost'];
  435. switch ($gapKey) {
  436. case 0:
  437. $gapOpen = 13;
  438. $gapExtend = 3;
  439. break;
  440. case 1:
  441. $gapOpen = 12;
  442. $gapExtend = 3;
  443. break;
  444. case 2:
  445. $gapOpen = 11;
  446. $gapExtend = 3;
  447. break;
  448. case 3:
  449. $gapOpen = 10;
  450. $gapExtend = 3;
  451. break;
  452. case 4:
  453. $gapOpen = 15;
  454. $gapExtend = 2;
  455. break;
  456. case 5:
  457. $gapOpen = 14;
  458. $gapExtend = 2;
  459. break;
  460. case 6:
  461. $gapOpen = 13;
  462. $gapExtend = 2;
  463. break;
  464. case 7:
  465. $gapOpen = 12;
  466. $gapExtend = 2;
  467. break;
  468. case 8:
  469. $gapOpen = 19;
  470. $gapExtend = 1;
  471. break;
  472. case 9:
  473. $gapOpen = 18;
  474. $gapExtend = 1;
  475. break;
  476. case 10:
  477. $gapOpen = 17;
  478. $gapExtend = 1;
  479. break;
  480. case 11:
  481. $gapOpen = 16;
  482. $gapExtend = 1;
  483. break;
  484. }
  485. break;
  486. case 6:
  487. $matrix ="BLOSUM50";
  488. $gapKey = $form_state['values']['gapCost'];
  489. switch ($gapKey) {
  490. case 0:
  491. $gapOpen = 13;
  492. $gapExtend = 3;
  493. break;
  494. case 1:
  495. $gapOpen = 12;
  496. $gapExtend = 3;
  497. break;
  498. case 2:
  499. $gapOpen = 11;
  500. $gapExtend = 3;
  501. break;
  502. case 3:
  503. $gapOpen = 10;
  504. $gapExtend = 3;
  505. break;
  506. case 4:
  507. $gapOpen = 9;
  508. $gapExtend = 3;
  509. break;
  510. case 5:
  511. $gapOpen = 16;
  512. $gapExtend = 2;
  513. break;
  514. case 6:
  515. $gapOpen = 15;
  516. $gapExtend = 2;
  517. break;
  518. case 7:
  519. $gapOpen = 14;
  520. $gapExtend = 2;
  521. break;
  522. case 8:
  523. $gapOpen = 13;
  524. $gapExtend = 2;
  525. break;
  526. case 9:
  527. $gapOpen = 12;
  528. $gapExtend = 2;
  529. break;
  530. case 10:
  531. $gapOpen = 19;
  532. $gapExtend = 1;
  533. break;
  534. case 11:
  535. $gapOpen = 18;
  536. $gapExtend = 1;
  537. break;
  538. case 12:
  539. $gapOpen = 17;
  540. $gapExtend = 1;
  541. break;
  542. case 13:
  543. $gapOpen = 16;
  544. $gapExtend = 1;
  545. break;
  546. case 14:
  547. $gapOpen = 15;
  548. $gapExtend = 1;
  549. break;
  550. }
  551. break;
  552. case 7:
  553. $matrix ="BLOSUM90";
  554. $gapKey = $form_state['values']['gapCost'];
  555. switch ($gapKey) {
  556. case 0:
  557. $gapOpen = 9;
  558. $gapExtend = 2;
  559. break;
  560. case 1:
  561. $gapOpen = 8;
  562. $gapExtend = 2;
  563. break;
  564. case 2:
  565. $gapOpen = 7;
  566. $gapExtend = 2;
  567. break;
  568. case 3:
  569. $gapOpen = 6;
  570. $gapExtend = 2;
  571. break;
  572. case 4:
  573. $gapOpen = 11;
  574. $gapExtend = 1;
  575. break;
  576. case 5:
  577. $gapOpen = 10;
  578. $gapExtend = 1;
  579. break;
  580. case 6:
  581. $gapOpen = 9;
  582. $gapExtend = 1;
  583. break;
  584. }
  585. break;
  586. }
  587. // If the query was submitted via the texrfield then create a file containing it
  588. if ( isset($form_state['qFlag']) ) {
  589. if ( $form_state['qFlag'] == 'seqQuery' ) {
  590. $seq_content = $form_state['values']['FASTA'];
  591. $query = "/tmp/user__query_file.fasta";
  592. file_put_contents ( $query , $seq_content);
  593. }
  594. elseif ( $form_state['qFlag'] == 'upQuery' ) {
  595. $query = $form_state['upQuery_path'];
  596. }
  597. }
  598. // If the BLAST database was uploaded then use it to run the BLAST
  599. if ($form_state['dbFlag'] == 'upQuery') {
  600. $subjectSeq = $form_state['upDB_path'];
  601. $subSeqOut = drupal_basename($form_state['upDB_path']) . rand(0, 10000);
  602. $blast_subj_cmd = "blastp -task blastp -query $query -subject $subjectSeq -out sites/default/files/$subSeqOut.blastp.html";
  603. system($blast_subj_cmd);
  604. }
  605. // Otherwise, we are using one of the website provided BLAST databases so form the
  606. // BLAST command accordingly
  607. elseif ($form_state['dbFlag'] == 'blastdb') {
  608. $selected_db = $form_state['values']['SELECT_DB'];
  609. $blastdb_node = node_load($selected_db);
  610. $blastdb_path = $blastdb_node->db_path;
  611. $blastdb_human_name = $form['DB']['SELECT_DB']['#options'][$selected_db];
  612. $subSeqOut = str_replace(' ','_', $blastdb_human_name) . rand(0, 10000);
  613. $blast_db_cmd = "blastp -task blastp -query $query -db $blastdb_path -out sites/default/files/$subSeqOut.blastp.html -evalue $eVal -word_size $wordSize -gapopen $gapOpen -gapextend $gapExtend -matrix $matrix -num_alignments 100 -html";
  614. system($blast_db_cmd,$input);
  615. }
  616. // Redirect to the BLAST Results page
  617. $path = "$subSeqOut.blastp.html";
  618. drupal_goto("blast/report/$path");
  619. }
  620. /**
  621. * FASTA validating parser
  622. *
  623. * @param $sequence
  624. * A string of characters to be validated. A sequence in FASTA format begins with a single-line description, followed by lines of sequence data.
  625. * The description line is distinguished from the sequence data by a greater-than (">") symbol in the first column.
  626. * The word following the ">" symbol is the identifier of the sequence, and the rest of the line is the description (both are optional).
  627. * There should be no space between the ">" and the first letter of the identifier. The sequence ends if another line starting with a ">" appears;
  628. * this indicates the start of another sequence.
  629. *
  630. * @return
  631. * Return a boolean. 1 if the sequence does not pass the format valifation stage and 0 otherwise.
  632. *
  633. */
  634. function validateFasta($sequence) {
  635. $fastaIdRegEx = '/^>.*(\\n|\\r)/';
  636. $fastaSeqRegEx = '/[^acgturykmswbdhvnxACGTURYKMSWBDHVNX\*\-\n\r]/';
  637. if ( preg_match($fastaSeqRegEx,$sequence) && !(preg_match($fastaIdRegEx,$sequence)) ) {
  638. $flag = 1;
  639. } else {
  640. $flag = 0;
  641. }
  642. return $flag;
  643. }
  644. /**
  645. * Generate an array of BLAST database options based on existing nodes of type BlastDB
  646. *
  647. * @return
  648. * Return human readble names of the pre-existing blast databases
  649. *
  650. */
  651. function DB_options() {
  652. $type = 'blastdb';
  653. $nodes = node_load_multiple(array(), array('type'=> $type));
  654. $options = array();
  655. foreach ($nodes as $node) {
  656. if ( isset($node) && isset($node->db_dbtype) ) {
  657. if ( ($node->db_dbtype=='p') ) {
  658. $options[$node->nid] = $node->db_name;
  659. }
  660. }
  661. }
  662. asort($options);
  663. $options[0] = 'Select a Dataset';
  664. return $options;
  665. }
  666. /**
  667. * Fill the first dropdown list with appropriate options
  668. *
  669. * @return
  670. * An array consisting of matrices name for the first dropdown list
  671. */
  672. function _ajax_example_get_first_dropdown_options() {
  673. return drupal_map_assoc(array(
  674. t('PAM30'),
  675. t('PAM70'),
  676. t('PAM250'),
  677. t('BLOSUM80'),
  678. t('BLOSUM62'),
  679. t('BLOSUM45'),
  680. t('BLOSUM50'),
  681. t('BLOSUM90'),
  682. ));
  683. }
  684. /**
  685. * Fill the second dropdown list with appropriate options
  686. *
  687. * @return
  688. * An array containing open and extension gap values for the chosen matrix (to fill the second dropdown list)
  689. */
  690. function _ajax_example_get_second_dropdown_options($key = '') {
  691. $options = array(
  692. t('PAM30') => drupal_map_assoc(array(
  693. t('Existence: 7 Extension: 2'),
  694. t('Existence: 6 Extension: 2'),
  695. t('Existence: 5 Extension: 2'),
  696. t('Existence: 10 Extension: 1'),
  697. t('Existence: 9 Extension: 1'),
  698. t('Existence: 8 Extension: 1'),
  699. )),
  700. t('PAM70') => drupal_map_assoc(array(
  701. t('Existence: 8 Extension: 2'),
  702. t('Existence: 7 Extension: 2'),
  703. t('Existence: 6 Extension: 2'),
  704. t('Existence: 11 Extension: 1'),
  705. t('Existence: 10 Extension: 1'),
  706. t('Existence: 9 Extension: 1'),
  707. )),
  708. t('PAM250') => drupal_map_assoc(array(
  709. t('Existence: 15 Extension: 3'),
  710. t('Existence: 14 Extension: 3'),
  711. t('Existence: 13 Extension: 3'),
  712. t('Existence: 12 Extension: 3'),
  713. t('Existence: 11 Extension: 3'),
  714. t('Existence: 17 Extension: 2'),
  715. t('Existence: 16 Extension: 2'),
  716. t('Existence: 15 Extension: 2'),
  717. t('Existence: 14 Extension: 2'),
  718. t('Existence: 13 Extension: 2'),
  719. t('Existence: 21 Extension: 1'),
  720. t('Existence: 20 Extension: 1'),
  721. t('Existence: 19 Extension: 1'),
  722. t('Existence: 18 Extension: 1'),
  723. t('Existence: 17 Extension: 1'),
  724. )),
  725. t('BLOSUM80') => drupal_map_assoc(array(
  726. t('Existence: 8 Extension: 2'),
  727. t('Existence: 7 Extension: 2'),
  728. t('Existence: 6 Extension: 2'),
  729. t('Existence: 11 Extension: 1'),
  730. t('Existence: 10 Extension: 1'),
  731. t('Existence: 9 Extension: 1'),
  732. )),
  733. t('BLOSUM62') => drupal_map_assoc(array(
  734. t('Existence: 11 Extension: 2'),
  735. t('Existence: 10 Extension: 2'),
  736. t('Existence: 9 Extension: 2'),
  737. t('Existence: 8 Extension: 2'),
  738. t('Existence: 7 Extension: 2'),
  739. t('Existence: 6 Extension: 2'),
  740. t('Existence: 13 Extension: 1'),
  741. t('Existence: 12 Extension: 1'),
  742. t('Existence: 11 Extension: 1'),
  743. t('Existence: 10 Extension: 1'),
  744. t('Existence: 9 Extension: 1'),
  745. )),
  746. t('BLOSUM45') => drupal_map_assoc(array(
  747. t('Existence: 13 Extension: 3'),
  748. t('Existence: 12 Extension: 3'),
  749. t('Existence: 11 Extension: 3'),
  750. t('Existence: 10 Extension: 3'),
  751. t('Existence: 15 Extension: 2'),
  752. t('Existence: 14 Extension: 2'),
  753. t('Existence: 13 Extension: 2'),
  754. t('Existence: 12 Extension: 2'),
  755. t('Existence: 19 Extension: 1'),
  756. t('Existence: 18 Extension: 1'),
  757. t('Existence: 17 Extension: 1'),
  758. t('Existence: 16 Extension: 1'),
  759. )),
  760. t('BLOSUM50') => drupal_map_assoc(array(
  761. t('Existence: 13 Extension: 3'),
  762. t('Existence: 12 Extension: 3'),
  763. t('Existence: 11 Extension: 3'),
  764. t('Existence: 10 Extension: 3'),
  765. t('Existence: 9 Extension: 3'),
  766. t('Existence: 16 Extension: 2'),
  767. t('Existence: 15 Extension: 2'),
  768. t('Existence: 14 Extension: 2'),
  769. t('Existence: 13 Extension: 2'),
  770. t('Existence: 12 Extension: 2'),
  771. t('Existence: 19 Extension: 1'),
  772. t('Existence: 18 Extension: 1'),
  773. t('Existence: 17 Extension: 1'),
  774. t('Existence: 16 Extension: 1'),
  775. t('Existence: 15 Extension: 1'),
  776. )),
  777. t('BLOSUM90') => drupal_map_assoc(array(
  778. t('Existence: 9 Extension: 2'),
  779. t('Existence: 8 Extension: 2'),
  780. t('Existence: 7 Extension: 2'),
  781. t('Existence: 6 Extension: 2'),
  782. t('Existence: 11 Extension: 1'),
  783. t('Existence: 10 Extension: 1'),
  784. t('Existence: 9 Extension: 1'),
  785. )),
  786. );
  787. if (isset($options[$key])) {
  788. return $options[$key];
  789. } else {
  790. return array();
  791. }
  792. }
  793. /**
  794. * Respond to Ajax dropdown call
  795. */
  796. function ajax_example_dependent_dropdown_callback($form, $form_state) {
  797. return $form['ALG']['SParam']['gapCost'];
  798. }