Exemplo n.º 1
0
def run(args, verbose=False):
    from libtbx.utils import Sorry
    import os
    from spotfinder.command_line.signal_strength import master_params
    from spotfinder.servers import LoggingFramework

    # For the Apache server version, do not allow site, user, or dataset preferences
    # all parameters are to be passed in through the http: query line

    logfile = LoggingFramework()

    phil_objects = []
    argument_interpreter = master_params.command_line_argument_interpreter(home_scope="distl")

    for key in args.keys():
        arg = "%s=%s" % (key, args.get(key, ""))
        try:
            command_line_params = argument_interpreter.process(arg=arg)
        except Exception:
            return str(Sorry("Unknown file or keyword: %s" % arg))
        else:
            phil_objects.append(command_line_params)

    working_params = master_params.fetch(sources=phil_objects)
    params = working_params.extract()
    # working_params.show()

    if not os.path.isfile(params.distl.image):
        return str(Sorry("%s is not a readable file" % params.distl.image))

    print "Image: %s" % params.distl.image

    from spotfinder.applications import signal_strength

    try:
        signal_strength.run_signal_strength(params)
    except Exception:
        import traceback

        logger = StringIO.StringIO()
        logger.write("Sorry, can't process %s.  Please contact authors.\n" % params.distl.image)
        traceback.print_exc(file=logger)
        return str(Sorry(logger.getvalue()))

    return logfile.getvalue()
Exemplo n.º 2
0
def run(args, verbose=False):
    from libtbx.utils import Sorry
    import os
    from spotfinder.command_line.signal_strength import master_params
    from spotfinder.servers import LoggingFramework

    #For the Apache server version, do not allow site, user, or dataset preferences
    #all parameters are to be passed in through the http: query line

    logfile = LoggingFramework()

    phil_objects = []
    argument_interpreter = master_params.command_line_argument_interpreter(
        home_scope="distl")

    for key in args.keys():
        arg = "%s=%s" % (key, args.get(key, ""))
        try:
            command_line_params = argument_interpreter.process(arg=arg)
        except Exception:
            return str(Sorry("Unknown file or keyword: %s" % arg))
        else:
            phil_objects.append(command_line_params)

    working_params = master_params.fetch(sources=phil_objects)
    params = working_params.extract()
    #working_params.show()

    if not os.path.isfile(params.distl.image):
        return str(Sorry("%s is not a readable file" % params.distl.image))

    print "Image: %s" % params.distl.image

    from spotfinder.applications import signal_strength
    try:
        signal_strength.run_signal_strength(params)
    except Exception:
        import traceback
        logger = StringIO()
        logger.write("Sorry, can't process %s.  Please contact authors.\n" %
                     params.distl.image)
        traceback.print_exc(file=logger)
        return str(Sorry(logger.getvalue()))

    return logfile.getvalue()
Exemplo n.º 3
0
    def do_GET_run(self,
                   qs):  #similar to the run() function in apache.py module
        from libtbx.utils import Sorry
        import os
        from spotfinder.servers import LoggingFramework

        base_params = copy.deepcopy(common_parameters_singleton)
        argument_interpreter = base_params.command_line_argument_interpreter()
        phil_objects = []

        for key in qs.keys():
            arg = "%s=%s" % (key, qs.get(key, "")[0])
            try:
                command_line_params = argument_interpreter.process(arg=arg)
            except Exception:
                return str(Sorry("Unknown file or keyword: %s" % arg))
            else:
                phil_objects.append(command_line_params)

        working_params = base_params.fetch(sources=phil_objects)
        params = working_params.extract()
        #working_params.show()
        if not os.path.isfile(params.distl.image):
            return str(Sorry("%s is not a readable file" % params.distl.image))

        print "Image: %s" % params.distl.image

        logfile = LoggingFramework()
        from spotfinder.applications import signal_strength
        try:
            signal_strength.run_signal_strength(params)
        except Exception:
            import traceback
            logger = StringIO()
            logger.write(
                "Sorry, can't process %s.  Please contact authors.\n" %
                params.distl.image)
            traceback.print_exc(file=logger)
            return str(Sorry(logger.getvalue()))

        return logfile.getvalue()
  def do_GET_run(self,qs): #similar to the run() function in apache.py module
    from libtbx.utils import Sorry
    import os
    from spotfinder.servers import LoggingFramework

    base_params = copy.deepcopy(common_parameters_singleton)
    argument_interpreter = base_params.command_line_argument_interpreter()
    phil_objects = []

    for key in qs.keys():
      arg = "%s=%s"%(key,qs.get(key,"")[0])
      try: command_line_params = argument_interpreter.process(arg=arg)
      except Exception: return str(Sorry("Unknown file or keyword: %s" % arg))
      else: phil_objects.append(command_line_params)

    working_params = base_params.fetch(sources=phil_objects)
    params = working_params.extract()
    #working_params.show()
    if not os.path.isfile(params.distl.image):
      return  str(Sorry("%s is not a readable file" % params.distl.image))

    print "Image: %s"%params.distl.image

    logfile = LoggingFramework()
    from spotfinder.applications import signal_strength
    try:
      signal_strength.run_signal_strength(params)
    except Exception:
      import traceback
      logger = StringIO.StringIO()
      logger.write(
      "Sorry, can't process %s.  Please contact authors.\n"% params.distl.image)
      traceback.print_exc(file=logger)
      return str(Sorry( logger.getvalue() ))

    return logfile.getvalue()
