コード例 #1
0
ファイル: index.py プロジェクト: pjuren/pyokit
    def test_index_genome_alig(self, mock_open):
        """Do a full round trip test for a simple whole-genome alignment."""
        in_strm = StringIO.StringIO(self.ga_maf1)
        idx_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
            raise IOError("No such file")

        mock_open.side_effect = open_side_effect
        main(["build", "-o", "one.idx", "one.maf"])
        idx_strm.seek(0)
        in_strm.seek(0)
        ga = build_genome_alignment_from_file("one.maf", "hg19", "one.idx")
        b1_res = ga.get_blocks("chr22", 1711, 1720)[0]
        b2_res = ga.get_blocks("chr22", 1770, 1780)[0]
        self.assertEqual(b1_res["hg19.chr22"], self.b1_hg19)
        self.assertEqual(b2_res["hg19.chr22"], self.b2_hg19)
コード例 #2
0
ファイル: index.py プロジェクト: pjuren/pyokit
  def test_index_genome_alig(self, mock_open):
    """Do a full round trip test for a simple whole-genome alignment."""
    in_strm = StringIO.StringIO(self.ga_maf1)
    idx_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
      raise IOError("No such file")

    mock_open.side_effect = open_side_effect
    main(["build", "-o", "one.idx", "one.maf"])
    idx_strm.seek(0)
    in_strm.seek(0)
    ga = build_genome_alignment_from_file("one.maf", "hg19", "one.idx")
    b1_res = ga.get_blocks("chr22", 1711, 1720)[0]
    b2_res = ga.get_blocks("chr22", 1770, 1780)[0]
    self.assertEqual(b1_res["hg19.chr22"], self.b1_hg19)
    self.assertEqual(b2_res["hg19.chr22"], self.b2_hg19)
コード例 #3
0
ファイル: conservationProfile.py プロジェクト: pjuren/pyokit
def main(args, prog_name):
  """Process the command line arguments of this script and dispatch."""
  # get options and arguments
  ui = getUI(prog_name, args)

  if ui.optionIsSet("test"):
    # just run unit tests
    unittest.main(argv=[sys.argv[0]])
  elif ui.optionIsSet("help"):
    # just show help
    ui.usage()
  else:
    verbose = (ui.optionIsSet("verbose") is True) or DEFAULT_VERBOSITY

    # get output handle
    out_fh = sys.stdout
    if ui.optionIsSet("output"):
      out_fh = open(ui.getValue("output"), "w")

    # get window size...
    window_size = DEFAULT_WINDOW_SIZE
    if ui.optionIsSet("window"):
      window_size = ui.getValue("window")

    # get the window anchoring location
    windowCentre = DEFAULT_WINDOW_CENTRE
    if ui.optionIsSet("centre"):
      windowCentre = ui.getValue("centre")
      if windowCentre not in WINDOW_CENTRE_OPTIONS:
        sys.stderr.write("un-recognised window anchor position: " +
                         str(windowCentre) + "\n")
        sys.exit(1)

    args = ui.getAllArguments()
    assert(len(args) == 3 or len(args) == 4)
    region_fn = ui.getArgument(0)
    ga_path = ui.getArgument(1)
    index_fn = None
    if len(args) == 3:
      spec = ui.getArgument(2)
    else:
      index_fn = ui.getArgument(2)
      spec = ui.getArgument(3)

    extensions = (ui.getValue("extensions").strip().split(",") if
                  ui.optionIsSet("extensions") else None)
    index_extensions = (ui.getValue("index-extensions").strip().split(",") if
                        ui.optionIsSet("index-extensions") else None)
    fail_no_index = ui.optionIsSet("fail-no-index")
    mi_seqs = (MissingSequenceHandler[ui.getValue("missing")]
               if ui.optionIsSet("missing")
               else MissingSequenceHandler.TREAT_AS_ALL_GAPS)
    species = ([x.strip() for x in ui.getValue("species").split(",")] if
               ui.optionIsSet("species") else None)

    # build the genome alignment
    alig = (load_just_in_time_genome_alignment(ga_path, spec, extensions,
                                               index_extensions, fail_no_index,
                                               verbose)
            if os.path.isdir(ga_path)
            else build_genome_alignment_from_file(ga_path, spec, index_fn,
                                                  verbose))

    # get the profile and write it to the output stream
    profile = processBED(open(region_fn), alig, window_size, CENTRE,
                         mi_seqs, species, verbose)
    out_fh.write("\n\n" + ", ".join(str(x) for x in profile) + "\n")
コード例 #4
0
def main(args, prog_name):
    """Process the command line arguments of this script and dispatch."""
    # get options and arguments
    ui = getUI(prog_name, args)

    if ui.optionIsSet("test"):
        # just run unit tests
        unittest.main(argv=[sys.argv[0]])
    elif ui.optionIsSet("help"):
        # just show help
        ui.usage()
    else:
        verbose = (ui.optionIsSet("verbose") is True) or DEFAULT_VERBOSITY

        # get output handle
        out_fh = sys.stdout
        if ui.optionIsSet("output"):
            out_fh = open(ui.getValue("output"), "w")

        # get window size...
        window_size = DEFAULT_WINDOW_SIZE
        if ui.optionIsSet("window"):
            window_size = ui.getValue("window")

        # get the window anchoring location
        windowCentre = DEFAULT_WINDOW_CENTRE
        if ui.optionIsSet("centre"):
            windowCentre = ui.getValue("centre")
            if windowCentre not in WINDOW_CENTRE_OPTIONS:
                sys.stderr.write("un-recognised window anchor position: " +
                                 str(windowCentre) + "\n")
                sys.exit(1)

        args = ui.getAllArguments()
        assert (len(args) == 3 or len(args) == 4)
        region_fn = ui.getArgument(0)
        ga_path = ui.getArgument(1)
        index_fn = None
        if len(args) == 3:
            spec = ui.getArgument(2)
        else:
            index_fn = ui.getArgument(2)
            spec = ui.getArgument(3)

        extensions = (ui.getValue("extensions").strip().split(",")
                      if ui.optionIsSet("extensions") else None)
        index_extensions = (ui.getValue("index-extensions").strip().split(",")
                            if ui.optionIsSet("index-extensions") else None)
        fail_no_index = ui.optionIsSet("fail-no-index")
        mi_seqs = (MissingSequenceHandler[ui.getValue("missing")]
                   if ui.optionIsSet("missing") else
                   MissingSequenceHandler.TREAT_AS_ALL_GAPS)
        species = ([x.strip() for x in ui.getValue("species").split(",")]
                   if ui.optionIsSet("species") else None)

        # build the genome alignment
        alig = (load_just_in_time_genome_alignment(
            ga_path, spec, extensions, index_extensions, fail_no_index,
            verbose) if
                os.path.isdir(ga_path) else build_genome_alignment_from_file(
                    ga_path, spec, index_fn, verbose))

        # get the profile and write it to the output stream
        profile = processBED(open(region_fn), alig, window_size, CENTRE,
                             mi_seqs, species, verbose)
        out_fh.write("\n\n" + ", ".join(str(x) for x in profile) + "\n")