blast_ui.blastp.inc 22 KB

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