Exemplo n.º 5
0
  def run_distl(self, params):
    """ Performs a quick DISTL spotfinding and returns Bragg spots information.
    """
    from spotfinder.applications import signal_strength

    # run DISTL spotfinder
    with misc.Capturing() as distl_output:
      Org = signal_strength.run_signal_strength(params)

    # Extract relevant spotfinding info
    for frame in Org.S.images.keys():
      saturation = Org.Files.imageindex(frame).saturation
      Bragg_spots = [flex.sum(spot.wts) for spot in Org.S.images[frame]['inlier_spots']]

    return Bragg_spots
Exemplo n.º 6
0
    def run_distl(self, params):
        """ Performs a quick DISTL spotfinding and returns Bragg spots information.
    """
        from spotfinder.applications import signal_strength

        # run DISTL spotfinder
        with misc.Capturing() as distl_output:
            Org = signal_strength.run_signal_strength(params)

        # Extract relevant spotfinding info
        for frame in Org.S.images.keys():
            saturation = Org.Files.imageindex(frame).saturation
            Bragg_spots = [
                flex.sum(spot.wts)
                for spot in Org.S.images[frame]['inlier_spots']
            ]

        return Bragg_spots
Exemplo n.º 7
0
def run_one(path, *command_line, **kwargs):
  args = ["distl.image=%s"%path,
          "distl.res.outer=2.1",
          "distl.detector_format_version=CXI 5.1",
          ]

  horizons_phil = cxi_phil.cxi_versioned_extract(
                    copy.deepcopy(args),list(command_line))

  global parameters
  parameters.horizons_phil = horizons_phil

  from spotfinder.applications import signal_strength
  info = signal_strength.run_signal_strength(horizons_phil)

  if kwargs.get("display",False):

    work = wrapper_of_callback(info)
    work.display_with_callback(path)
Exemplo n.º 8
0
def run_one(path, *command_line, **kwargs):
  args = ["distl.image=%s"%path,
          "distl.res.outer=2.1",
          "distl.detector_format_version=CXI 5.1",
          ]

  horizons_phil = cxi_phil.cxi_versioned_extract(
                    copy.deepcopy(args),list(command_line))

  global parameters
  parameters.horizons_phil = horizons_phil

  from spotfinder.applications import signal_strength
  info = signal_strength.run_signal_strength(horizons_phil)

  if kwargs.get("display",False):

    work = wrapper_of_callback(info)
    work.display_with_callback(path)
    def run_distl(self, params):
        """ Performs a quick DISTL spotfinding and returns Bragg spots information.
    """
        from spotfinder.applications import signal_strength
        # run DISTL spotfinder
        try:
            with util.Capturing() as distl_output:
                Org = signal_strength.run_signal_strength(params)
        except NotImplementedError as e:
            print("NOT IMPLEMENTED ERROR FOR {}".format(self.img))

        # Extract relevant spotfinding info
        for frame in Org.S.images.keys():
            saturation = Org.Files.imageindex(frame).saturation
            Bragg_spots = [
                flex.sum(spot.wts)
                for spot in Org.S.images[frame]['inlier_spots']
            ]

        return Bragg_spots
