~ubuntu-branches/ubuntu/feisty/ncbi-tools6/feisty

« back to all changes in this revision

Viewing changes to algo/blast/api/blast_api.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2006-07-19 23:28:07 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060719232807-et3cdmcjgmnyleyx
Tags: 6.1.20060507-3ubuntu1
Re-merge with Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: blast_api.c,v 1.20 2005/09/19 15:40:03 camacho Exp $
 
1
/* $Id: blast_api.c,v 1.33 2006/04/26 12:44:37 madden Exp $
2
2
***************************************************************************
3
3
*                                                                         *
4
4
*                             COPYRIGHT NOTICE                            *
52
52
#include <algo/blast/api/seqsrc_multiseq.h>
53
53
#include <algo/blast/api/blast_seqalign.h>
54
54
#include <algo/blast/api/dust_filter.h>
 
55
#include <algo/blast/api/blast_message_api.h>
55
56
 
56
57
/** @addtogroup CToolkitAlgoBlast
57
58
 *
102
103
 
103
104
   info->lookup_header = (BlastRPSLookupFileHeader *)lut_mmap->mmp_begin;
104
105
   if (info->lookup_header->magic_number != RPS_MAGIC_NUM) {
105
 
       if (Nlm_SwapUint4(info->lookup_header->magic_number) == RPS_MAGIC_NUM) {
 
106
       if (Nlm_SwitchUint4(info->lookup_header->magic_number)==RPS_MAGIC_NUM) {
106
107
           ErrPostEx(SEV_FATAL, 1, 0, "RPS BLAST lookup file was created "
107
108
                           "on an incompatible platform");
108
109
       }
118
119
 
119
120
   info->profile_header = (BlastRPSProfileHeader *)pssm_mmap->mmp_begin;
120
121
   if (info->profile_header->magic_number != RPS_MAGIC_NUM) {
121
 
       if (Nlm_SwapUint4(info->profile_header->magic_number) == RPS_MAGIC_NUM) {
 
122
       if (Nlm_SwitchUint4(info->profile_header->magic_number)==RPS_MAGIC_NUM) {
122
123
           ErrPostEx(SEV_FATAL, 1, 0, "RPS BLAST profile file was created "
123
124
                           "on an incompatible platform");
124
125
       }
193
194
    if (kDbName == NULL ||
194
195
        (status = s_BlastRPSInfoInit(&rps_info, rps_mmap, 
195
196
                                     rps_pssm_mmap, kDbName)) != 0) {
196
 
        Blast_MessageWrite(&extra_returns->error, 3, 1, 0,  
197
 
                           "RPS BLAST database setup failed");
 
197
        SBlastMessageWrite(&extra_returns->error, SEV_WARNING, "RPS BLAST database setup failed", NULL, FALSE);
198
198
        return status;
199
199
    }
200
200
    *rps_info_out = rps_info;
288
288
                          options->score_options, sbp, options->eff_len_options,
289
289
                          options->ext_options, options->hit_options, 
290
290
                          options->db_options)) != 0) {
291
 
            Blast_MessageWrite(&extra_returns->error, 2, 0, 0,
292
 
                "Failed to set up tabular formatting data structure");
 
291
            SBlastMessageWrite(&extra_returns->error, SEV_WARNING,
 
292
                "Failed to set up tabular formatting data structure", NULL, FALSE);
293
293
            return status;
294
294
        }
295
295
    }
329
329
           hsp_stream && extra_returns);
330
330
 
331
331
    /* Start the formatting thread */
332
 
    if(NlmThreadsAvailable() &&
 
332
    if(tf_data && NlmThreadsAvailable() &&
333
333
       (format_thread =
334
334
        NlmThreadCreate(Blast_TabularFormatThread, (void*) tf_data))
335
335
       == NULL_thread) {
336
 
        Blast_MessageWrite(&extra_returns->error, 2, 0, 0,
337
 
                           "Cannot create thread for formatting tabular output\n");
 
336
        SBlastMessageWrite(&extra_returns->error, SEV_WARNING,
 
337
                           "Cannot create thread for formatting tabular output\n", NULL, options->believe_query);
338
338
        return -1;
339
339
    }
340
340
 
375
375
                             ext_options, hit_options, eff_len_options, 
376
376
                             db_options, psi_options, sbp, hsp_stream, 
377
377
                             rps_info, pattern_blk, results)) != 0) {
378
 
                Blast_MessageWrite(&extra_returns->error, 3, 0, 0,  
379
 
                                   "Traceback engine failed\n");
 
378
                SBlastMessageWrite(&extra_returns->error, SEV_ERROR,
 
379
                                   "Traceback engine failed\n", NULL, options->believe_query);
380
380
            }
381
381
        }
