Exemplo n.º 1
0
    def test_split_at_with_header(self):
        source = StringIO("""@header1
AGCTTTTT
+
@IIIB+++
@header2
AGCTTTTT
+
IIIIB+++
""")
        target1 = StringIO()
        target2 = StringIO()

        srf2fastq.convert_single_to_two_fastq(source, target1, target2, header="foo_")

        target1.seek(0)
        lines1 = target1.readlines()
        self.assertEqual(len(lines1),8)
        self.assertEqual(lines1[0].rstrip(), '@foo_header1/1')
        self.assertEqual(lines1[1].rstrip(), 'AGCT')
        self.assertEqual(lines1[2].rstrip(), '+')
        self.assertEqual(lines1[3].rstrip(), '@III')

        target2.seek(0)
        lines2 = target2.readlines()
        self.assertEqual(len(lines2),8)
        self.assertEqual(lines2[0].rstrip(), '@foo_header1/2')
        self.assertEqual(lines2[1].rstrip(), 'TTTT')
        self.assertEqual(lines2[2].rstrip(), '+')
        self.assertEqual(lines2[3].rstrip(), 'B+++')
Exemplo n.º 2
0
    def test_split_good(self):
        source = StringIO("""@header
AGCTTTTT
+
IIIIB+++
""")
        target1 = StringIO()
        target2 = StringIO()

        srf2fastq.convert_single_to_two_fastq(source, target1, target2)

        target1.seek(0)
        lines1 = target1.readlines()
        self.assertEqual(len(lines1),4)
        self.assertEqual(lines1[0].rstrip(), '@header/1')
        self.assertEqual(lines1[1].rstrip(), 'AGCT')
        self.assertEqual(lines1[2].rstrip(), '+')
        self.assertEqual(lines1[3].rstrip(), 'IIII')

        target2.seek(0)
        lines2 = target2.readlines()
        self.assertEqual(len(lines2),4)
        self.assertEqual(lines2[0].rstrip(), '@header/2')
        self.assertEqual(lines2[1].rstrip(), 'TTTT')
        self.assertEqual(lines2[2].rstrip(), '+')
        self.assertEqual(lines2[3].rstrip(), 'B+++')
Exemplo n.º 3
0
def test_show_urls(mfindurls):
    mfindurls.return_value = URLS
    args = argparse.Namespace(
        server='test.datafind.com:443',
        observatory='X',
        type='test',
        gpsstart=0,
        gpsend=10,
        url_type='file',
        match=None,
        lal_cache=False,
        names_only=False,
        frame_cache=False,
        gaps=None,
    )
    out = StringIO()
    main.show_urls(args, out)
    assert mfindurls.called_with(args.observatory,
                                 args.type,
                                 args.gpsstart,
                                 args.gpsend,
                                 match=args.match,
                                 urltype=args.url_type,
                                 on_gaps='ignore',
                                 host=args.server)
    out.seek(0)
    assert list(map(str.rstrip, out.readlines())) == URLS
Exemplo n.º 4
0
def test_show_observatories(mfindobs):
    mfindobs.return_value = ['A', 'B', 'C']
    args = argparse.Namespace(
        server='test.datafind.com:443',
        match='test',
    )
    out = StringIO()
    main.show_observatories(args, out)
    out.seek(0)
    assert mfindobs.called_with(host=args.server, match=args.match)
    assert list(map(str.rstrip, out.readlines())) == ['A', 'B', 'C']
Exemplo n.º 5
0
class TestProgressMeter(TestCase):
    def setUp(self):
        self.buf = StringIO()

    def tearDown(self):
        del self.buf

    def _assert_in(self, output, string):
        assert_(string in output,
                "Output '{0}' does not match required format '{1}'.".format(
                output.replace('\r', '\\r'), string))


    def test_default_ProgressMeter(self, n=101, interval=10):
        format = "Step %(step)5d/%(numsteps)d [%(percentage)5.1f%%]\r"
        with RedirectedStderr(self.buf):
            pm = MDAnalysis.lib.log.ProgressMeter(n, interval=interval)
            for frame in range(n):
                pm.echo(frame)
        self.buf.seek(0)
        output = "".join(self.buf.readlines())
        self._assert_in(output, format % {'step': 1, 'numsteps': n, 'percentage': 100./n})
        # last line always has \n instead of \r!
        self._assert_in(output, format.replace('\r', '\n') %
                        {'step': n, 'numsteps': n, 'percentage': 100.})

    def test_custom_ProgressMeter(self, n=51, interval=7):
        format = "RMSD %(rmsd)5.2f at %(step)03d/%(numsteps)4d [%(percentage)5.1f%%]\r"
        with RedirectedStderr(self.buf):
            pm = MDAnalysis.lib.log.ProgressMeter(n, interval=interval,
                                                  format=format, offset=1)
            for frame in range(n):
                rmsd = 0.02 * frame * (n+1)/float(n)  # n+1/n correction for 0-based frame vs 1-based counting
                pm.echo(frame, rmsd=rmsd)
        self.buf.seek(0)
        output = "".join(self.buf.readlines())
        self._assert_in(output, format %
                        {'rmsd': 0.0, 'step': 1, 'numsteps': n, 'percentage': 100./n})
        # last line always has \n instead of \r!
        self._assert_in(output, format.replace('\r', '\n') %
                        {'rmsd': 0.02*n, 'step': n, 'numsteps': n, 'percentage': 100.0})