Exemplo n.º 10
0
def run(args, verbose=False):
    from libtbx.utils import Sorry
    import os
    from spotfinder.command_line.signal_strength import master_params

    #For the Apache server version, do not allow site, user, or dataset preferences
    #all parameters are to be passed in through the http: query line

    phil_objects = []
    argument_interpreter = master_params.command_line_argument_interpreter(
        home_scope="distl")

    from spotfinder.servers.apache_utils import LongLineSimpleNode as SimpleNode
    from spotfinder.applications import signal_strength

    logger = StringIO()
    top = SimpleNode("spotfinder")

    try:
        for key in args.keys():
            arg = "%s=%s" % (key, args.get(key, ""))
            command_line_params = argument_interpreter.process(arg=arg)
            phil_objects.append(command_line_params)

        working_params = master_params.fetch(sources=phil_objects)
        params = working_params.extract()

        top.child(SimpleNode(tag="file_name", contents=params.distl.image))

        if not os.path.isfile(params.distl.image):
            raise Sorry("%s not a readable file" % params.distl.image)

        Org = signal_strength.run_signal_strength(params)
        assert len(list(Org.S.images.keys())) == 1  # there is only one image
        key = list(Org.S.images.keys())[0]

        # List of spots between specified high- and low-resolution limits
        if Org.S.images[key].has_extended_key('lo_pass_resolution_spots'):
            spots = Org.S.images[key]['lo_pass_resolution_spots']
        elif Org.S.images[key].has_extended_key('inlier_spots'):
            spots = Org.S.images[key]['inlier_spots']
        else:
            spots = []

        if Org.S.images[key].has_extended_key('N_spots_total'):
            total = "%d" % Org.S.images[key]["N_spots_total"]
        else:
            total = "0"

        if Org.S.images[key].has_extended_key('resolution'):
            resolution = Org.S.images[key]['resolution']
        elif Org.S.images[key].has_extended_key('distl_resolution'):
            resolution = Org.S.images[key]['distl_resolution']
        else:
            resolution = 0.0

        top.child(SimpleNode(tag="total_spots", contents=total))
        top.child(SimpleNode(tag="good_spots", contents="%d" % len(spots)))
        top.child(SimpleNode(tag="resolution", contents="%.3f" % resolution))

        if len(Org.S.reporters[key]) == 0:
            top.child(SimpleNode(tag="total_integrated", contents="0"))
            top.child(SimpleNode(tag="mean_isigi", contents="0"))
        else:
            reporter = Org.S.reporters[key][-1]
            normalizer = reporter.weights.sum()
            summation = 0
            for x in range(reporter.S_table_rows):
                summation += reporter.weights[x] * reporter.MeanIsigI[x]
            top.child(
                SimpleNode(tag="mean_isigi",
                           contents="%.3f" % (summation / normalizer)))
            integrated = reporter.Integrated.sum()
            top.child(
                SimpleNode(tag="integrated", contents="%.3f" % integrated))

    except Exception as e:
        top.child(SimpleNode(tag="status", contents=repr(e)))
        top.emit(logger)
        return logger.getvalue()

    top.child(SimpleNode(tag="status", contents="OK"))
    top.emit(logger)

    return logger.getvalue()
