Changeset 3475


Ignore:
Timestamp:
Mar 8, 2016, 9:05:33 AM (6 years ago)
Author:
Peter
Message:

closes #859

New class handling Fasta files that have an index file (see samtools
faidx). Allow easy random access to the Fasta file.

A new functor that calculates the genomic complement of a char, e.g. A
-> T. A function using this functor on a range as well as combined
with reverse to create reverse complement which is more common.

Location:
trunk
Files:
6 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Makefile.am

    r3474 r3475  
    5858  test/deleter.test \
    5959  test/distance.test \
    60   test/dna.test test/ensemble.test test/feature_selection.test \
     60  test/dna.test \
     61  test/dna_reverse_complement.test \
     62  test/ensemble.test \
     63  test/fasta.test \
     64  test/feature_selection.test \
    6165  test/fileutil.test \
    6266  test/fisher.test test/genomic_position.test test/getline_iterator.test \
     
    309313check_DATA  = test/data/foo.sorted.bam
    310314check_DATA += test/data/foo.sorted.bam.bai
     315check_DATA += test/data/foo.fasta
     316check_DATA += test/data/foo.fasta.fai
    311317
    312318test/data/.dirstamp:
     
    322328  $(AM_V_GEN)
    323329  $(AM_V_at)$(SAMTOOLS) index test/data/foo.sorted.bam
     330
     331test/data/foo.fasta: test/data/foo.sorted.bam
     332  $(AM_V_GEN)
     333  $(AM_V_at)$(SAMTOOLS) fasta test/data/foo.sorted.bam > $@
     334
     335test/data/foo.fasta.fai: test/data/foo.fasta
     336  $(AM_V_GEN)
     337  $(AM_V_at)$(SAMTOOLS) faidx test/data/foo.fasta
     338
    324339else
    325340test/data/foo.sorted.bam: test/data/.dirstamp
     
    328343test/data/foo.sorted.bam.bai: test/data/.dirstamp
    329344  $(AM_V_at): > $@
     345
     346test/data/foo.fasta: test/data/.dirstamp
     347  $(AM_V_at): > $@
     348
     349test/data/foo.fasta.fai: test/data/.dirstamp
     350  $(AM_V_at): > $@
    330351endif
    331352
  • trunk/yat/omic/Makefile.am

    r3417 r3475  
    11## $Id$
    22
    3 # Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015 Peter Johansson
     3# Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Peter Johansson
    44#
    55# This file is part of the yat library, http://dev.thep.lu.se/yat
     
    2626yat_libyat_la_SOURCES += yat/omic/BamReadIterator.cc
    2727yat_libyat_la_SOURCES += yat/omic/BamWriteIterator.cc
     28yat_libyat_la_SOURCES += yat/omic/Fasta.cc
    2829endif
    2930yat_libyat_la_SOURCES += yat/omic/Codon.cc
    3031yat_libyat_la_SOURCES += yat/omic/DNA.cc
     32yat_libyat_la_SOURCES += yat/omic/DnaComplementer.cc
    3133yat_libyat_la_SOURCES += yat/omic/GenomicPosition.cc
    3234yat_libyat_la_SOURCES += yat/omic/GFF.cc
     
    4749nobase_include_HEADERS += $(srcdir)/yat/omic/Codon.h
    4850nobase_include_HEADERS += $(srcdir)/yat/omic/DNA.h
     51nobase_include_HEADERS += $(srcdir)/yat/omic/DnaComplementer.h
     52nobase_include_HEADERS += $(srcdir)/yat/omic/Fasta.h
    4953nobase_include_HEADERS += $(srcdir)/yat/omic/GenomicPosition.h
    5054nobase_include_HEADERS += $(srcdir)/yat/omic/GFF.h
  • trunk/yat/omic/algorithm.h

    r3295 r3475  
    2323*/
    2424
     25#include <yat/utility/config_public.h>
     26
     27#ifdef YAT_HAVE_HTSLIB
    2528#include "BamPairIterator.h"
     29#endif
     30#include "DnaComplementer.h"
     31
     32#include <boost/iterator/iterator_concepts.hpp>
     33#include <boost/iterator/iterator_traits.hpp>
     34#include <boost/concept_check.hpp>
    2635
    2736namespace theplu {
     
    4857     \since New in yat 0.10
    4958   */
     59#ifdef YAT_HAVE_HTSLIB
     60  template<class Iterator, class Visitor>
     61  void bam_pair_analyse(Iterator first, Iterator last, Visitor& visitor);
     62#endif
     63
     64  /**
     65     Function that transforms a sequence of chars to its genomic
     66     complement (see DnaComplementer). Sequence can be transformed
     67     in-place, i.e., begin and out can point to the same element.
     68
     69     Type Requirements:
     70     - \c InputIterator is \readable_iterator
     71     - \c InputIterator models \single_pass_iterator
     72     - value type of \c InputIterator is convertible to char
     73     - \c OutputIterator models \incrementable_iterator
     74     - \c OutputIterator is a \writable_iterator
     75     - \c char must be convertible to value type of OutputIterator
     76
     77     \since New in yat 0.14
     78   */
     79  template<typename InputIterator, typename OutputIterator>
     80  void dna_complement(InputIterator begin, InputIterator end,
     81                      OutputIterator out);
     82
     83  /**
     84     Function that transforms a sequence of chars to its genomic
     85     reverse complement, i.e., it transforms the sequence using
     86     DnaComplementer and reverse the sequence.
     87
     88     Type Requirements:
     89     - \c BidirectionalIterator is \bidirectional_iterator
     90     - \c BidirectionalIterator is \writable_iterator
     91     - value type of \c BidirectionalIterator is convertible to char
     92     - \c char must be convertible to value type of BidirectionalIterator
     93
     94     \see dna_complement
     95
     96     \since New in yat 0.14
     97  */
     98  template<typename BidirectionalIterator>
     99  void dna_reverse_complement(BidirectionalIterator begin,
     100                              BidirectionalIterator end);
     101
     102  /**
     103     Function that transforms a sequence of chars to its genomic
     104     reverse complement, i.e., it transforms the sequence using
     105     DnaComplementer and reverse the sequence.
     106
     107     Type Requirements:
     108     - \c InputIterator is \readable_iterator
     109     - \c InputIterator models \single_pass_iterator
     110     - value type of \c InputIterator is convertible to char
     111     - \c OutputIterator models \incrementable_iterator
     112     - \c OutputIterator is a \writable_iterator
     113     - \c char must be convertible to value type of OutputIterator
     114
     115     \see dna_complement
     116
     117     \since New in yat 0.14
     118  */
     119  template<typename InputIterator, typename OutputIterator>
     120  void dna_reverse_complement_copy(InputIterator begin, InputIterator end,
     121                                   OutputIterator out);
     122
     123
     124  // template implementations
     125
     126#ifdef YAT_HAVE_HTSLIB
    50127  template<class Iterator, class Visitor>
    51128  void bam_pair_analyse(Iterator first, Iterator last, Visitor& visitor)
     
    56133      visitor((*iter).first(), (*iter).second());
    57134  }
     135#endif
     136
     137
     138  template<typename InputIterator, typename OutputIterator>
     139  void dna_complement(InputIterator begin, InputIterator end,
     140                      OutputIterator out)
     141  {
     142    BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<InputIterator>));
     143    BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<InputIterator>));
     144
     145    BOOST_CONCEPT_ASSERT((
     146      boost::Convertible<typename boost::iterator_value<InputIterator>::type,
     147                         char
     148      >));
     149
     150    using namespace boost_concepts;
     151    BOOST_CONCEPT_ASSERT((WritableIterator<OutputIterator, char>));
     152    BOOST_CONCEPT_ASSERT((IncrementableIterator<OutputIterator>));
     153    std::transform(begin, end, out, DnaComplementer());
     154  }
     155
     156
     157  template<typename BidirectionalIterator>
     158  void dna_reverse_complement(BidirectionalIterator begin,
     159                              BidirectionalIterator end)
     160  {
     161    BOOST_CONCEPT_ASSERT((
     162      boost::Mutable_BidirectionalIterator<BidirectionalIterator>
     163    ));
     164    dna_complement(begin, end, begin);
     165    std::reverse(begin, end);
     166  }
     167
     168
     169  template<typename InputIterator, typename OutputIterator>
     170  void dna_reverse_complement_copy(InputIterator begin, InputIterator end,
     171                                   OutputIterator out)
     172  {
     173    std::vector<char> vec;
     174    dna_complement(begin, end, std::back_inserter(vec));
     175    std::reverse_copy(vec.begin(), vec.end(), out);
     176  }
    58177
    59178}}}
  • trunk/yat/omic/config_bam.h

    r3439 r3475  
    3636#if defined YAT_HAVE_HTSLIB_HTS_H
    3737#  define YAT_SAM_HEADER "htslib/sam.h"
     38#  define YAT_FAIDX_HEADER "htslib/faidx.h"
    3839#elif defined YAT_HAVE_BAM_H
    3940#  define YAT_BAM_HEADER "bam.h"
     41#  define YAT_FAIDX_HEADER "faidx.h"
    4042#  define YAT_SAM_HEADER "sam.h"
    4143#elif defined YAT_HAVE_BAM_BAM_H
    4244#  define YAT_BAM_HEADER "bam/bam.h"
     45#  define YAT_FAIDX_HEADER "bam/faidx.h"
    4346#  define YAT_SAM_HEADER "bam/sam.h"
    4447#elif defined YAT_HAVE_SAMTOOLS_BAM_H
    4548#  define YAT_BAM_HEADER "samtools/bam.h"
     49#  define YAT_FAIDX_HEADER "samtools/faidx.h"
    4650#  define YAT_SAM_HEADER "samtools/sam.h"
    4751#endif
  • trunk/yat/utility/utility.h

    r3417 r3475  
    4747#include <cctype>
    4848#include <cmath>
     49#include <cstdlib>
    4950#include <functional>
    5051#include <limits>
     
    135136  */
    136137  void copy_file(const std::string& source, const std::string& target);
     138
    137139
    138140  /**
Note: See TracChangeset for help on using the changeset viewer.