eXpress “1.5”

src/directiondetector.cpp

00001 //
00002 //  directiondetector.cpp
00003 //  express
00004 //
00005 //  Created by Adam Roberts on 11/21/12.
00006 //
00007 //
00008 
00009 #include "directiondetector.h"
00010 
00011 #include <iostream>
00012 #include "fragments.h"
00013 #include "main.h"
00014 
00015 using namespace std;
00016 
00017 DirectionDetector::DirectionDetector()
00018 : _num_fr(0), _num_rf(0), _num_f(0), _num_r(0) {}
00019 
00020 void DirectionDetector::add_fragment(Fragment* f) {
00021   foreach (FragHit* h, f->hits()) {
00022     switch(h->pair_status()) {
00023       case PAIRED: {
00024         if (h->left_read() == h->first_read()) {
00025           _num_fr++;
00026         } else {
00027           assert(h->right_read() == h->first_read());
00028           _num_rf++;
00029         }
00030         break;
00031       }
00032       case LEFT_ONLY: {
00033         _num_f++;
00034         break;
00035       }
00036       case RIGHT_ONLY: {
00037         _num_r++;
00038         break;
00039       }
00040     }
00041   }
00042 }
00043 
00044 bool DirectionDetector::report_if_improper_direction() {
00045   size_t num_paired = _num_fr + _num_rf;
00046   size_t num_single = _num_f + _num_r;
00047   if (num_paired + num_single == 0) {
00048     return false;
00049   }
00050   if (num_paired == 0) {
00051     // Single-end case
00052     double max_dir = max(_num_f, _num_r);
00053     double min_dir = min(_num_f, _num_r);
00054     if (min_dir < max_dir / 2) {
00055       if (_num_f > _num_r && direction != F) {
00056         logger.warn("The observed alignments appear disporportionately on "
00057                     "the forward strand (%d  vs. %d). If your library is "
00058                     "strand-specific and single-end, you should use the "
00059                     "--f-stranded option to avoid incorrect results.",
00060                     _num_f, _num_r);
00061         return true;
00062       } else if (_num_f < _num_r && direction != R) {
00063         logger.warn("The observed alignments appear disporportionately on "
00064                     "the reverse strand (%d vs. %d). If your library is "
00065                     "strand-specific and single-end, you should use the "
00066                     "--r-stranded option to avoid incorrect results.",
00067                     _num_r, _num_f);
00068         return true;
00069       }
00070     }
00071   } else {
00072     // Paired-end case
00073     size_t fr = _num_f + _num_fr;
00074     size_t rf = _num_r + _num_rf;
00075     double max_dir = max(fr, rf);
00076     double min_dir = min(fr, rf);
00077     if (min_dir < max_dir / 2) {
00078       if (fr > rf && direction != FR) {
00079         logger.warn("The observed alignments appear disporportionately in the"
00080                     "the forward-reverse order (%d vs %d). If your library is "
00081                     "strand-specific, you should use the --fr-stranded option "
00082                     "to avoid incorrect results.", fr, rf);
00083         return true;
00084       } else if (rf > fr && direction != RF) {
00085         logger.warn("The observed alignments appear disporportionately in "
00086                     "the reverse-forward order (%d vs. %d). If your library is "
00087                     "strand-specific, you should use the --rf-stranded option "
00088                     "to avoid incorrect results.", rf, fr);
00089         return true;
00090       }
00091     }
00092   }
00093   return false;
00094 }
00095 
00096 
 All Classes Functions Variables