Exemplo n.º 11
0
def run(args, command_name="distl.signal_strength"):
    help_str = """explanation:
Local background and background standard deviation are determined.
Pixels are classified as signal if > minimum_signal_height sigmas above background.
Signals are chosen as spot maxima if > minimum_spot_height sigmas above background.
Spots are grown around the maxima, and retained if they fit minimal area criteria.
Total number of candidates at this stage is reported as "Spot Total"
Ice rings are eliminated by at least two different algorithms (rings of high pixel
  values and rings of high spot count).
Resolution filters are applied if given on the command line.
Total number of candidates at this stage is reported as "In-Resolution Total"
Other spot-quality filters are applied to give the number of "Good Bragg Candidates".
Method 1 Resolution is a published legacy algorithm (Zhang et al, 2006) no longer used.
Method 2 Resolution reflects drop off of spot count as a function of resolution shell,
  but is overridden by command line input of distl.res.outer
Signal strength of the Good Bragg Candidates is then presented as integrated area of
  the spot above local background, expressed in pixel-analog/digital units.
Very verbose output is available by setting distl.verbose=True
Full documentation: http://cci.lbl.gov/publications/download/ccn_jul2010_page18.pdf
"""

    if (len(args) == 0
            or args[0] in ["H", "h", "-H", "-h", "help", "--help", "-help"]):
        print "usage:   %s image_filename [parameter=value ...]" % command_name
        print "example: %s lysozyme_001.img distl.res.outer=2.0 distl.res.inner=6.0 distl.minimum_spot_area=8" % command_name
        master_params.show(attributes_level=1, expert_level=1)
        print help_str
        return

    print "%s: characterization of candidate Bragg spots" % command_name

    phil_objects = []
    argument_interpreter = master_params.command_line_argument_interpreter(
        home_scope="distl")
    image_file_name = None
    moving_pdb_file_name = None
    for arg in args:
        if (os.path.isfile(arg)):
            if (image_file_name is None): image_file_name = arg
            else: raise Sorry("Too many file names.")
        else:
            try:
                command_line_params = argument_interpreter.process(arg=arg)
            except KeyboardInterrupt:
                raise
            except Exception:
                raise Sorry("Unknown file or keyword: %s" % arg)
            else:
                phil_objects.append(command_line_params)

    working_params = master_params.fetch(sources=phil_objects)
    params = working_params.extract()

    def raise_missing(what):
        raise Sorry("""\
Missing file name for %(what)s structure:
  Please add
    %(what)s=file_name
  to the command line to specify the %(what)s structure.""" % vars())

    if (image_file_name is None):
        if (params.distl.image is None): raise_missing("file name")
    else:
        params.distl.image = image_file_name

    print "#Parameters used:"
    print "#phil __ON__"
    print
    working_params = master_params.format(python_object=params)
    working_params.show(expert_level=1)
    print
    print "#phil __OFF__"
    print

    #Now actually run the program logic
    from spotfinder.applications import signal_strength
    return signal_strength.run_signal_strength(working_params.extract())
Exemplo n.º 12
0
def run(args, command_name="distl.signal_strength"):
  help_str="""explanation:
Local background and background standard deviation are determined.
Pixels are classified as signal if > minimum_signal_height sigmas above background.
Signals are chosen as spot maxima if > minimum_spot_height sigmas above background.
Spots are grown around the maxima, and retained if they fit minimal area criteria.
Total number of candidates at this stage is reported as "Spot Total"
Ice rings are eliminated by at least two different algorithms (rings of high pixel
  values and rings of high spot count).
Resolution filters are applied if given on the command line.
Total number of candidates at this stage is reported as "In-Resolution Total"
Other spot-quality filters are applied to give the number of "Good Bragg Candidates".
Method 1 Resolution is a published legacy algorithm (Zhang et al, 2006) no longer used.
Method 2 Resolution reflects drop off of spot count as a function of resolution shell,
  but is overridden by command line input of distl.res.outer
Signal strength of the Good Bragg Candidates is then presented as integrated area of
  the spot above local background, expressed in pixel-analog/digital units.
Very verbose output is available by setting distl.verbose=True
Full documentation: http://cci.lbl.gov/publications/download/ccn_jul2010_page18.pdf
"""

  if (len(args) == 0 or args[0] in ["H","h","-H","-h","help","--help","-help"]):
    print "usage:   %s image_filename [parameter=value ...]" % command_name
    print "example: %s lysozyme_001.img distl.res.outer=2.0 distl.res.inner=6.0 distl.minimum_spot_area=8"%command_name
    master_params.show(attributes_level=1,expert_level=1)
    print help_str
    return

  print "%s: characterization of candidate Bragg spots"%command_name

  phil_objects = []
  argument_interpreter = master_params.command_line_argument_interpreter(
    home_scope="distl")
  image_file_name = None
  moving_pdb_file_name = None
  for arg in args:
    if (os.path.isfile(arg)):
      if (image_file_name is None): image_file_name = arg
      else: raise Sorry("Too many file names.")
    else:
      try: command_line_params = argument_interpreter.process(arg=arg)
      except KeyboardInterrupt: raise
      except Exception: raise Sorry("Unknown file or keyword: %s" % arg)
      else: phil_objects.append(command_line_params)

  working_params = master_params.fetch(sources=phil_objects)
  params = working_params.extract()

  def raise_missing(what):
      raise Sorry("""\
Missing file name for %(what)s structure:
  Please add
    %(what)s=file_name
  to the command line to specify the %(what)s structure.""" % vars())

  if (image_file_name is None):
    if (params.distl.image is None): raise_missing("file name")
  else:
    params.distl.image = image_file_name

  print "#Parameters used:"
  print "#phil __ON__"
  print
  working_params = master_params.format(python_object=params)
  working_params.show(expert_level=1)
  print
  print "#phil __OFF__"
  print

  #Now actually run the program logic
  from spotfinder.applications import signal_strength
  return signal_strength.run_signal_strength(working_params.extract())
