예제 #1
0
def as_csv(spotfinder_results, out=None):
    if out is None:
        import sys
        out = sys.stdout
    columns = as_columns(spotfinder_results)
    from iotbx import csv_utils
    csv_utils.writer(out, columns.values(), field_names=columns.keys())
예제 #2
0
def as_csv(spotfinder_results, out=None):
    if out is None:
        import sys

        out = sys.stdout
    columns = as_columns(spotfinder_results)
    from iotbx import csv_utils

    csv_utils.writer(out, columns.values(), field_names=columns.keys())
예제 #3
0
def exercise_reader():
  from iotbx import csv_utils

  x = (1,2,3,4,5)
  y = (6,7,8,9,10)
  f = open_tmp_file()
  field_names = ('x','y')
  csv_utils.writer(f, (x,y), field_names=field_names,delimiter=';')
  f.close()
  f = open(f.name, 'r')
  a = csv_utils.reader(f, data_type=int, field_names=True,delimiter=';')
  f.close()
  assert tuple(a.data[0]) == x
  assert tuple(a.data[1]) == y

  x = (1,2,3,4,5)
  y = (1.1,2.2,3.3,4.4,5.5)
  f = open_tmp_file()
  csv_utils.writer(f, (x,y))
  f.close()
  f = open(f.name, 'r')
  data_type_list = (int, float)
  a = csv_utils.reader(f, data_type_list=data_type_list)
  f.close()
  assert tuple(a.data[0]) == x
  assert tuple(a.data[1]) == y

  f = open(f.name, 'r')
  data_type_list = (int, float)
  try:
    a = csv_utils.reader(f, data_type=int,
                         data_type_list=data_type_list)
    # Can't pass data_type AND data_type_list
  except AssertionError:
    pass
  else:
    raise Exception_expected
  f.close()

  f = open(f.name, 'r')
  a = csv_utils.reader(f)
  f.close()
  assert list(a.data[0]) == [str(i) for i in x]
  assert list(a.data[1]) == [str(i) for i in y]
예제 #4
0
def exercise_reader():
    from iotbx import csv_utils

    x = (1, 2, 3, 4, 5)
    y = (6, 7, 8, 9, 10)
    f = open_tmp_file()
    field_names = ('x', 'y')
    csv_utils.writer(f, (x, y), field_names=field_names, delimiter=';')
    f.close()
    f = open(f.name, 'r')
    a = csv_utils.reader(f, data_type=int, field_names=True, delimiter=';')
    f.close()
    assert tuple(a.data[0]) == x
    assert tuple(a.data[1]) == y

    x = (1, 2, 3, 4, 5)
    y = (1.1, 2.2, 3.3, 4.4, 5.5)
    f = open_tmp_file()
    csv_utils.writer(f, (x, y))
    f.close()
    f = open(f.name, 'r')
    data_type_list = (int, float)
    a = csv_utils.reader(f, data_type_list=data_type_list)
    f.close()
    assert tuple(a.data[0]) == x
    assert tuple(a.data[1]) == y

    f = open(f.name, 'r')
    data_type_list = (int, float)
    try:
        a = csv_utils.reader(f, data_type=int, data_type_list=data_type_list)
        # Can't pass data_type AND data_type_list
    except AssertionError:
        pass
    else:
        raise Exception_expected
    f.close()

    f = open(f.name, 'r')
    a = csv_utils.reader(f)
    f.close()
    assert list(a.data[0]) == [str(i) for i in x]
    assert list(a.data[1]) == [str(i) for i in y]