382
382
    } else {
388
388
                     seq_src, score_options, sbp, lookup_wrap, word_options, 
389
389
                     ext_options, hit_options, eff_len_options, psi_options, 
390
390
                     db_options, hsp_stream, diagnostics)) != 0) {
391
 
                Blast_MessageWrite(&extra_returns->error, 3, 1, 0,  
392
 
                                   "Preliminary search engine failed\n");
 
391
                SBlastMessageWrite(&extra_returns->error, SEV_ERROR,
 
392
                                   "Preliminary search engine failed\n", NULL, options->believe_query);
393
393
            }
394
394
        } else { /* Single thread, non-tabular */
395
395
            if ((status=Blast_RunFullSearch(kProgram, query, query_info, 
396
396
                            seq_src, sbp, score_options, lookup_wrap, 
397
397
                            word_options, ext_options, hit_options, 
398
398
                            eff_len_options, psi_options, db_options, hsp_stream,
399
 
                            rps_info, diagnostics, results)) != 0) {
400
 
                Blast_MessageWrite(&extra_returns->error, 3, 1, 0,  
401
 
                                   "Blast_RunFullSearch failed\n");
 
399
                            rps_info, diagnostics, results, 0, 0)) != 0) {
 
400
                SBlastMessageWrite(&extra_returns->error, SEV_ERROR,  
 
401
                                    "Blast_RunFullSearch failed\n", NULL, options->believe_query);
402
402
            }
403
403
        }
404
404
    }
453
453
    const BlastHitSavingOptions* hit_options = options->hit_options;
454
454
    SBlastOptions* rps_options = NULL;
455
455
    const Boolean kPhiBlast = Blast_ProgramIsPhiBlast(kProgram);
 
456
    const Uint1 kDeallocateMe = 253;
 
457
    Blast_Message *core_msg = NULL;
456
458
 
457
459
    if (!query_seqloc || !seq_src || !options || !extra_returns) 
458
460
        return -1;
460
462
    if ((status = 
461
463
         BLAST_ValidateOptions(kProgram, options->ext_options, score_options, 
462
464
                               lookup_options, options->word_options, hit_options, 
463
 
                               &extra_returns->error)) != 0) {
 
465
                               &core_msg)) != 0) {
 
466
         extra_returns->error = Blast_MessageToSBlastMessage(core_msg, NULL, NULL, options->believe_query);
 
467
         core_msg = Blast_MessageFree(core_msg);
 
468
         
464
469
        return status;
465
470
    }
466
471
 
468
473
    {
469
474
         SeqLoc* dust_mask = NULL; /* Dust mask locations */
470
475
         Blast_FindDustSeqLoc(query_seqloc, options, &dust_mask);
471
 
         /* Combine dust mask with lower case mask */
472
 
         ValNodeLink(&masking_locs, dust_mask);
 
476
         /* Combine dust mask with lower case mask 
 
477
            The dust mask will be deallocated by the end of this function
 
478
            though as it's copied in BLAST_MainSetUp 
 
479
            Not deallocating it will result in a memory leak if masking_locs
 
480
            was NULL at the start of this function */
 
481
         if (dust_mask)
 
482
         {
 
483
            SeqLoc* dust_mask_var = dust_mask;
 
484
            while (dust_mask_var)
 
485
            {
 
486
               dust_mask_var->choice = kDeallocateMe;
 
487
               dust_mask_var = dust_mask_var->next;
 
488
            }
 
489
            ValNodeLink(&masking_locs, dust_mask);
 
490
         }
473
491
    }
474
492
 
475
493
    if (kRpsBlast) {
485
503
 
486
504
    if ((status = BLAST_SetUpQuery(kProgram, query_seqloc, query_options, 
487
505
                                   masking_locs, &query_info, &query))) {
488
 
        Blast_MessageWrite(&extra_returns->error, 3, 0, 0,  
489
 
                           "BLAST_SetUpQuery returned non-zero status\n");
 
506
        SBlastMessageWrite(&extra_returns->error, SEV_ERROR,  
 
507
                "BLAST_SetUpQuery returned non-zero status\n", NULL, FALSE);
490
508
        return status;
491
509
    }
492
510
 
493
511
    status = 
494
512
        BLAST_MainSetUp(kProgram, query_options, score_options, query, 
495
513
                        query_info, scale_factor, &lookup_segments, &mask_loc,
496
 
                        &sbp, &extra_returns->error);
 
514
                        &sbp, &core_msg);
 
515
    if (core_msg)
 
516
    {
 
517
       extra_returns->error = Blast_MessageToSBlastMessage(core_msg, query_seqloc, query_info, options->believe_query);
 
518
       core_msg = Blast_MessageFree(core_msg);
 
519
    }
 
520
 
 
521
    if (status)
 
522
        return status;
497
523
 