Exemplo n.º 13
0
def run(args, verbose=False):
  from libtbx.utils import Sorry
  import os
  from spotfinder.command_line.signal_strength import master_params

  #For the Apache server version, do not allow site, user, or dataset preferences
  #all parameters are to be passed in through the http: query line

  phil_objects = []
  argument_interpreter = master_params.command_line_argument_interpreter(
    home_scope="distl")

  from spotfinder.servers.apache_utils import LongLineSimpleNode as SimpleNode
  from spotfinder.applications import signal_strength

  logger = StringIO.StringIO()
  top = SimpleNode("spotfinder")

  try:
    for key in args.keys():
        arg = "%s=%s"%(key,args.get(key,""))
        command_line_params = argument_interpreter.process(arg=arg)
        phil_objects.append(command_line_params)

    working_params = master_params.fetch(sources=phil_objects)
    params = working_params.extract()

    top.child(SimpleNode(tag="file_name",contents=params.distl.image))

    if not os.path.isfile(params.distl.image):
      raise Sorry("%s not a readable file"%params.distl.image)

    Org = signal_strength.run_signal_strength(params)
    assert len(Org.S.images.keys())==1 # there is only one image
    key = Org.S.images.keys()[0]

    # List of spots between specified high- and low-resolution limits
    if Org.S.images[key].has_key('lo_pass_resolution_spots'):
      spots = Org.S.images[key]['lo_pass_resolution_spots']
    elif Org.S.images[key].has_key('inlier_spots'):
      spots = Org.S.images[key]['inlier_spots']
    else:
      spots = []

    if Org.S.images[key].has_key('N_spots_total'):
      total = "%d"%Org.S.images[key]["N_spots_total"]
    else:
      total = "0"

    if Org.S.images[key].has_key('resolution'):
      resolution = Org.S.images[key]['resolution']
    elif Org.S.images[key].has_key('distl_resolution'):
      resolution = Org.S.images[key]['distl_resolution']
    else:
      resolution = 0.0

    top.child(SimpleNode(tag="total_spots",contents=total))
    top.child(SimpleNode(tag="good_spots",contents="%d"%len(spots)))
    top.child(SimpleNode(tag="resolution",contents="%.3f"%resolution))

    if len(Org.S.reporters[key])==0:
      top.child(SimpleNode(tag="total_integrated",contents="0"))
      top.child(SimpleNode(tag="mean_isigi",contents="0"))
    else:
      reporter = Org.S.reporters[key][-1]
      normalizer = reporter.weights.sum()
      summation = 0;
      for x in xrange(reporter.S_table_rows):
        summation += reporter.weights[x] * reporter.MeanIsigI[x]
      top.child(SimpleNode(tag="mean_isigi",contents="%.3f"%(summation/normalizer)))
      integrated = reporter.Integrated.sum()
      top.child(SimpleNode(tag="integrated",contents="%.3f"%integrated))

  except Exception,e:
    top.child(SimpleNode(tag="status",contents=repr(e)))
    top.emit(logger)
    return logger.getvalue()