blast_ui.blastp.inc 26 KB

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