498
524
    if (filter_out) {
499
525
        *filter_out = 
500
526
            BlastMaskLocToSeqLoc(kProgram, mask_loc, query_seqloc);
501
527
    }
502
 
    
 
528
 
503
529
    /* Mask locations in BlastMaskLoc form are no longer needed. */
504
530
    BlastMaskLocFree(mask_loc);
505
 
    
506
 
    if (status)
507
 
        return status;
 
531
 
 
532
    if (masking_locs)
 
533
    {
 
534
          SeqLocPtr slp_var = masking_locs;
 
535
          SeqLocPtr last = NULL;
 
536
          while (slp_var)
 
537
          {
 
538
              if (slp_var->choice == kDeallocateMe)
 
539
              {
 
540
                  if (last == NULL)
 
541
                  {
 
542
                     masking_locs = slp_var->next;
 
543
                     slp_var->next = NULL;
 
544
                     Blast_ValNodeMaskListFree(slp_var);
 
545
                     slp_var = masking_locs;
 
546
                  }
 
547
                  else
 
548
                  {
 
549
                     last->next = slp_var->next;
 
550
                     slp_var->next = NULL;
 
551
                     Blast_ValNodeMaskListFree(slp_var);
 
552
                     slp_var = last->next;
 
553
                  }
 
554
              } 
 
555
              else
 
556
              {
 
557
                  last = slp_var;
 
558
                  slp_var = slp_var->next;
 
559
              }
 
560
          }
 
561
    }
508
562
 
509
563
    if ((status = LookupTableWrapInit(query, lookup_options, 
510
564
                        lookup_segments, sbp, &lookup_wrap, rps_info)))
518
572
        Blast_SetPHIPatternInfo(kProgram, pattern_blk, query, lookup_segments, 
519
573
                                query_info);
520
574
    }
 
575
    /* Only need for the setup of lookup table. */
 
576
    lookup_segments = BlastSeqLocFree(lookup_segments);
521
577
 
522
578
    if ((status = s_BlastHSPStreamSetUp(query, query_info, seq_src, options, sbp,
523
579
                                        tf_data, &hsp_stream, extra_returns)))
529
585
        return status;
530
586
    
531
587
    lookup_wrap = LookupTableWrapFree(lookup_wrap);
532
 
    /* The following works because the ListNodes' data point to simple
533
 
       double-integer structures */
534
 
    lookup_segments = BlastSeqLocFree(lookup_segments);
535
588
    
536
589
    query = BlastSequenceBlkFree(query);
537
590
    query_info = BlastQueryInfoFree(query_info);
548
601
                     SeqLoc* masking_locs,
549
602
                     const SBlastOptions* options,
550
603
                     BlastTabularFormatData* tf_data,
551
 
                     SeqAlign **seqalign_out,
 
604
                     SBlastSeqalignArray* *seqalign_arr,
552
605
                     SeqLoc** filter_out,
553
606
                     Blast_SummaryReturn* extra_returns)
554
607
{
572
625
    seq_src = ReaddbBlastSeqSrcAttach(rdfp);
573
626
 
574
627
    if (seq_src == NULL) {
575
 
        Blast_MessageWrite(&extra_returns->error, 2, 1, 0,  
576
 
                           "Initialization of subject sequences source failed");
 
628
        SBlastMessageWrite(&extra_returns->error, SEV_WARNING,
 
629
                           "Initialization of subject sequences source failed", NULL, options->believe_query);
577
630
    } else {
578
631
        char* error_str = BlastSeqSrcGetInitError(seq_src);
579
632
        if (error_str)
580
 
            Blast_MessageWrite(&extra_returns->error, 2, 1, 0, error_str); 
 
633
            SBlastMessageWrite(&extra_returns->error, SEV_WARNING, error_str, NULL, options->believe_query); 
581
634
    }
582
635
 
583
636
    /* If there was an error initializing the sequence source, return without 
595
648
 
596
649
    if (!status && !tf_data) {
597
650
        status = 
598
 
            BLAST_ResultsToSeqAlign(options->program, results, 
 
651
            BLAST_ResultsToSeqAlign(options->program, &results, 
599
652
                                    query_seqloc, rdfp, NULL, 
600
653
                                    options->score_options->gapped_calculation,
601
654
                                    options->score_options->is_ooframe, 
602
 
                                    seqalign_out);
 
655
                                    seqalign_arr);
603
656
    }
604
657
 
605
658
    readdb_destruct(rdfp);
606
 
    results = Blast_HSPResultsFree(results);
607
659
 
608
660
    if (status)
609
661
        return status;
617
669
 *                mixed together. On return points to NULL. [in]
618
670
 * @param pattern_info Query pattern occurrences information [in]
619
671
 * @param program Program type (phiblastp or phiblastn) [in]
 
672
 * @param query_seqloc List of query locations [in]
 
673
 * @param rdfp blast db object [in]
620
674
 * @param phivnps List of ValNodes containing Seq-aligns. [out]
621
675
 * @return Status, 0 on success, -1 on failure.
622
676
 */
637
691
 
638
692
        for (pattern_index = 0; pattern_index < pattern_info->num_patterns;
639
693
             ++pattern_index) {
 
694
            SBlastSeqalignArray* seqalign_arr = NULL;
640
695
            SeqAlign* seqalign = NULL;
641
696
            BlastHSPResults* one_phi_results = phi_results[pattern_index];
642
697
 
646
701
                 * call.
647
702
                 */
648
703
                status =
649
 
                    BLAST_ResultsToSeqAlign(program, one_phi_results, 
 
704
                    BLAST_ResultsToSeqAlign(program, &one_phi_results, 
650
705
                                            query_seqloc, rdfp, NULL, TRUE, 
651
 
                                            FALSE, &seqalign);
 
706
                                            FALSE, &seqalign_arr);
 
707
                if (seqalign_arr)
 
708
                {
 
709
                    seqalign = seqalign_arr->array[0];
 
710
                    seqalign_arr->array[0] = NULL;
 
711
                    SBlastSeqalignArrayFree(seqalign_arr);
 
712
                }
652
713
                ValNodeAddPointer(phivnps, pattern_index, seqalign);
653
 
 
654
 
                one_phi_results = Blast_HSPResultsFree(one_phi_results);
655
714
            }
656
715
        }