Exemplo n.º 6
0
def test_to_xds(dials_regression, tmpdir):
    tmpdir.chdir()
    template = os.path.join(dials_regression, 'centroid_test_data',
                            "centroid_00*.cbf")
    file_names = glob.glob(template)
    sweep = ImageSetFactory.new(file_names)[0]
    to_xds = xds.to_xds(sweep)
    s1 = StringIO()
    to_xds.XDS_INP(out=s1)
    empty = StringIO()
    s1a = to_xds.XDS_INP(as_str=True, out=empty)
    assert empty.getvalue() == ''
    assert s1.getvalue().strip() == s1a
    s2 = StringIO()
    real_space_a = (-5.327642, -39.034747, -4.988286)
    real_space_b = (-35.253495, 7.596265, -22.127661)
    real_space_c = (-22.673623, -1.486119, 35.793463)
    to_xds.xparm_xds(real_space_a,
                     real_space_b,
                     real_space_c,
                     space_group=1,
                     out=s2)
    # run coordinate frame converter on xparm.xds as a sanity check
    with open('xparm.xds', mode="wb") as fh:
        s2.seek(0)
        fh.writelines(s2.readlines())
    from rstbx.cftbx import coordinate_frame_helpers
    converter = coordinate_frame_helpers.import_xds_xparm('xparm.xds')
    scan = sweep.get_scan()
    detector = sweep.get_detector()
    goniometer = sweep.get_goniometer()
    beam = sweep.get_beam()
    assert approx_equal(real_space_a, converter.get_real_space_a())
    assert approx_equal(real_space_b, converter.get_real_space_b())
    assert approx_equal(real_space_c, converter.get_real_space_c())
    assert approx_equal(goniometer.get_rotation_axis(),
                        converter.get_rotation_axis())
    assert approx_equal(beam.get_direction(),
                        converter.get_sample_to_source().elems)
    assert approx_equal(detector[0].get_fast_axis(),
                        converter.get_detector_fast())
    assert approx_equal(detector[0].get_slow_axis(),
                        converter.get_detector_slow())
    assert approx_equal(detector[0].get_origin(),
                        converter.get_detector_origin())
Exemplo n.º 7
0
def test_show_times(mfindtimes):
    mfindtimes.return_value = [segment(0, 1), segment(1, 2), segment(3, 4)]
    args = argparse.Namespace(
        server='test.datafind.com:443',
        observatory='X',
        type='test',
        gpsstart=0,
        gpsend=10,
    )
    out = StringIO()
    main.show_times(args, out)
    assert mfindtimes.called_with(host=args.server,
                                  site=args.observatory,
                                  frametype=args.type,
                                  gpsstart=args.gpsstart,
                                  gpsend=args.gpsend)
    out.seek(0)
    for i, line in enumerate(out.readlines()[1:]):
        seg = mfindtimes.return_value[i]
        assert line.split() == list(map(str, (i, seg[0], seg[1], abs(seg))))
Exemplo n.º 8
0
    def test_single_at(self):
        source = StringIO("""@header1
AGCTTTTT
+
@IIIB+++
@header2
AGCTTTTT
+
IIIIB+++
""")
        target1 = StringIO()

        srf2fastq.convert_single_to_fastq(source, target1)

        target1.seek(0)
        lines1 = target1.readlines()
        self.assertEqual(len(lines1),8)
        self.assertEqual(lines1[0].rstrip(), '@header1')
        self.assertEqual(lines1[1].rstrip(), 'AGCTTTTT')
        self.assertEqual(lines1[2].rstrip(), '+')
        self.assertEqual(lines1[3].rstrip(), '@IIIB+++')
Exemplo n.º 9
0
            log.removeHandler(logging_handler)
            args_obj, _, _ = app.make_cli_parser().interpret_args(['--verbose'])
            logging_handler = app.setup_logging(args_obj)
            log.debug("this one is captured")

            log.removeHandler(logging_handler)
            args_obj, _, _ = app.make_cli_parser().interpret_args(['--silent'])
            logging_handler = app.setup_logging(args_obj)
            log.debug("not captured")
            log.warning("not captured")
            log.info("not captured")
            log.error("also captured")

            fle.flush()
            fle.seek(0)
            logs = fle.readlines()
            now = datetime.datetime.now()
            date = now.strftime("%Y-%m-%d [^ ]+")
            expect = [
                  re.compile("{0} INFO    blah            hello there".format(date))
                , re.compile("{0} ERROR   blah            hmmm".format(date))
                , re.compile("{0} WARNING blah            yeap".format(date))
                , re.compile("{0} DEBUG   blah            this one is captured".format(date))
                , re.compile("{0} ERROR   blah            also captured".format(date))
                ]

            self.assertEqual(len(expect), len(logs), logs)
            for index, line in enumerate(expect):
                assert line.match(logs[index].strip()), "Expected '{0}' to match '{1}'".format(logs[index].strip().replace('\t', '\\t').replace(' ', '.'), line.pattern.replace('\t', '\\t').replace(' ', '.'))

    describe "make_cli_parser":
