Some R problems that maybe worth reporting
------------------------------------------

- Loading a serialized XStringViews object without prior loading the Biostrings
  package seems to have problems: the object loads, but, when I try to display
  it, then nothing is printed and the prompt doesn't come back either (unless I
  CTRL C).

- rowSums() and colSums() should return integer vectors when applied on
  an integer matrix.


Immediate TODO list
-------------------

BASIC CONTAINERS

- Fix the MIndex container. It must support storage of hits for patterns of
  variable width. Make sure to make startIndex() work properly on the MIndex
  object returned by a call to matchPDict() on a PDict object with a head or
  a tail (it's currently broken). It should also support storage of the nb of
  mismatches for each hit. No need to store the locations of those mismatches
  though: this would require a huge amount of memory and there are other ways
  to retrieve these locations on user demand so maybe it's not worth it.

- Add "baseXStringSubtype" methods for XStringViews, XStringSet and
  MaskedXString objects and replace use of "baseClass" by use of
  "baseXStringSubtype".

- XStringSet objects:
    o Modify the internals of the XStringSet containers to support efficient
      replacement of elements (without reallocation and data copy). See long
      comment at the beginning of R/XStringSet-class.R for the details.
    o Support this: DNAStringSet(x, start=c(1,5), end=c(3,7)) when x is a
      single string (character or XString). The result should be a DNAStringSet
      object of the length of 'start' (or 'end').
    o Fix validObject() for XStringSet objects (currently broken).
    o DNAStringSet(x) should not do anything when x is already a DNAStringSet
      _instance_ (class(x) == "DNAStringSet").
    o Add methods for XStringSet objects everywhere there are methods defined
      for XStringViews objects (matchPattern, countPattern, etc...).
      Make them work in a vectorized fashion for XStringSet objects.
    o Add "==" method for XStringSet objects.
    o Try to speed up "show" method for XStringSet objects.

- Define a DNAorRNA class (or NucleotideString) that is the union of the
  DNAString and RNAString classes (use a union class for this or "do it by
  hand" by defining this as a virtual class and by having the DNAString
  and RNAString classes derived from it). Then use it to simplify code like:
    setMethod("alphabetFrequency", "DNAString", ...)
    setMethod("alphabetFrequency", "RNAString", ...)
  These 2 methods can be replaced by a single method:
    setMethod("alphabetFrequency", "NucleotideString", ...)
  Also this:
    if (is(x@subject, "DNAString") || is(x@subject, "RNAString")) ...
  can be replaced by:
    if (is(x@subject, "NucleotideString")) ...
  Etc...

C-LEVEL FACILITIES

- Code cleaning: use _get_XString_asRoSeq() in every C routine that receives
  an XString argument. This reduces the number of args that need to be passed
  and makes the code much cleaner. See XString_match_pattern() for an example.

UTILITIES

- Deprecate adjacentViews() in favor of successiveViews() from the IRanges
  package. Use successiveIRanges()/successiveViews() internally instead of
  deprecated intToAdjacentRanges()/adjacentViews().

- Move lcprefix()/lcsuffix() out of pmatchPattern.R to a file of their own.
  (This stuff needs to belong to the UTILITIES component of the package, not
  to the STRING ALIGNMENT component.)

- Clean the mess in R/XStringViews-constructors.R. This file should go away
  or be renamed something like R/XStringViews-old.R

- Add "order", "sort", "duplicated", "unique" and "patternFrequency" methods
  for XStringSet and XStringViews objects. Also, for completeness, the "<=",
  ">=", "<" and ">" operators between XString objects should be provided.
  Note that Martin's srsort() from the ShortRead package is much faster
  than sortDNAString() from the old Biostrings 1 package:

    library(drosophila2probe)
    dict0 <- DNAString(drosophila2probe$sequence[1:100000])

  On george1:

    sortDNAString(dict0) # 1.053 sec. (R-2.7.1 + Biostrings 1.4.0)

    srsort(dict0) # 0.097 sec. (R-2.8 + Biostrings 2.9 + ShortRead 0.1)

  srsort() uses standard C qsort() internally.
  It might be possible to be even faster by building a prefix tree (like
  for the Aho-Corasick algo) but that will probably be at the cost of
  using much more memory. Also it might be relatively easy do reuse the
  current Aho-Corasick code for a DNAStringSet object but it will require
  much more work to do this for a BStringSet or AAStringSet object.

- Add an xsmatch() function that would behave like standard base::match()
  but on XString objects (2nd arg 'table' must be an XStringSet object).
  When 'x' is a single string, 'xsmatch(x, table)' would return:

    ii <- nchar(x) == width(table) &
          isMatching(x, Biostrings:::super(table), start(table))
    which(ii)[1]

  although this is not optimal because isMatching() is doing too many
  comparisons when it could in fact bail out early.

- Add functions for translating DNA or RNA into AA.

- Use subseq() instead of subXString(). Remove subXString.R file.

- Finish C implementation of read.XStringViews()

- Maybe make strrev() a "reverse" method for character objects.

- Add a new generic that combines a subject and an IRanges (or IRanges-like)
  object to return an XStringViews object. The IRanges-like object could be
  MIndex object and the method for it would do as if it had received
  unlist(MIndex). Currently my problem is that I can't come up with a good
  name for such generic :-/ Maybe I could just use views(subject, x) for
  this (dispatch would be on x, not subject). And the current views function
  could be renamed (or maybe it's not needed at all, maybe a fancy
  new("IRanges", ...) could replace it).

STRING MATCHING

- Move consensusMatrix()/consensusString() from align-utils.R to match-utils.R
  (This stuff needs to belong to the STRING MATCHING component of the package,
  not to the STRING ALIGNMENT component.)

- Add a Biostrings.Rnw vignette with a short overview of the string
  matching/aligning capabilities and a "how to choose the right string
  matching/aligning function" diagram.

- Add a no.match.length argument to gregexpr2() that is FALSE by
  default so gregexpr(pattern, text, fixed=TRUE) is more interchangeable
  with gregexpr2(pattern, text) and use no.match.length=TRUE in matchPattern's
  internal code.

- When algo="auto", use "naive_inexact" instead of "shift-or" when max.mismatch
  is high (e.g. >= 8, finding the exact cut-value requires some testing).
  Correct Robert's RBioinf book reporting that the performance decrease
  significantly when max.mismatch becomes to large. Should not be the case
  anymore.

- Add some convenience function (e.g. a wrapper to .valid.algos()) to let the
  curious user know which algos are available/used for a given search problem.

- Rework findPalindromes() (and findComplementedPalindromes()) so that they
  return maximum palindromes only.

- PDict()/matchPDict()/countPDict()/whichPDict():

  o Document the "allow mismacthes anywhere in the patterns" feature (activated
    via the 'max.mismatch' argument of PDict()).

  o Support IUPAC ambiguity letters in the DNAStringSet object passed to
    PDict().

  o Harris suggestion: treat a max.mismatch value that is strictly between 0
    and 1 like an error rate (so that the actual max number of mismatches
    adjust to the length of each pattern).

  o Patrick's suggestion: give the user the option to make matchPDict() return
    directly the coverage of the hits (apparently a common use case). That
    would avoid the overhead of storing the hits in the (generally big) MIndex
    object first.
    Maybe put this in a separate function e.g. coveragePDict().

  o _match_ACtree() doesn't need to walk until the end of the subject: it could
    stop when the number of remaining chars to read is < to the difference
    between the depth of the AC tree (i.e. the width of the Trusted Band) and
    the current depth. This should speed up matchPDict()/countPDict()/whichPDict()
    substantially when the length of the subject is very small. A typical use
    case where this could be of great benefit is when finding the neighbors of a
    given pattern with e.g. whichPDict(pdict, pdict[[99]], max.mismatch=2).

  o Implement the skip.invalid.patterns arg in PDict() (so the user can build
    a PDict object from Solexa data that would contain Ns if he wants, reads
    with an N would just be skipped).

  o Implement "duplicated" and "patternFrequency" methods for PDict objects
    with a head or a tail. Add 'freq' arg (default FALSE) to patternFrequency()
    like for alphabetFrequency().

  o extractAllMatches() fails on a very big MIndex object (can't allocate
    vector of size 5.2Gb).

  o C code improvement: no need to use temporary storage for 'dups_buf' and
    'match_count' in match_pdict.c, store directly in the returned
    INTEGER vector.

  o MIndex objects: at some point the user will want to be able to combine
    "compatible" MIndex objects. 2 MIndex objects are "compatible" if they
    are describing 2 set of matches coming from the same original dict and on
    the same target (subject). In practice, it will be enough that they have
    the same index i.e. they have the same pids() or, if the pids() is NULL,
    they have the same length.
    Then methods like "union", "rangesect", "setdiff", "setequal", etc...
    could be defined. The set operation would be performed between the 2
    subsets of matches of each input pattern. Of course, 2 matches are
    considered equal if their start/end are the same.

  o Make reverseComplement() work on a PDict object.

  o Compare with other software for fast alignment and assembly:
      Vmatch (http://www.vmatch.de/)
      Maq (http://maq.sourceforge.net/)
      MUMmer (http://mummer.sourceforge.net/)

STRING ALIGNMENT

MISCELLANEOUS

- Port DNASuffixArray() and related functions from Biostrings 1.

- Robert wants the dependencies to be reduced to 1 BSgenome pkg only (not 2),
  or, even better, to 0 BSgenome pkg. The examples would then use a single
  sequence stored in the data folder.

- Remove the Biostrings 1 subdir. But first compare NAMESPACE + list of aliases
  in Rd files from Biostrings 1 and 2 make sure no important feature has been
  lost.

- Update the CHANGES file.


Long term TODO list
-------------------

- Look at apse.c in R/src/main for Levenshtein. It's coming from
    http://search.cpan.org/dist/String-Approx/
  and is what Perl and Python are using.
  It should stop and return an error code after some max.distance has been
  reached. We definitely want to be able to do this if we're going to use it
  on the millions of elements of the head and tail of a TB_PDict object.

- Change signature of matchPattern() (and of friends too, maybe): add a
  'min.mismatch' arg.

- Have the "XStringViews" method for XString objects support the 'collapse' arg.

- Maybe: add a specific containers for results returned by matchPattern
  (and family). Would derive from the XStringViews class with at least one
  additional slot, the @call slot (of type "language"), that would contain
  the value of match.call(), so that one knows what parameters were supplied
  for a given matching task.

- readFASTA(): remove warning when strip.descs is missing.

- Merge ~rgentlem/tmp/EMBOSS-3.0.0/emboss/matcher.c (Huang & Miller
  alignment algo) into Biostrings.

- An old Robert request: "have a look at GeneR, and see if there are
  any other packages that do sequence matching, and describe, in one page or
  so, what the differences are between the packages (also some notion of speed
  and size, how well do they work on different inputs)".

- Extend pairwiseAlignment to return the set of maximum alignments, rather
  than just one element from that set.

- Why doesn't sapply or lapply work for an XStringViews object (it didn't
  work either for BioString objects). Isn't it enough that these objects
  are subsettable?

- Restore the test units.

- Fix pb with length(x) <- 2 screwing up x if it's an XString or XStringViews
  object (prevent people of doing this by defining the replacement version
  of the length method and issuing an error).

- Still have to think about it (Robert suggestion): make [[ work on "out
  of limits" views with a warning (we keep issuing an error only when the
  view is all blank).

- Start adding suffix tree capabilities: maybe merge SuffixTree package from
  Robert?

