def test_load_min_missingvalues(self): loader = ProjectDataLoader( dbsession, self.project.geid, 'python/tests/pytest_min_missingvalues.xlsx') with pytest.raises( LoaderException, match=r"Column target_gene_id needs a value in Target tab"): loader.load()
def test_load_min(self): loader = ProjectDataLoader(dbsession, self.project.geid, 'python/tests/pytest_min.xlsx') assert not loader.xls.parse('Target').empty assert not loader.xls.parse('Guide').empty assert not loader.xls.parse('Amplicon').empty assert not loader.xls.parse('Layout').empty loader.load() dbsession.commit() target = dbsession.query(Target)\ .join(Project)\ .filter(Project.geid == self.project.geid)\ .filter(Target.name == 'test_target').one() assert target guide = dbsession.query(Guide)\ .join(Target)\ .join(Project)\ .filter(Project.geid == self.project.geid)\ .filter(Guide.name == 'test_guide')\ .one() assert guide amplicon = dbsession.query(Amplicon)\ .join(Project)\ .filter(Project.geid == self.project.geid)\ .filter(Amplicon.chromosome == 1)\ .filter(Amplicon.start == 1)\ .one() assert amplicon primer = dbsession.query(Primer)\ .join(Amplicon)\ .join(Project)\ .filter(Project.geid == self.project.geid)\ .filter(Amplicon.chromosome == 1)\ .filter(Amplicon.start == 1)\ .filter(Primer.sequence == 'AAAAA')\ .filter(Primer.strand == 'forward')\ .filter(Primer.start == 1)\ .filter(Primer.end == 10)\ .one() assert primer primer = dbsession.query(Primer)\ .join(Amplicon)\ .join(Project)\ .filter(Project.geid == self.project.geid)\ .filter(Amplicon.chromosome == 1)\ .filter(Amplicon.start == 1)\ .filter(Primer.sequence == 'CCCCC')\ .filter(Primer.strand == 'reverse')\ .filter(Primer.start == 101)\ .filter(Primer.end == 110)\ .one() assert primer
def test_load_min_withlayouterror2(self): loader = ProjectDataLoader( dbsession, self.project.geid, 'python/tests/pytest_min_withlayouterror2.xlsx') with pytest.raises( sqlalchemy.exc.IntegrityError, match= r".*UNIQUE constraint failed: layout_content.sequencing_barcode, layout_content.layout_id.*" ): try: loader.load() except sqlalchemy.exc.IntegrityError as e: dbsession.rollback() raise
def test_load_mouse(self): loader = ProjectDataLoader(dbsession, self.project.geid, 'python/tests/pytest_mouse.xlsx') assert not loader.xls.parse('Target').empty assert not loader.xls.parse('Guide').empty assert not loader.xls.parse('Amplicon').empty assert not loader.xls.parse('Layout').empty loader.load() dbsession.commit() target = dbsession.query(Target)\ .join(Project)\ .filter(Project.geid == self.project.geid)\ .filter(Target.name == 'test_mouse_target').one() assert target assert target.genome.name == 'Mus_musculus'
def main(): parser = argparse.ArgumentParser() parser.add_argument("--layout", dest="file_layout", action="store", help="The file layout e.g. '20170118_GEP00001.xlsx'", required=True) parser.add_argument("--geid", dest="geid", action="store", help="Project GEP ID e.g. 'GEP00001'", required=True) options = parser.parse_args() log = logger.get_custom_logger(os.path.join(cfg['PROJECTS_FOLDER'], 'load_layout.log')) try: loader = ProjectDataLoader(dbsession, options.geid, options.file_layout) loader.load() session.commit() except Exception as e: log.exception(e) session.rollback() finally: session.close()
def test_init_empty(self): loader = ProjectDataLoader(dbsession, self.project.geid, 'python/tests/pytest_empty.xlsx') assert loader.project.name == self.project.name assert loader.xls assert loader.xls.parse('Target').empty assert loader.xls.parse('Guide').empty assert loader.xls.parse('Amplicon').empty assert loader.xls.parse('Layout').empty
def project(self): gepid = self.request.matchdict['gepid'] project = self.dbsession.query(Project).filter( Project.geid == gepid).one() plotter = Plotter(self.dbsession, project.geid) # Tables project_header, project_rows = self.get_project_table(project) target_header, target_rows = self.get_target_table(project) guide_header, guide_rows = self.get_guide_table(project) amplicon_header, amplicon_rows = self.get_amplicon_table(project) layout_header, layout_rows = self.get_layout_table(project) return_map = { 'project': project, 'title': "GenEditID", 'subtitle': "Project: {}".format(project.geid), 'info': False, 'error': False, 'project_header': project_header, 'project_rows': project_rows, 'target_header': target_header, 'target_rows': target_rows, 'guide_header': guide_header, 'guide_rows': guide_rows, 'amplicon_header': amplicon_header, 'amplicon_rows': amplicon_rows, 'layout_header': layout_header, 'layout_rows': layout_rows, 'config_header': plotter.config_header(), 'config_rows': plotter.config_rows(), 'coverage_plot': plotter.coverage_plot(), 'coverage_header': plotter.coverage_header(), 'coverage_rows': plotter.coverage_rows(), 'impact_plot': plotter.variant_impact_plot(), 'impact_header': plotter.impact_header(), 'impact_rows': plotter.impact_rows(), 'variant_header': plotter.variant_header(), 'variant_rows': plotter.variant_rows(), 'amplicount_header': plotter.amplicount_header(), 'amplicount_rows': plotter.amplicount_rows(), 'heatmap_plot': plotter.heatmap_plot(), 'koscores_header': plotter.koscores_header(), 'koscores_rows': plotter.koscores_rows(), 'tsearch_plot': plotter.targeted_search_plot(), 'tsearch_config_header': plotter.tsearch_config_header(), 'tsearch_config_rows': plotter.tsearch_config_rows(), 'tsearch_header': plotter.tsearch_header(), 'tsearch_rows': plotter.tsearch_rows(), } self.logger.debug('project return_map') if 'submit_project_data' in self.request.params: file_path = None try: error = False file_path = self._upload("layoutfile", ".xlsx") self.dbsession.begin_nested() loader = ProjectDataLoader(self.dbsession, project.geid, file_path) loader.load() self.dbsession.commit() shutil.copyfile( file_path, os.path.join(project.project_folder, "{}.xlsx".format(project.geid))) project_header, project_rows = self.get_project_table(project) target_header, target_rows = self.get_target_table(project) guide_header, guide_rows = self.get_guide_table(project) amplicon_header, amplicon_rows = self.get_amplicon_table( project) layout_header, layout_rows = self.get_layout_table(project) return_map = { 'project': project, 'title': "GenEditID", 'subtitle': "Project: {}".format(project.geid), 'info': "Project configuration file has been uploaded successfully.", 'error': False, 'project_header': project_header, 'project_rows': project_rows, 'target_header': target_header, 'target_rows': target_rows, 'guide_header': guide_header, 'guide_rows': guide_rows, 'amplicon_header': amplicon_header, 'amplicon_rows': amplicon_rows, 'layout_header': layout_header, 'layout_rows': layout_rows, 'config_header': plotter.config_header(), 'config_rows': plotter.config_rows(), 'coverage_plot': plotter.coverage_plot(), 'coverage_header': plotter.coverage_header(), 'coverage_rows': plotter.coverage_rows(), 'impact_plot': plotter.variant_impact_plot(), 'impact_header': plotter.impact_header(), 'impact_rows': plotter.impact_rows(), 'variant_header': plotter.variant_header(), 'variant_rows': plotter.variant_rows(), 'amplicount_header': plotter.amplicount_header(), 'amplicount_rows': plotter.amplicount_rows(), 'heatmap_plot': plotter.heatmap_plot(), 'koscores_header': plotter.koscores_header(), 'koscores_rows': plotter.koscores_rows(), 'tsearch_plot': plotter.targeted_search_plot(), 'tsearch_config_header': plotter.tsearch_config_header(), 'tsearch_config_rows': plotter.tsearch_config_rows(), 'tsearch_header': plotter.tsearch_header(), 'tsearch_rows': plotter.tsearch_rows(), } return HTTPFound( self.request.route_url('project', gepid=project.geid)) except FinderException as e: self.dbsession.rollback() error = "Unexpected finder error: {}".format(e) self.logger.error(error) except LoaderException as e: self.dbsession.rollback() error = "Unexpected loader error: {}".format(e) self.logger.error(error) except ValueError as e: self.dbsession.rollback() error = "Unexpected value error: {}".format(e) self.logger.error(error) except DBAPIError as e: self.dbsession.rollback() error = "Unexpected database error: {}".format(e) self.logger.error(error) except AttributeError as e: self.dbsession.rollback() error = "Unexpected error: {}".format(e) if not file_path: error = "No file selected. Please select a file before uploading." self.logger.error(error) finally: if file_path: try: os.remove(file_path) except OSError: pass return_map['error'] = error return return_map return return_map