Beispiel #1
0
def index_repeatmasker_alignment_by_id(fh, out_fh, vebrose=False):
    """Build an index for a repeat-masker alignment file by repeat-masker ID."""
    def extract_UID(rm_alignment):
        return rm_alignment.meta[multipleAlignment.RM_ID_KEY]

    index = IndexedFile(fh, repeat_masker_alignment_iterator, extract_UID)
    index.write_index(out_fh)
Beispiel #2
0
    def test_index_lookup(self, mock_open):
        """Test lookup of specific key using full UI."""
        in_strm = StringIO.StringIO(self.ga_maf1)
        idx_strm = StringIO.StringIO()
        out_strm = StringIO.StringIO()

        # replace open with mock
        def open_side_effect(*args, **kwargs):
            if not isinstance(args[0], basestring):
                raise TypeError()
            if args[0] == "one.maf":
                return in_strm
            elif args[0] == "one.idx":
                return idx_strm
            elif args[0] == "out.txt":
                return out_strm
            raise IOError("No such file")

        mock_open.side_effect = open_side_effect

        # build and index in idx_strm
        bound_iter = functools.partial(genome_alignment_iterator,
                                       reference_species="hg19")
        hash_func = JustInTimeGenomeAlignmentBlock.build_hash
        idx = IndexedFile(StringIO.StringIO(self.ga_maf1), bound_iter,
                          hash_func)
        idx.write_index(idx_strm)
        idx_strm.seek(0)

        key = "chr22" + "\t" + "1772" + "\t" + "1825"
        main(["lookup", "-o", "out.txt", "-k", key, "one.maf", "one.idx"])
        self.assertEqual(
            str(idx[key]).strip(),
            str(out_strm.getvalue()).strip())
Beispiel #3
0
def index_genome_alignment_by_locus(fh, out_fh, verbose=False):
  """Build an index for a genome alig. using coords in ref genome as keys."""
  bound_iter = functools.partial(genome_alignment_iterator,
                                 reference_species="hg19", index_friendly=True)
  hash_func = JustInTimeGenomeAlignmentBlock.build_hash
  idx = IndexedFile(fh, bound_iter, hash_func)
  idx.write_index(out_fh, verbose=verbose)
Beispiel #4
0
def index_repeatmasker_alignment_by_id(fh, out_fh, vebrose=False):
  """Build an index for a repeat-masker alignment file by repeat-masker ID."""
  def extract_UID(rm_alignment):
    return rm_alignment.meta[multipleAlignment.RM_ID_KEY]

  index = IndexedFile(fh, repeat_masker_alignment_iterator, extract_UID)
  index.write_index(out_fh)
Beispiel #5
0
  def test_index_lookup(self, mock_open):
    """Test lookup of specific key using full UI."""
    in_strm = StringIO.StringIO(self.ga_maf1)
    idx_strm = StringIO.StringIO()
    out_strm = StringIO.StringIO()

    # replace open with mock
    def open_side_effect(*args, **kwargs):
      if not isinstance(args[0], basestring):
        raise TypeError()
      if args[0] == "one.maf":
        return in_strm
      elif args[0] == "one.idx":
        return idx_strm
      elif args[0] == "out.txt":
        return out_strm
      raise IOError("No such file")

    mock_open.side_effect = open_side_effect

    # build and index in idx_strm
    bound_iter = functools.partial(genome_alignment_iterator,
                                   reference_species="hg19")
    hash_func = JustInTimeGenomeAlignmentBlock.build_hash
    idx = IndexedFile(StringIO.StringIO(self.ga_maf1), bound_iter, hash_func)
    idx.write_index(idx_strm)
    idx_strm.seek(0)

    key = "chr22" + "\t" + "1772" + "\t" + "1825"
    main(["lookup", "-o", "out.txt", "-k", key, "one.maf", "one.idx"])
    self.assertEqual(str(idx[key]).strip(), str(out_strm.getvalue()).strip())
Beispiel #6
0
def index_genome_alignment_by_locus(fh, out_fh, verbose=False):
    """Build an index for a genome alig. using coords in ref genome as keys."""
    bound_iter = functools.partial(genome_alignment_iterator,
                                   reference_species="hg19",
                                   index_friendly=True)
    hash_func = JustInTimeGenomeAlignmentBlock.build_hash
    idx = IndexedFile(fh, bound_iter, hash_func)
    idx.write_index(out_fh, verbose=verbose)
Beispiel #7
0
def _build_index(in_strng, ref_spec):
  idx_strm = StringIO.StringIO()
  bound_iter = functools.partial(genome_alignment_iterator,
                                 reference_species=ref_spec)
  hash_func = JustInTimeGenomeAlignmentBlock.build_hash
  idx = IndexedFile(StringIO.StringIO(in_strng), bound_iter, hash_func)
  idx.write_index(idx_strm)
  idx_strm.seek(0)  # seek to the start
  return idx_strm
Beispiel #8
0
def _build_index(in_strng, ref_spec):
    idx_strm = StringIO.StringIO()
    bound_iter = functools.partial(genome_alignment_iterator,
                                   reference_species=ref_spec)
    hash_func = JustInTimeGenomeAlignmentBlock.build_hash
    idx = IndexedFile(StringIO.StringIO(in_strng), bound_iter, hash_func)
    idx.write_index(idx_strm)
    idx_strm.seek(0)  # seek to the start
    return idx_strm
Beispiel #9
0
def _build_index(maf_strm, ref_spec):
    """Build an index for a MAF genome alig file and return StringIO of it."""
    idx_strm = StringIO.StringIO()
    bound_iter = functools.partial(genome_alignment_iterator,
                                   reference_species=ref_spec)
    hash_func = JustInTimeGenomeAlignmentBlock.build_hash
    idx = IndexedFile(maf_strm, bound_iter, hash_func)
    idx.write_index(idx_strm)
    idx_strm.seek(0)  # seek to the start
    return idx_strm
Beispiel #10
0
def _build_index(maf_strm, ref_spec):
  """Build an index for a MAF genome alig file and return StringIO of it."""
  idx_strm = StringIO.StringIO()
  bound_iter = functools.partial(genome_alignment_iterator,
                                 reference_species=ref_spec)
  hash_func = JustInTimeGenomeAlignmentBlock.build_hash
  idx = IndexedFile(maf_strm, bound_iter, hash_func)
  idx.write_index(idx_strm)
  idx_strm.seek(0)  # seek to the start
  return idx_strm