blast_ui.blastp.inc 26 KB

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