예제 #5
0
def exercise_writer():
    from iotbx import csv_utils

    x = (1, 2, 3, 4, 5)
    y = (6, 7, 8, 9, 10)
    f = open_tmp_file()
    field_names = ('x', 'y')
    csv_utils.writer(f, (x, y), field_names=field_names)
    f.close()
    f = open(f.name, 'r')
    content = [l.strip() for l in f.readlines()]

    text = ['x,y']
    text += ['%s,%s' % (row[0], row[1]) for row in zip(x, y)]
    assert content == text
    f.close()

    x = (1, 2, 3, 4, 5)
    y = (6, 7, 8, 9, 10)
    f = open_tmp_file()
    csv_utils.writer(f, (x, y), delimiter=';')
    f.close()
    f = open(f.name, 'r')
    content = [l.strip() for l in f.readlines()]
    text = ['%s;%s' % (row[0], row[1]) for row in zip(x, y)]
    assert content == text
    f.close()

    x = flex.int(x)
    y = flex.int(y)
    f = open_tmp_file()
    csv_utils.writer(f, (x, y), field_names=field_names)
    f.close()
    f = open(f.name, 'r')
    content = [l.strip() for l in f.readlines()]
    text = ['x,y']
    text += ['%s,%s' % (row[0], row[1]) for row in zip(x, y)]
    assert content == text
    f.close()

    y.append(11)
    f = open_tmp_file()
    try:
        csv_utils.writer(f, (x, y), field_names=field_names)
    except AssertionError:
        pass
    else:
        raise Exception_expected
    f.close()
예제 #6
0
def exercise_writer():
  from iotbx import csv_utils

  x = (1,2,3,4,5)
  y = (6,7,8,9,10)
  f = open_tmp_file()
  field_names = ('x','y')
  csv_utils.writer(f, (x,y), field_names=field_names)
  f.close()
  f = open(f.name, 'r')
  content = f.readlines()
  text = ['x,y\r\n']
  text += ['%s,%s\r\n' %(row[0],row[1]) for row in zip(x,y)]
  assert content == text
  f.close()

  x = (1,2,3,4,5)
  y = (6,7,8,9,10)
  f = open_tmp_file()
  csv_utils.writer(f, (x,y), delimiter=';')
  f.close()
  f = open(f.name, 'r')
  content = f.readlines()
  text = ['%s;%s\r\n' %(row[0],row[1]) for row in zip(x,y)]
  assert content == text

  x = flex.int(x)
  y = flex.int(y)
  f = open_tmp_file()
  csv_utils.writer(f, (x,y), field_names=field_names)
  f.close()
  f = open(f.name, 'r')
  content = f.readlines()
  text = ['x,y\r\n']
  text += ['%s,%s\r\n' %(row[0],row[1]) for row in zip(x,y)]
  assert content == text
  f.close()

  y.append(11)
  f = open_tmp_file()
  try:
    csv_utils.writer(f, (x,y), field_names=field_names)
  except AssertionError:
    pass
  else:
    raise Exception_expected
  f.close()
