def test_00_metadata_edit( self ):
     """test_metadata_edit: Testing metadata editing"""
     self.logout()
     self.login( email='*****@*****.**', username='******' )
     admin_user = sa_session.query( galaxy.model.User ) \
                           .filter( galaxy.model.User.table.c.email=='*****@*****.**' ) \
                           .one()
     self.new_history( name='Test Metadata Edit' )
     history1 = sa_session.query( galaxy.model.History ) \
                         .filter( and_( galaxy.model.History.table.c.deleted==False,
                                        galaxy.model.History.table.c.user_id==admin_user.id ) ) \
                         .order_by( desc( galaxy.model.History.table.c.create_time ) ) \
                         .first()
     self.upload_file( '1.bed' )
     latest_hda = sa_session.query( galaxy.model.HistoryDatasetAssociation ) \
                           .order_by( desc( galaxy.model.HistoryDatasetAssociation.table.c.create_time ) ) \
                           .first()
     self.home()
     # Due to twill not being able to handle the permissions forms, we'll eliminate
     # DefaultHistoryPermissions prior to uploading a dataset so that the permission
     # form will not be displayed on ted edit attributes page.
     for dp in latest_hda.dataset.actions:
         sa_session.delete( dp )
         sa_session.flush()
     sa_session.refresh( latest_hda.dataset )
     self.check_history_for_string( '1.bed' )
     self.check_metadata_for_string( '1.bed uploaded file unspecified (\?) chromCol value="1" selected endCol value="3" is_strandCol value="true" checked', hid=str( latest_hda.hid ) )
     """test editing attributes"""
     self.edit_hda_attribute_info( hda_id=str( latest_hda.id ),
                                   new_name='Testdata',
                                   new_info="Uploaded my file",
                                   new_dbkey='hg16',
                                   new_startcol='6' )
     self.check_metadata_for_string( 'Testdata bed Uploaded my file hg16 "bed" selected="yes" "startCol" value="6" selected', hid=str( latest_hda.hid ) )
     """test Auto-detecting attributes"""
     self.auto_detect_metadata( hda_id=str( latest_hda.id ) )
     self.check_metadata_for_string('Testdata bed Uploaded my file hg16 "bed" selected="yes" "startCol" value="2" selected', hid=str( latest_hda.hid ) )
     """test converting formats"""
     self.convert_format( hda_id=str( latest_hda.id ), target_type='gff' )
     self.check_metadata_for_string( '"gff" selected="yes"', hid=str( latest_hda.hid ) )
     """test changing data type"""
     self.change_datatype( hda_id=str( latest_hda.id ), datatype='gff3' )
     self.check_metadata_for_string( 'gff3', hid=str( latest_hda.hid ) )
     self.delete_history( id=self.security.encode_id( history1.id ) )
     self.logout()
 def test_999_reset_data_for_later_test_runs( self ):
     """Reseting data to enable later test runs to pass"""
     # Logged in as regular_user2
     self.logout()
     self.login( email=admin_user.email )
     ##################
     # Purge all libraries
     ##################
     for library in [ library1, library2 ]:
         self.delete_library_item( 'library_admin',
                                   self.security.encode_id( library.id ),
                                   self.security.encode_id( library.id ),
                                   library.name,
                                   item_type='library' )
         self.purge_library( self.security.encode_id( library.id ), library.name )
     ##################
     # Eliminate all non-private roles
     ##################
     for role in [ role1, role2 ]:
         self.mark_role_deleted( self.security.encode_id( role.id ), role.name )
         self.purge_role( self.security.encode_id( role.id ), role.name )
         # Manually delete the role from the database
         refresh( role )
         sa_session.delete( role )
         sa_session.flush()
     ##################
     # Eliminate all groups
     ##################
     for group in [ group1 ]:
         self.mark_group_deleted( self.security.encode_id( group.id ), group.name )
         self.purge_group( self.security.encode_id( group.id ), group.name )
         # Manually delete the group from the database
         refresh( group )
         sa_session.delete( group )
         sa_session.flush()
     ##################
     # Make sure all users are associated only with their private roles
     ##################
     for user in [ admin_user, regular_user1, regular_user2, regular_user3 ]:
         refresh( user )
         if len( user.roles) != 1:
             raise AssertionError( '%d UserRoleAssociations are associated with %s ( should be 1 )' % ( len( user.roles ), user.email ) )
 def test_get_DNAseHSS_flanked_genes( self ):
     self.logout()
     self.login( email='*****@*****.**' )
     admin_user = sa_session.query( galaxy.model.User ) \
                            .filter( galaxy.model.User.table.c.email=='*****@*****.**' ) \
                            .one()
     self.new_history( name='DNAseHSS_flanked_genes' )
     history1 = sa_session.query( galaxy.model.History ) \
                          .filter( and_( galaxy.model.History.table.c.deleted==False,
                                         galaxy.model.History.table.c.user_id==admin_user.id ) ) \
                          .order_by( desc( galaxy.model.History.table.c.create_time ) ) \
                          .first()
     track_params = dict(
         db="hg17",
         hgta_group="regulation",
         hgta_table="dukeDnaseCd4Sites",
         hgta_track="dukeDnaseCd4Sites",
         hgta_regionType="range",
         position="chr22",
         hgta_outputType="bed",
         sendToGalaxy="1"
     )
     output_params = dict(
         fbQual="whole",
     )
     # Test 1
     self.run_ucsc_main( track_params, output_params )
     self.wait()
     self.verify_dataset_correctness('DNAseHSS.dat')
     latest_hda = sa_session.query( galaxy.model.HistoryDatasetAssociation ) \
                            .order_by( desc( galaxy.model.HistoryDatasetAssociation.table.c.create_time ) ) \
                            .first()
     # Due to twill not being able to handle the permissions forms, we'll eliminate
     # DefaultHistoryPermissions prior to uploading a dataset so that the permission
     # form will not be displayed on ted edit attributes page.
     for dp in latest_hda.dataset.actions:
         sa_session.delete( dp )
         sa_session.flush()
     sa_session.refresh( latest_hda.dataset )
     self.edit_hda_attribute_info( str( latest_hda.id ), new_name="DNAse HS" )
     self.check_metadata_for_string( "DNAse HS" )
     track_params = dict(
         db="hg17",
         hgta_group="genes",
         hgta_table="knownGene",
         hgta_track="knownGene",
         hgta_regionType="range",
         position="chr22",
         hgta_outputType="bed",
         sendToGalaxy="1"
     )
     output_params = dict(
         fbQual="whole",
     )
     # Test 2
     self.run_ucsc_main( track_params, output_params )
     self.wait()
     self.verify_dataset_correctness('hg17chr22KnownGenes.dat')
     latest_hda = sa_session.query( galaxy.model.HistoryDatasetAssociation ) \
                            .order_by( desc( galaxy.model.HistoryDatasetAssociation.table.c.create_time ) ) \
                            .first()
     for dp in latest_hda.dataset.actions:
         sa_session.delete( dp )
         sa_session.flush()
     sa_session.refresh( latest_hda.dataset )
     self.edit_hda_attribute_info( str( latest_hda.id ), new_name="Genes" )
     self.check_metadata_for_string( "Genes" )
     # Test 3
     self.run_tool( 'get_flanks1', input="2", region="whole", direction="Upstream", offset="0", size="500" )
     self.wait()
     self.verify_dataset_correctness( 'knownGeneUpstream500Flanks.dat' )
     latest_hda = sa_session.query( galaxy.model.HistoryDatasetAssociation ) \
                            .order_by( desc( galaxy.model.HistoryDatasetAssociation.table.c.create_time ) ) \
                            .first()
     for dp in latest_hda.dataset.actions:
         sa_session.delete( dp )
         sa_session.flush()
     sa_session.refresh( latest_hda.dataset )
     self.edit_hda_attribute_info( str( latest_hda.id ), new_name="Flanks" )
     self.check_metadata_for_string( "Flanks" )
     # Test 4
     self.run_tool( 'gops_join_1', input1="3", input2="1", min="1", fill="none"  )
     self.wait()
     # We cannot verify this dataset, because this tool spits out data in a non-deterministic order
     #self.verify_dataset_correctness( 'joinFlanksDNAse.dat' )
     # Test 5
     self.run_tool( 'Filter1', input="4", cond="c17==1000"  )
     self.wait()
     self.verify_dataset_correctness( 'filteredJoinedFlanksDNAse.dat' )
     self.delete_history( self.security.encode_id( history1.id ) )
     self.logout()