Exemplo n.º 10
0
def test_to_xds(dials_regression, tmpdir):
    tmpdir.chdir()
    template = os.path.join(dials_regression, "centroid_test_data",
                            "centroid_00*.cbf")
    file_names = glob.glob(template)
    sweep = ImageSetFactory.new(file_names)[0]
    to_xds = xds.to_xds(sweep)
    s1 = to_xds.XDS_INP()
    expected = """\
DETECTOR=PILATUS MINIMUM_VALID_PIXEL_VALUE=0 OVERLOAD=495976
SENSOR_THICKNESS= 0.320
!SENSOR_MATERIAL / THICKNESS Si 0.320
!SILICON= 3.960382
DIRECTION_OF_DETECTOR_X-AXIS= 1.00000 0.00000 0.00000
DIRECTION_OF_DETECTOR_Y-AXIS= 0.00000 1.00000 0.00000
NX=2463 NY=2527 QX=0.1720 QY=0.1720
DETECTOR_DISTANCE= 190.180000
ORGX= 1235.84 ORGY= 1279.58
ROTATION_AXIS= 1.00000 0.00000 0.00000
STARTING_ANGLE= 0.000
OSCILLATION_RANGE= 0.200
X-RAY_WAVELENGTH= 0.97950
INCIDENT_BEAM_DIRECTION= -0.000 -0.000 1.021
FRACTION_OF_POLARIZATION= 0.999
POLARIZATION_PLANE_NORMAL= 0.000 1.000 0.000
NAME_TEMPLATE_OF_DATA_FRAMES= %s
TRUSTED_REGION= 0.0 1.41
UNTRUSTED_RECTANGLE= 487 495 0 2528
UNTRUSTED_RECTANGLE= 981 989 0 2528
UNTRUSTED_RECTANGLE= 1475 1483 0 2528
UNTRUSTED_RECTANGLE= 1969 1977 0 2528
UNTRUSTED_RECTANGLE= 0 2464 195 213
UNTRUSTED_RECTANGLE= 0 2464 407 425
UNTRUSTED_RECTANGLE= 0 2464 619 637
UNTRUSTED_RECTANGLE= 0 2464 831 849
UNTRUSTED_RECTANGLE= 0 2464 1043 1061
UNTRUSTED_RECTANGLE= 0 2464 1255 1273
UNTRUSTED_RECTANGLE= 0 2464 1467 1485
UNTRUSTED_RECTANGLE= 0 2464 1679 1697
UNTRUSTED_RECTANGLE= 0 2464 1891 1909
UNTRUSTED_RECTANGLE= 0 2464 2103 2121
UNTRUSTED_RECTANGLE= 0 2464 2315 2333
DATA_RANGE= 1 9
JOB=XYCORR INIT COLSPOT IDXREF DEFPIX INTEGRATE CORRECT\
""" % os.path.join(dials_regression, "centroid_test_data", "centroid_????.cbf")
    assert s1 == expected
    s2 = StringIO()
    real_space_a = (-5.327642, -39.034747, -4.988286)
    real_space_b = (-35.253495, 7.596265, -22.127661)
    real_space_c = (-22.673623, -1.486119, 35.793463)
    to_xds.xparm_xds(real_space_a,
                     real_space_b,
                     real_space_c,
                     space_group=1,
                     out=s2)
    # run coordinate frame converter on xparm.xds as a sanity check
    with open("xparm.xds", mode="wb") as fh:
        s2.seek(0)
        fh.writelines(s2.readlines())
    from rstbx.cftbx import coordinate_frame_helpers

    converter = coordinate_frame_helpers.import_xds_xparm("xparm.xds")
    scan = sweep.get_scan()
    detector = sweep.get_detector()
    goniometer = sweep.get_goniometer()
    beam = sweep.get_beam()
    assert approx_equal(real_space_a, converter.get_real_space_a())
    assert approx_equal(real_space_b, converter.get_real_space_b())
    assert approx_equal(real_space_c, converter.get_real_space_c())
    assert approx_equal(goniometer.get_rotation_axis(),
                        converter.get_rotation_axis())
    assert approx_equal(beam.get_direction(),
                        converter.get_sample_to_source().elems)
    assert approx_equal(detector[0].get_fast_axis(),
                        converter.get_detector_fast())
    assert approx_equal(detector[0].get_slow_axis(),
                        converter.get_detector_slow())
    assert approx_equal(detector[0].get_origin(),
                        converter.get_detector_origin())