예제 #7
0
 def exercise(self, debug=False):
   if debug:
     distribution = distributions.normal_distribution()
     observed_deviations = (
       self.fo2.data() - self.scale_factor*self.fc.as_intensity_array().data())
     observed_deviations = observed_deviations.select(
       flex.sort_permutation(observed_deviations))
     expected_deviations = distribution.quantiles(observed_deviations.size())
     csv_utils.writer(
       open('delta_F_npp.csv', 'wb'), (expected_deviations, observed_deviations))
   # first with the correct absolute structure
   gaussian = absolute_structure.hooft_analysis(self.fo2, self.fc)
   analyses = [gaussian]
   NPP = absolute_structure.bijvoet_differences_probability_plot(gaussian)
   if self.use_students_t_errors:
     nu_calc = absolute_structure.maximise_students_t_correlation_coefficient(
       NPP.y, min_nu=1, max_nu=200)
     t_analysis = absolute_structure.students_t_hooft_analysis(
       self.fo2, self.fc, nu_calc, probability_plot_slope=NPP.fit.slope())
     analyses.append(gaussian)
     tPP = absolute_structure.bijvoet_differences_probability_plot(
       t_analysis, use_students_t_distribution=True, students_t_nu=nu_calc)
     if tPP.distribution.degrees_of_freedom() < 100:
       assert tPP.correlation.coefficient() > NPP.correlation.coefficient()
   else:
     assert approx_equal(NPP.correlation.coefficient(), 1, 0.005)
   for analysis in analyses:
     assert approx_equal(analysis.hooft_y, 0, 1e-2)
     assert approx_equal(analysis.p2_true, 1)
     assert approx_equal(analysis.p2_false, 0)
     assert approx_equal(analysis.p3_true, 1)
     assert approx_equal(analysis.p3_false, 0)
     assert approx_equal(analysis.p3_racemic_twin, 0)
   if debug:
     csv_utils.writer(open('npp.csv', 'wb'), (NPP.x,NPP.y))
     if self.use_students_t_errors:
       csv_utils.writer(open('tpp.csv', 'wb'), (tPP.x,tPP.y))
   assert approx_equal(NPP.fit.y_intercept(), 0)
   # and now with the wrong absolute structure
   gaussian = absolute_structure.hooft_analysis(self.fo2, self.fc_i)
   analyses = [gaussian]
   NPP = absolute_structure.bijvoet_differences_probability_plot(gaussian)
   if self.use_students_t_errors:
     nu_calc = absolute_structure.maximise_students_t_correlation_coefficient(
       NPP.y, min_nu=1, max_nu=200)
     t_analysis = absolute_structure.students_t_hooft_analysis(
       self.fo2, self.fc_i, nu_calc, probability_plot_slope=NPP.fit.slope())
     analyses.append(gaussian)
     tPP = absolute_structure.bijvoet_differences_probability_plot(
       t_analysis, use_students_t_distribution=True)
     if tPP.distribution.degrees_of_freedom() < 100:
       assert tPP.correlation.coefficient() > NPP.correlation.coefficient()
   else:
     assert approx_equal(NPP.correlation.coefficient(), 1, 0.002)
     assert approx_equal(NPP.fit.y_intercept(), 0)
   for analysis in analyses:
     assert approx_equal(analysis.hooft_y, 1, 1e-2)
     assert approx_equal(analysis.p2_true, 0)
     assert approx_equal(analysis.p2_false, 1)
     assert approx_equal(analysis.p3_true, 0)
     assert approx_equal(analysis.p3_false, 1)
     assert approx_equal(analysis.p3_racemic_twin, 0)
   # test for the case of a racemic twin
   gaussian = absolute_structure.hooft_analysis(self.fo2_twin, self.fc)
   analyses = [gaussian]
   NPP = absolute_structure.bijvoet_differences_probability_plot(gaussian)
   if self.use_students_t_errors:
     nu_calc = absolute_structure.maximise_students_t_correlation_coefficient(
       NPP.y, min_nu=1, max_nu=200)
     t_analysis = absolute_structure.students_t_hooft_analysis(
       self.fo2_twin, self.fc, nu_calc, probability_plot_slope=NPP.fit.slope())
     tPP = absolute_structure.bijvoet_differences_probability_plot(
       t_analysis, use_students_t_distribution=True)
     if tPP.distribution.degrees_of_freedom() < 100:
       assert tPP.correlation.coefficient() > NPP.correlation.coefficient()
   else:
     assert approx_equal(NPP.correlation.coefficient(), 1, 0.002)
     assert approx_equal(NPP.fit.y_intercept(), 0)
   for analysis in analyses:
     assert approx_equal(analysis.hooft_y, 0.5, 1e-2)
     assert approx_equal(analysis.p3_true, 0)
     assert approx_equal(analysis.p3_false, 0)
     assert approx_equal(analysis.p3_racemic_twin, 1)
 def exercise(self, debug=False):
   if debug:
     distribution = distributions.normal_distribution()
     observed_deviations = (
       self.fo2.data() - self.scale_factor*self.fc.as_intensity_array().data())
     observed_deviations = observed_deviations.select(
       flex.sort_permutation(observed_deviations))
     expected_deviations = distribution.quantiles(observed_deviations.size())
     csv_utils.writer(
       open('delta_F_npp.csv', 'wb'), (expected_deviations, observed_deviations))
   # first with the correct absolute structure
   gaussian = absolute_structure.hooft_analysis(self.fo2, self.fc)
   analyses = [gaussian]
   NPP = absolute_structure.bijvoet_differences_probability_plot(gaussian)
   if self.use_students_t_errors:
     nu_calc = absolute_structure.maximise_students_t_correlation_coefficient(
       NPP.y, min_nu=1, max_nu=200)
     t_analysis = absolute_structure.students_t_hooft_analysis(
       self.fo2, self.fc, nu_calc, probability_plot_slope=NPP.fit.slope())
     analyses.append(gaussian)
     tPP = absolute_structure.bijvoet_differences_probability_plot(
       t_analysis, use_students_t_distribution=True, students_t_nu=nu_calc)
     if tPP.distribution.degrees_of_freedom() < 100:
       assert tPP.correlation.coefficient() > NPP.correlation.coefficient()
   else:
     assert approx_equal(NPP.correlation.coefficient(), 1, 0.005)
   for analysis in analyses:
     assert approx_equal(analysis.hooft_y, 0, 1e-2)
     assert approx_equal(analysis.p2_true, 1)
     assert approx_equal(analysis.p2_false, 0)
     assert approx_equal(analysis.p3_true, 1)
     assert approx_equal(analysis.p3_false, 0)
     assert approx_equal(analysis.p3_racemic_twin, 0)
   if debug:
     csv_utils.writer(open('npp.csv', 'wb'), (NPP.x,NPP.y))
     if self.use_students_t_errors:
       csv_utils.writer(open('tpp.csv', 'wb'), (tPP.x,tPP.y))
   assert approx_equal(NPP.fit.y_intercept(), 0)
   # and now with the wrong absolute structure
   gaussian = absolute_structure.hooft_analysis(self.fo2, self.fc_i)
   analyses = [gaussian]
   NPP = absolute_structure.bijvoet_differences_probability_plot(gaussian)
   if self.use_students_t_errors:
     nu_calc = absolute_structure.maximise_students_t_correlation_coefficient(
       NPP.y, min_nu=1, max_nu=200)
     t_analysis = absolute_structure.students_t_hooft_analysis(
       self.fo2, self.fc_i, nu_calc, probability_plot_slope=NPP.fit.slope())
     analyses.append(gaussian)
     tPP = absolute_structure.bijvoet_differences_probability_plot(
       t_analysis, use_students_t_distribution=True)
     if tPP.distribution.degrees_of_freedom() < 100:
       assert tPP.correlation.coefficient() > NPP.correlation.coefficient()
   else:
     assert approx_equal(NPP.correlation.coefficient(), 1, 0.002)
     assert approx_equal(NPP.fit.y_intercept(), 0)
   for analysis in analyses:
     assert approx_equal(analysis.hooft_y, 1, 1e-2)
     assert approx_equal(analysis.p2_true, 0)
     assert approx_equal(analysis.p2_false, 1)
     assert approx_equal(analysis.p3_true, 0)
     assert approx_equal(analysis.p3_false, 1)
     assert approx_equal(analysis.p3_racemic_twin, 0)
   # test for the case of a racemic twin
   gaussian = absolute_structure.hooft_analysis(self.fo2_twin, self.fc)
   analyses = [gaussian]
   NPP = absolute_structure.bijvoet_differences_probability_plot(gaussian)
   if self.use_students_t_errors:
     nu_calc = absolute_structure.maximise_students_t_correlation_coefficient(
       NPP.y, min_nu=1, max_nu=200)
     t_analysis = absolute_structure.students_t_hooft_analysis(
       self.fo2_twin, self.fc, nu_calc, probability_plot_slope=NPP.fit.slope())
     tPP = absolute_structure.bijvoet_differences_probability_plot(
       t_analysis, use_students_t_distribution=True)
     if tPP.distribution.degrees_of_freedom() < 100:
       assert tPP.correlation.coefficient() > NPP.correlation.coefficient()
   else:
     assert approx_equal(NPP.correlation.coefficient(), 1, 0.002)
     assert approx_equal(NPP.fit.y_intercept(), 0)
   for analysis in analyses:
     assert approx_equal(analysis.hooft_y, 0.5, 1e-2)
     assert approx_equal(analysis.p3_true, 0)
     assert approx_equal(analysis.p3_false, 0)
     assert approx_equal(analysis.p3_racemic_twin, 1)