657
716
        sfree(phi_results);
682
741
    seq_src = ReaddbBlastSeqSrcAttach(rdfp);
683
742
 
684
743
    if (seq_src == NULL) {
685
 
        Blast_MessageWrite(&extra_returns->error, 2, 1, 0,
686
 
                           "Initialization of subject sequences source failed");
 
744
        SBlastMessageWrite(&extra_returns->error, SEV_WARNING,
 
745
                           "Initialization of subject sequences source failed", NULL, options->believe_query);
687
746
    } else {
688
747
        char* error_str = BlastSeqSrcGetInitError(seq_src);
689
748
        if (error_str)
690
 
            Blast_MessageWrite(&extra_returns->error, 2, 1, 0, error_str);
 
749
            SBlastMessageWrite(&extra_returns->error, SEV_WARNING, error_str, NULL, options->believe_query);
691
750
    }
692
751
 
693
752
    /* If there was an error initializing the sequence source, return without
726
785
                            SeqLoc* masking_locs,
727
786
                            const SBlastOptions* options,
728
787
                            BlastTabularFormatData* tf_data,
729
 
                            SeqAlign **seqalign_out,
 
788
                            SBlastSeqalignArray* *seqalign_arr,
730
789
                            SeqLoc** filter_out,
731
790
                            Blast_SummaryReturn* extra_returns)
732
791
{
734
793
    Int2 status = 0;
735
794
    BlastHSPResults* results = NULL;
736
795
 
 
796
 
737
797
    if (!options || !query_seqloc || !subject_seqloc || !extra_returns)
738
798
        return -1;
739
799
 
 
800
 
740
801
    seq_src = MultiSeqBlastSeqSrcInit(subject_seqloc, options->program);
741
802
 
742
803
    if (seq_src == NULL) {
743
 
        Blast_MessageWrite(&extra_returns->error, 2, 1, 0,  
744
 
                           "Initialization of subject sequences source failed");
 
804
        SBlastMessageWrite(&extra_returns->error, SEV_WARNING,
 
805
                           "Initialization of subject sequences source failed", NULL, options->believe_query);
745
806
    } else {
746
807
        char* error_str = BlastSeqSrcGetInitError(seq_src);
747
808
        if (error_str)
748
 
            Blast_MessageWrite(&extra_returns->error, 2, 1, 0, error_str); 
 
809
            SBlastMessageWrite(&extra_returns->error, SEV_WARNING, error_str, NULL, options->believe_query); 
749
810
    }
750
811
 
751
812
    /* If there was an error initializing the sequence source, return without 
763
824
 
764
825
    if (!status) {
765
826
        status = 
766
 
            BLAST_ResultsToSeqAlign(options->program, results, query_seqloc, 
 
827
            BLAST_ResultsToSeqAlign(options->program, &results, query_seqloc, 
767
828
                                    NULL, subject_seqloc, 
768
829
                                    options->score_options->gapped_calculation,
769
830
                                    options->score_options->is_ooframe, 
770
 
                                    seqalign_out);
 
831
                                    seqalign_arr);
771
832
    }
772
833
 
773
 
    results = Blast_HSPResultsFree(results);
774
 
 
775
834
    if (status)
776
835
        return status;
777
836