blast_ui.blastp.inc 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  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. // Validate query sequence
  213. $fastaSeq = $form_state['input']['FASTA'];
  214. if (isset($fastaSeq)) {
  215. if (validateFasta($fastaSeq)){
  216. form_set_error('pBLAST', t('Error: Failed to read the Blast query: Wrong format provided for FASTA protein sequence'));
  217. }
  218. else {
  219. $form_state['qFlag'] = 'seqQuery';
  220. }
  221. }
  222. // Validate Query Upload
  223. $upQuery = file_save_upload('UPLOAD', array('file_validate_extensions' => array('txt fasta fa fna')), FILE_EXISTS_RENAME);
  224. if ($upQuery) {
  225. $upQuery_uri = $upQuery->uri;
  226. $form_state['upQuery_path'] = drupal_realpath($upQuery_uri);
  227. $upQuery_content = file_get_contents($form_state['upQuery_path']);
  228. if(validateFasta($upQuery_content)){
  229. form_set_error('pBLAST', t('Error: Failed to upload the Blast query: Wrong format provided for FASTA protein sequence'));
  230. }
  231. else {
  232. $form_state['qFlag'] = 'upQuery';
  233. }
  234. }
  235. // Validate uploaded database
  236. $upDB = file_save_upload('DBUPLOAD', array('file_validate_extensions' => array('txt fasta fa fna')), FILE_EXISTS_RENAME);
  237. if ($upDB) {
  238. $upDB_uri = $upDB->uri;
  239. $form_state['upDB_path'] = drupal_realpath($upDB_uri);
  240. $upDB_content = file_get_contents($form_state['upDB_path']);
  241. if(validateFasta($upDB_content)){
  242. form_set_error('DB', t('Error: Failed to upload the Blast subject sequence file: Wrong format provided for FASTA protein sequence'));
  243. }
  244. else {
  245. $form_state['dbFlag'] = 'upQuery';
  246. }
  247. }
  248. else {
  249. $form_state['dbFlag'] = 'blastdb';
  250. }
  251. }
  252. /**
  253. * Form submition handler for blast_protein_form().
  254. *
  255. * @see blast_protein_form_submit()
  256. */
  257. function blast_protein_form_submit($form, &$form_state) {
  258. $eVal = $form_state['values']['eVal'];
  259. $trgtKey = $form_state['values']['maxTarget'];
  260. $numAlign = $form['ALG']['GParam']['maxTarget']['#options'][$trgtKey];
  261. $wsKey = $form_state['values']['wordSize'];
  262. $wordSize = $form['ALG']['GParam']['wordSize']['#options'][$wsKey];
  263. // Expand Gap Cost key into open and extend penalties
  264. $gapKey = $form_state['values']['MATRIX'];
  265. switch ($gapKey) {
  266. case 0:
  267. $matrix ="PAM30";
  268. $gapKey = $form_state['values']['gapCost'];
  269. switch ($gapKey) {
  270. case 0:
  271. $gapOpen = 7;
  272. $gapExtend = 2;
  273. break;
  274. case 1:
  275. $gapOpen = 6;
  276. $gapExtend = 2;
  277. break;
  278. case 2:
  279. $gapOpen = 5;
  280. $gapExtend = 2;
  281. break;
  282. case 3:
  283. $gapOpen = 10;
  284. $gapExtend = 1;
  285. break;
  286. case 4:
  287. $gapOpen = 9;
  288. $gapExtend = 1;
  289. break;
  290. case 5:
  291. $gapOpen = 8;
  292. $gapExtend = 1;
  293. break;
  294. }
  295. break;
  296. case 1:
  297. $matrix ="PAM70";
  298. $gapKey = $form_state['values']['gapCost'];
  299. switch ($gapKey) {
  300. case 0:
  301. $gapOpen = 8;
  302. $gapExtend = 2;
  303. break;
  304. case 1:
  305. $gapOpen = 7;
  306. $gapExtend = 2;
  307. break;
  308. case 2:
  309. $gapOpen = 6;
  310. $gapExtend = 2;
  311. break;
  312. case 3:
  313. $gapOpen = 11;
  314. $gapExtend = 1;
  315. break;
  316. case 4:
  317. $gapOpen = 10;
  318. $gapExtend = 1;
  319. break;
  320. case 5:
  321. $gapOpen = 9;
  322. $gapExtend = 1;
  323. break;
  324. }
  325. break;
  326. case 2:
  327. $matrix ="PAM250";
  328. $gapKey = $form_state['values']['gapCost'];
  329. switch ($gapKey) {
  330. case 0:
  331. $gapOpen = 15;
  332. $gapExtend = 3;
  333. break;
  334. case 1:
  335. $gapOpen = 14;
  336. $gapExtend = 3;
  337. break;
  338. case 2:
  339. $gapOpen = 13;
  340. $gapExtend = 3;
  341. break;
  342. case 3:
  343. $gapOpen = 12;
  344. $gapExtend = 3;
  345. break;
  346. case 4:
  347. $gapOpen = 11;
  348. $gapExtend = 3;
  349. break;
  350. case 5:
  351. $gapOpen = 17;
  352. $gapExtend = 2;
  353. break;
  354. case 6:
  355. $gapOpen = 16;
  356. $gapExtend = 2;
  357. break;
  358. case 7:
  359. $gapOpen = 15;
  360. $gapExtend = 2;
  361. break;
  362. case 8:
  363. $gapOpen = 14;
  364. $gapExtend = 2;
  365. break;
  366. case 9:
  367. $gapOpen = 13;
  368. $gapExtend = 2;
  369. break;
  370. case 10:
  371. $gapOpen = 21;
  372. $gapExtend = 1;
  373. break;
  374. case 11:
  375. $gapOpen = 20;
  376. $gapExtend = 1;
  377. break;
  378. case 12:
  379. $gapOpen = 19;
  380. $gapExtend = 1;
  381. break;
  382. case 13:
  383. $gapOpen = 18;
  384. $gapExtend = 1;
  385. break;
  386. case 14:
  387. $gapOpen = 17;
  388. $gapExtend = 1;
  389. break;
  390. }
  391. break;
  392. case 3:
  393. $matrix ="BLOSUM80";
  394. $gapKey = $form_state['values']['gapCost'];
  395. switch ($gapKey) {
  396. case 0:
  397. $gapOpen = 8;
  398. $gapExtend = 2;
  399. break;
  400. case 1:
  401. $gapOpen = 7;
  402. $gapExtend = 2;
  403. break;
  404. case 2:
  405. $gapOpen = 6;
  406. $gapExtend = 2;
  407. break;
  408. case 3:
  409. $gapOpen = 11;
  410. $gapExtend = 1;
  411. break;
  412. case 4:
  413. $gapOpen = 10;
  414. $gapExtend = 1;
  415. break;
  416. case 5:
  417. $gapOpen = 9;
  418. $gapExtend = 1;
  419. break;
  420. }
  421. break;
  422. case 4:
  423. $matrix ="BLOSUM62";
  424. $gapKey = $form_state['values']['gapCost'];
  425. switch ($gapKey) {
  426. case 0:
  427. $gapOpen = 11;
  428. $gapExtend = 2;
  429. break;
  430. case 1:
  431. $gapOpen = 10;
  432. $gapExtend = 2;
  433. break;
  434. case 2:
  435. $gapOpen = 9;
  436. $gapExtend = 2;
  437. break;
  438. case 3:
  439. $gapOpen = 8;
  440. $gapExtend = 2;
  441. break;
  442. case 4:
  443. $gapOpen = 7;
  444. $gapExtend = 2;
  445. break;
  446. case 5:
  447. $gapOpen = 6;
  448. $gapExtend = 2;
  449. break;
  450. case 6:
  451. $gapOpen = 13;
  452. $gapExtend = 1;
  453. break;
  454. case 7:
  455. $gapOpen = 12;
  456. $gapExtend = 1;
  457. break;
  458. case 8:
  459. $gapOpen = 11;
  460. $gapExtend = 1;
  461. break;
  462. case 9:
  463. $gapOpen = 10;
  464. $gapExtend = 1;
  465. break;
  466. case 10:
  467. $gapOpen = 9;
  468. $gapExtend = 1;
  469. break;
  470. }
  471. break;
  472. case 5:
  473. $matrix ="BLOSUM45";
  474. $gapKey = $form_state['values']['gapCost'];
  475. switch ($gapKey) {
  476. case 0:
  477. $gapOpen = 13;
  478. $gapExtend = 3;
  479. break;
  480. case 1:
  481. $gapOpen = 12;
  482. $gapExtend = 3;
  483. break;
  484. case 2:
  485. $gapOpen = 11;
  486. $gapExtend = 3;
  487. break;
  488. case 3:
  489. $gapOpen = 10;
  490. $gapExtend = 3;
  491. break;
  492. case 4:
  493. $gapOpen = 15;
  494. $gapExtend = 2;
  495. break;
  496. case 5:
  497. $gapOpen = 14;
  498. $gapExtend = 2;
  499. break;
  500. case 6:
  501. $gapOpen = 13;
  502. $gapExtend = 2;
  503. break;
  504. case 7:
  505. $gapOpen = 12;
  506. $gapExtend = 2;
  507. break;
  508. case 8:
  509. $gapOpen = 19;
  510. $gapExtend = 1;
  511. break;
  512. case 9:
  513. $gapOpen = 18;
  514. $gapExtend = 1;
  515. break;
  516. case 10:
  517. $gapOpen = 17;
  518. $gapExtend = 1;
  519. break;
  520. case 11:
  521. $gapOpen = 16;
  522. $gapExtend = 1;
  523. break;
  524. }
  525. break;
  526. case 6:
  527. $matrix ="BLOSUM50";
  528. $gapKey = $form_state['values']['gapCost'];
  529. switch ($gapKey) {
  530. case 0:
  531. $gapOpen = 13;
  532. $gapExtend = 3;
  533. break;
  534. case 1:
  535. $gapOpen = 12;
  536. $gapExtend = 3;
  537. break;
  538. case 2:
  539. $gapOpen = 11;
  540. $gapExtend = 3;
  541. break;
  542. case 3:
  543. $gapOpen = 10;
  544. $gapExtend = 3;
  545. break;
  546. case 4:
  547. $gapOpen = 9;
  548. $gapExtend = 3;
  549. break;
  550. case 5:
  551. $gapOpen = 16;
  552. $gapExtend = 2;
  553. break;
  554. case 6:
  555. $gapOpen = 15;
  556. $gapExtend = 2;
  557. break;
  558. case 7:
  559. $gapOpen = 14;
  560. $gapExtend = 2;
  561. break;
  562. case 8:
  563. $gapOpen = 13;
  564. $gapExtend = 2;
  565. break;
  566. case 9:
  567. $gapOpen = 12;
  568. $gapExtend = 2;
  569. break;
  570. case 10:
  571. $gapOpen = 19;
  572. $gapExtend = 1;
  573. break;
  574. case 11:
  575. $gapOpen = 18;
  576. $gapExtend = 1;
  577. break;
  578. case 12:
  579. $gapOpen = 17;
  580. $gapExtend = 1;
  581. break;
  582. case 13:
  583. $gapOpen = 16;
  584. $gapExtend = 1;
  585. break;
  586. case 14:
  587. $gapOpen = 15;
  588. $gapExtend = 1;
  589. break;
  590. }
  591. break;
  592. case 7:
  593. $matrix ="BLOSUM90";
  594. $gapKey = $form_state['values']['gapCost'];
  595. switch ($gapKey) {
  596. case 0:
  597. $gapOpen = 9;
  598. $gapExtend = 2;
  599. break;
  600. case 1:
  601. $gapOpen = 8;
  602. $gapExtend = 2;
  603. break;
  604. case 2:
  605. $gapOpen = 7;
  606. $gapExtend = 2;
  607. break;
  608. case 3:
  609. $gapOpen = 6;
  610. $gapExtend = 2;
  611. break;
  612. case 4:
  613. $gapOpen = 11;
  614. $gapExtend = 1;
  615. break;
  616. case 5:
  617. $gapOpen = 10;
  618. $gapExtend = 1;
  619. break;
  620. case 6:
  621. $gapOpen = 9;
  622. $gapExtend = 1;
  623. break;
  624. }
  625. break;
  626. }
  627. // If the query was submitted via the texrfield then create a file containing it
  628. if ( isset($form_state['qFlag']) ) {
  629. if ( $form_state['qFlag'] == 'seqQuery' ) {
  630. $seq_content = $form_state['values']['FASTA'];
  631. $query = "/tmp/user__query_file.fasta";
  632. file_put_contents ( $query , $seq_content);
  633. }
  634. elseif ( $form_state['qFlag'] == 'upQuery' ) {
  635. $query = $form_state['upQuery_path'];
  636. }
  637. }
  638. // If the BLAST database was uploaded then use it to run the BLAST
  639. if ($form_state['dbFlag'] == 'upQuery') {
  640. // Since we only support using the -db flag (not -subject) we need to create a
  641. // blast database for the FASTA uploaded.
  642. // NOTE: We can't support subject because we need to generate the ASN.1+ format
  643. // to provide multiple download type options from the same BLAST
  644. $blastdb_with_path = $form_state['upDB_path'];
  645. system("makeblastdb -in $blastdb_with_path -dbtype prot -parse_seqids");
  646. }
  647. // Otherwise, we are using one of the website provided BLAST databases so form the
  648. // BLAST command accordingly
  649. elseif ($form_state['dbFlag'] == 'blastdb') {
  650. $selected_db = $form_state['values']['SELECT_DB'];
  651. $blastdb_node = node_load($selected_db);
  652. $blastdb_with_path = $blastdb_node->db_path;
  653. }
  654. // Actually submit the BLAST Tripal Job
  655. // NOTE: Tripal jobs needs to be executed from the command-line before it will be run!!
  656. $blastdb_with_suffix = $blastdb_with_path . '.psq';
  657. if (is_readable($blastdb_with_suffix)) {
  658. global $user;
  659. $output_filestub = date('YMd_His');
  660. $job_args = array(
  661. 'program' => 'blastp',
  662. 'query' => $query,
  663. 'database' => $blastdb_with_path,
  664. 'output_filename' => $output_filestub,
  665. 'options' => array(
  666. 'evalue' => $eVal,
  667. 'word_size' => $wordSize,
  668. 'gapopen' => $gapOpen,
  669. 'gapextend' => $gapExtend,
  670. 'matrix' => $matrix
  671. )
  672. );
  673. $job_id = tripal_add_job("BLAST (blastp): $query",'blast_job','run_BLAST_tripal_job', $job_args, $user->uid);
  674. // Redirect to the BLAST results page
  675. drupal_goto("blast/report/$job_id");
  676. }
  677. else {
  678. $dbfile_uploaded_msg = ($form_state['dbFlag'] == 'upQuery') ? 'The BLAST database was submitted via user upload.' : 'Existing BLAST Database was chosen';
  679. tripal_report_error(
  680. 'blast_ui',
  681. TRIPAL_ERROR,
  682. "BLAST database %db unaccessible. $dbfile_uploaded_msg",
  683. array('%db' => $blastdb_with_path)
  684. );
  685. drupal_set_message('BLAST database unaccessible. Please contact the site administrator.','error');
  686. }
  687. }
  688. /**
  689. * FASTA validating parser
  690. *
  691. * @param $sequence
  692. * A string of characters to be validated. A sequence in FASTA format begins with a single-line description, followed by lines of sequence data.
  693. * The description line is distinguished from the sequence data by a greater-than (">") symbol in the first column.
  694. * The word following the ">" symbol is the identifier of the sequence, and the rest of the line is the description (both are optional).
  695. * There should be no space between the ">" and the first letter of the identifier. The sequence ends if another line starting with a ">" appears;
  696. * this indicates the start of another sequence.
  697. *
  698. * @return
  699. * Return a boolean. 1 if the sequence does not pass the format valifation stage and 0 otherwise.
  700. *
  701. */
  702. function validateFasta($sequence) {
  703. $fastaIdRegEx = '/^>.*(\\n|\\r)/';
  704. $fastaSeqRegEx = '/[^acgturykmswbdhvnxACGTURYKMSWBDHVNX\*\-\n\r]/';
  705. if ( preg_match($fastaSeqRegEx,$sequence) && !(preg_match($fastaIdRegEx,$sequence)) ) {
  706. $flag = 1;
  707. } else {
  708. $flag = 0;
  709. }
  710. return $flag;
  711. }
  712. /**
  713. * Fill the first dropdown list with appropriate options
  714. *
  715. * @return
  716. * An array consisting of matrices name for the first dropdown list
  717. */
  718. function _ajax_example_get_first_dropdown_options() {
  719. return drupal_map_assoc(array(
  720. t('PAM30'),
  721. t('PAM70'),
  722. t('PAM250'),
  723. t('BLOSUM80'),
  724. t('BLOSUM62'),
  725. t('BLOSUM45'),
  726. t('BLOSUM50'),
  727. t('BLOSUM90'),
  728. ));
  729. }
  730. /**
  731. * Fill the second dropdown list with appropriate options
  732. *
  733. * @return
  734. * An array containing open and extension gap values for the chosen matrix (to fill the second dropdown list)
  735. */
  736. function _ajax_example_get_second_dropdown_options($key = '') {
  737. $options = array(
  738. t('PAM30') => drupal_map_assoc(array(
  739. t('Existence: 7 Extension: 2'),
  740. t('Existence: 6 Extension: 2'),
  741. t('Existence: 5 Extension: 2'),
  742. t('Existence: 10 Extension: 1'),
  743. t('Existence: 9 Extension: 1'),
  744. t('Existence: 8 Extension: 1'),
  745. )),
  746. t('PAM70') => drupal_map_assoc(array(
  747. t('Existence: 8 Extension: 2'),
  748. t('Existence: 7 Extension: 2'),
  749. t('Existence: 6 Extension: 2'),
  750. t('Existence: 11 Extension: 1'),
  751. t('Existence: 10 Extension: 1'),
  752. t('Existence: 9 Extension: 1'),
  753. )),
  754. t('PAM250') => drupal_map_assoc(array(
  755. t('Existence: 15 Extension: 3'),
  756. t('Existence: 14 Extension: 3'),
  757. t('Existence: 13 Extension: 3'),
  758. t('Existence: 12 Extension: 3'),
  759. t('Existence: 11 Extension: 3'),
  760. t('Existence: 17 Extension: 2'),
  761. t('Existence: 16 Extension: 2'),
  762. t('Existence: 15 Extension: 2'),
  763. t('Existence: 14 Extension: 2'),
  764. t('Existence: 13 Extension: 2'),
  765. t('Existence: 21 Extension: 1'),
  766. t('Existence: 20 Extension: 1'),
  767. t('Existence: 19 Extension: 1'),
  768. t('Existence: 18 Extension: 1'),
  769. t('Existence: 17 Extension: 1'),
  770. )),
  771. t('BLOSUM80') => drupal_map_assoc(array(
  772. t('Existence: 8 Extension: 2'),
  773. t('Existence: 7 Extension: 2'),
  774. t('Existence: 6 Extension: 2'),
  775. t('Existence: 11 Extension: 1'),
  776. t('Existence: 10 Extension: 1'),
  777. t('Existence: 9 Extension: 1'),
  778. )),
  779. t('BLOSUM62') => drupal_map_assoc(array(
  780. t('Existence: 11 Extension: 2'),
  781. t('Existence: 10 Extension: 2'),
  782. t('Existence: 9 Extension: 2'),
  783. t('Existence: 8 Extension: 2'),
  784. t('Existence: 7 Extension: 2'),
  785. t('Existence: 6 Extension: 2'),
  786. t('Existence: 13 Extension: 1'),
  787. t('Existence: 12 Extension: 1'),
  788. t('Existence: 11 Extension: 1'),
  789. t('Existence: 10 Extension: 1'),
  790. t('Existence: 9 Extension: 1'),
  791. )),
  792. t('BLOSUM45') => drupal_map_assoc(array(
  793. t('Existence: 13 Extension: 3'),
  794. t('Existence: 12 Extension: 3'),
  795. t('Existence: 11 Extension: 3'),
  796. t('Existence: 10 Extension: 3'),
  797. t('Existence: 15 Extension: 2'),
  798. t('Existence: 14 Extension: 2'),
  799. t('Existence: 13 Extension: 2'),
  800. t('Existence: 12 Extension: 2'),
  801. t('Existence: 19 Extension: 1'),
  802. t('Existence: 18 Extension: 1'),
  803. t('Existence: 17 Extension: 1'),
  804. t('Existence: 16 Extension: 1'),
  805. )),
  806. t('BLOSUM50') => 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: 9 Extension: 3'),
  812. t('Existence: 16 Extension: 2'),
  813. t('Existence: 15 Extension: 2'),
  814. t('Existence: 14 Extension: 2'),
  815. t('Existence: 13 Extension: 2'),
  816. t('Existence: 12 Extension: 2'),
  817. t('Existence: 19 Extension: 1'),
  818. t('Existence: 18 Extension: 1'),
  819. t('Existence: 17 Extension: 1'),
  820. t('Existence: 16 Extension: 1'),
  821. t('Existence: 15 Extension: 1'),
  822. )),
  823. t('BLOSUM90') => drupal_map_assoc(array(
  824. t('Existence: 9 Extension: 2'),
  825. t('Existence: 8 Extension: 2'),
  826. t('Existence: 7 Extension: 2'),
  827. t('Existence: 6 Extension: 2'),
  828. t('Existence: 11 Extension: 1'),
  829. t('Existence: 10 Extension: 1'),
  830. t('Existence: 9 Extension: 1'),
  831. )),
  832. );
  833. if (isset($options[$key])) {
  834. return $options[$key];
  835. } else {
  836. return array();
  837. }
  838. }
  839. /**
  840. * Respond to Ajax dropdown call
  841. */
  842. function ajax_example_dependent_dropdown_callback($form, $form_state) {
  843. return $form['ALG']['SParam']['gapCost'];
  844. }
  845. // call back function for example sequence
  846. function ajax_protein_text_area_callback($form, $form_state) {
  847. $element = $form['query']['FASTA']; // Get example Protein sequence
  848. $element['#value'] =
  849. '>gi|166477|gb|AAA96434.1| resveratrol synthase [Arachis hypogaea]
  850. MVSVSGIRKVQRAEGPATVLAIGTANPPNCIDQSTYADYYFRVTNSEHMTDLKKKFQRICERTQIKNRHM
  851. YLTEEILKENPNMCAYKAPSLDAREDMMIREVPRVGKEAATKAIKEWGQPMSKITHLIFCTTSGVALPGV
  852. DYELIVLLGLDPCVKRYMMYHQGCFAGGTVLRLAKDLAENNKDARVLIVCSENTAVTFRGPSETDMDSLV
  853. GQALFADGAAAIIIGSDPVPEVEKPIFELVSTDQKLVPGSHGAIGGLLREVGLTFYLNKSVPDIISQNIN
  854. DALNKAFDPLGISDYNSIFWIAHPGGRAILDQVEQKVNLKPEKMKATRDVLSNYGNMSSACVFFIMDLMR
  855. KRSLEEGLKTTGEGLDWGVLFGFGPGLTIETVVLRSVAI';
  856. return $element;
  857. }