Author: bugman Date: Fri Nov 23 18:15:48 2007 New Revision: 3871 URL: http://svn.gna.org/viewcvs/relax?rev=3871&view=rev Log: Merged revisions 3863-3869 via svnmerge from svn+ssh://bugman@xxxxxxxxxxx/svn/relax/1.3 ........ r3863 | bugman | 2007-11-23 17:08:49 +0100 (Fri, 23 Nov 2007) | 6 lines Split the write() function in half. The two new functions are write() and write_body(). The write() function calls write_body(). This write_body() is designed to be used by the display() function. ........ r3864 | bugman | 2007-11-23 17:11:39 +0100 (Fri, 23 Nov 2007) | 3 lines Implemented the display() function. ........ r3865 | bugman | 2007-11-23 17:13:41 +0100 (Fri, 23 Nov 2007) | 3 lines Implemented all the arg unit tests for the sequence.display() user function. ........ r3866 | bugman | 2007-11-23 17:15:00 +0100 (Fri, 23 Nov 2007) | 3 lines Bug fix for all the arg unit tests for the sequence.display() user function. ........ r3867 | bugman | 2007-11-23 17:17:10 +0100 (Fri, 23 Nov 2007) | 3 lines Implemented a unit test to test the display of an amino acid sequence. ........ r3868 | bugman | 2007-11-23 17:27:40 +0100 (Fri, 23 Nov 2007) | 3 lines Implemented the sequence.display() user function. ........ r3869 | bugman | 2007-11-23 17:39:55 +0100 (Fri, 23 Nov 2007) | 3 lines A few improvements to the unit test for the display of an amino acid sequence. ........ Modified: branches/N_state_model/ (props changed) branches/N_state_model/generic_fns/sequence.py branches/N_state_model/prompt/sequence.py branches/N_state_model/test_suite/unit_tests/_prompt/test_sequence.py branches/N_state_model/test_suite/unit_tests/sequence_testing_base.py Propchange: branches/N_state_model/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Fri Nov 23 18:15:48 2007 @@ -1,1 +1,1 @@ -/1.3:1-3692,3695,3697-3713,3715-3719,3721-3728,3730-3731,3733-3755,3757-3807,3809-3833,3836-3838,3840-3862 +/1.3:1-3692,3695,3697-3713,3715-3719,3721-3728,3730-3731,3733-3755,3757-3807,3809-3833,3836-3838,3840-3869 Modified: branches/N_state_model/generic_fns/sequence.py URL: http://svn.gna.org/viewcvs/relax/branches/N_state_model/generic_fns/sequence.py?rev=3871&r1=3870&r2=3871&view=diff ============================================================================== --- branches/N_state_model/generic_fns/sequence.py (original) +++ branches/N_state_model/generic_fns/sequence.py Fri Nov 23 18:15:48 2007 @@ -25,22 +25,36 @@ from relax_errors import RelaxError, RelaxFileEmptyError, RelaxNoPdbChainError, RelaxNoPipeError, RelaxNoSequenceError, RelaxSequenceError from relax_io import extract_data, open_write_file, strip from generic_fns.selection import count_spins, spin_loop - - - -def display(): - """Function for displaying the molecule, residue, and spin sequence.""" +from sys import stdout + + + +def display(mol_name_col=None, res_num_col=None, res_name_col=None, spin_num_col=None, spin_name_col=None, sep=None): + """Function for displaying the molecule, residue, and/or spin sequence data. + + This calls the write_body() function to do most of the work. + + + @param mol_name_col: The column to contain the molecule name information. + @type mol_name_col: int or None + @param res_name_col: The column to contain the residue name information. + @type res_name_col: int or None + @param res_num_col: The column to contain the residue number information. + @type res_num_col: int or None + @param spin_name_col: The column to contain the spin name information. + @type spin_name_col: int or None + @param spin_num_col: The column to contain the spin number information. + @type spin_num_col: int or None + @param sep: The column seperator which, if None, defaults to whitespace. + @type sep: str or None + """ # Test if the sequence data is loaded. if not count_spins(): raise RelaxNoSequenceError - # Print a header. - print "%-8s%-8s%-8s%-8s%-8s%-10s" % ("Mol name", "Res num", "Res name", "Spin num", "Spin name", "Selected") - - # Print the data. - for spin, mol_name, res_num, res_name in spin_loop(full_info=True): - print "%-8s%-8i%-8s%-8i%-8s%-10i" % (mol_name, res_num, res_name, spin.num, spin.name, spin.select) + # Write the data. + write_body(file=stdout, mol_name_col=mol_name_col, res_num_col=res_num_col, res_name_col=res_name_col, spin_num_col=spin_num_col, spin_name_col=spin_name_col, sep=sep) def load_PDB_sequence(): @@ -275,6 +289,9 @@ def write(file=None, dir=None, mol_name_col=None, res_num_col=None, res_name_col=None, spin_num_col=None, spin_name_col=None, sep=None, force=0): """Function for writing molecule, residue, and/or sequence data. + This calls the write_body() function to do most of the work. + + @param file: The name of the file to write the data to. @type file: str @param dir: The directory to contain the file (defaults to the current directory if @@ -303,36 +320,60 @@ # Open the file for writing. seq_file = open_write_file(file, dir, force) + # Write the data. + write_body(file=seq_file, mol_name_col=mol_name_col, res_num_col=res_num_col, res_name_col=res_name_col, spin_num_col=spin_num_col, spin_name_col=spin_name_col, sep=sep) + + # Close the results file. + seq_file.close() + + + +def write_body(file=None, mol_name_col=None, res_num_col=None, res_name_col=None, spin_num_col=None, spin_name_col=None, sep=None): + """Function for writing to the given file object the molecule, residue, and/or sequence data. + + @param file: The file object to write the data to. + @type file: file object + @param mol_name_col: The column to contain the molecule name information. + @type mol_name_col: int or None + @param res_name_col: The column to contain the residue name information. + @type res_name_col: int or None + @param res_num_col: The column to contain the residue number information. + @type res_num_col: int or None + @param spin_name_col: The column to contain the spin name information. + @type spin_name_col: int or None + @param spin_num_col: The column to contain the spin number information. + @type spin_num_col: int or None + @param sep: The column seperator which, if None, defaults to whitespace. + @type sep: str or None + """ + # No special seperator character. if sep == None: sep = '' # Write a header. if mol_name_col != None: - seq_file.write("%-10s " % ("Mol_name"+sep)) + file.write("%-10s " % ("Mol_name"+sep)) if res_num_col != None: - seq_file.write("%-10s " % ("Res_num"+sep)) + file.write("%-10s " % ("Res_num"+sep)) if res_name_col != None: - seq_file.write("%-10s " % ("Res_name"+sep)) + file.write("%-10s " % ("Res_name"+sep)) if spin_num_col != None: - seq_file.write("%-10s " % ("Spin_num"+sep)) + file.write("%-10s " % ("Spin_num"+sep)) if spin_name_col != None: - seq_file.write("%-10s " % ("Spin_name"+sep)) - seq_file.write('\n') + file.write("%-10s " % ("Spin_name"+sep)) + file.write('\n') # Loop over the spins. for spin, mol_name, res_num, res_name in spin_loop(full_info=True): if mol_name_col != None: - seq_file.write("%-10s " % (str(mol_name)+sep)) + file.write("%-10s " % (str(mol_name)+sep)) if res_num_col != None: - seq_file.write("%-10s " % (str(res_num)+sep)) + file.write("%-10s " % (str(res_num)+sep)) if res_name_col != None: - seq_file.write("%-10s " % (str(res_name)+sep)) + file.write("%-10s " % (str(res_name)+sep)) if spin_num_col != None: - seq_file.write("%-10s " % (str(spin.num)+sep)) + file.write("%-10s " % (str(spin.num)+sep)) if spin_name_col != None: - seq_file.write("%-10s " % (str(spin.name)+sep)) - seq_file.write('\n') - - # Close the results file. - seq_file.close() + file.write("%-10s " % (str(spin.name)+sep)) + file.write('\n') Modified: branches/N_state_model/prompt/sequence.py URL: http://svn.gna.org/viewcvs/relax/branches/N_state_model/prompt/sequence.py?rev=3871&r1=3870&r2=3871&view=diff ============================================================================== --- branches/N_state_model/prompt/sequence.py (original) +++ branches/N_state_model/prompt/sequence.py Fri Nov 23 18:15:48 2007 @@ -42,27 +42,63 @@ self.__relax__ = relax - def display(self, run=None): - """Function for displaying the sequence. + def display(self, mol_name_col=0, res_num_col=1, res_name_col=2, spin_num_col=3, spin_name_col=4, sep=None): + """Function for displaying sequences of molecules, residues, and/or spins. Keyword Arguments ~~~~~~~~~~~~~~~~~ - run: The name of the run. + mol_name_col: The molecule name column (the default is 0, i.e. the first column). + + res_num_col: The residue number column (the default is 1, i.e. the second column). + + res_name_col: The residue name column (the default is 2, i.e. the third column). + + spin_num_col: The spin number column (the default is 3, i.e. the forth column). + + spin_name_col: The spin name column (the default is 4, i.e. the fifth column). + + sep: The column separator (the default is white space). + """ # Function intro text. if self.__relax__.interpreter.intro: text = sys.ps3 + "sequence.display(" - text = text + "run=" + `run` + ")" + text = text + "mol_name_col=" + `mol_name_col` + text = text + ", res_num_col=" + `res_num_col` + text = text + ", res_name_col=" + `res_name_col` + text = text + ", spin_num_col=" + `spin_num_col` + text = text + ", spin_name_col=" + `spin_name_col` + text = text + ", sep=" + `sep` + ")" print text - # The run argument. - if type(run) != str: - raise RelaxStrError, ('run', run) + # Molecule name column. + if mol_name_col != None and type(mol_name_col) != int: + raise RelaxNoneIntError, ('molecule name column', mol_name_col) + + # Residue number column. + if res_name_col != None and type(res_num_col) != int: + raise RelaxNoneIntError, ('residue number column', res_num_col) + + # Residue name column. + if res_name_col != None and type(res_name_col) != int: + raise RelaxNoneIntError, ('residue name column', res_name_col) + + # Spin number column. + if spin_num_col != None and type(spin_num_col) != int: + raise RelaxNoneIntError, ('spin number column', spin_num_col) + + # Spin name column. + if spin_name_col != None and type(spin_name_col) != int: + raise RelaxNoneIntError, ('spin name column', spin_name_col) + + # Column separator. + if sep != None and type(sep) != str: + raise RelaxNoneStrError, ('column separator', sep) # Execute the functional code. - self.__relax__.generic.sequence.display(run=run) + sequence.display(mol_name_col=mol_name_col, res_num_col=res_num_col, res_name_col=res_name_col, spin_num_col=spin_num_col, spin_name_col=spin_name_col, sep=sep) def read(self, file=None, dir=None, mol_name_col=None, res_num_col=0, res_name_col=1, spin_num_col=None, spin_name_col=None, sep=None): Modified: branches/N_state_model/test_suite/unit_tests/_prompt/test_sequence.py URL: http://svn.gna.org/viewcvs/relax/branches/N_state_model/test_suite/unit_tests/_prompt/test_sequence.py?rev=3871&r1=3870&r2=3871&view=diff ============================================================================== --- branches/N_state_model/test_suite/unit_tests/_prompt/test_sequence.py (original) +++ branches/N_state_model/test_suite/unit_tests/_prompt/test_sequence.py Fri Nov 23 18:15:48 2007 @@ -52,6 +52,84 @@ sequence_fns = Sequence(relax) + def test_display_argfail_mol_name_col(self): + """The proper failure of the sequence.display() user function for the mol_name_col argument.""" + + # Loop over the data types. + for data in DATA_TYPES: + # Catch the None, int, and bin arguments, and skip them. + if data[0] == 'None' or data[0] == 'int' or data[0] == 'bin': + continue + + # The argument test. + self.assertRaises(RelaxNoneIntError, self.sequence_fns.display, mol_name_col=data[1]) + + + def test_display_argfail_res_num_col(self): + """The proper failure of the sequence.display() user function for the res_num_col argument.""" + + # Loop over the data types. + for data in DATA_TYPES: + # Catch the None, int, and bin arguments, and skip them. + if data[0] == 'None' or data[0] == 'int' or data[0] == 'bin': + continue + + # The argument test. + self.assertRaises(RelaxNoneIntError, self.sequence_fns.display, res_num_col=data[1]) + + + def test_display_argfail_res_name_col(self): + """The proper failure of the sequence.display() user function for the res_name_col argument.""" + + # Loop over the data types. + for data in DATA_TYPES: + # Catch the None, int, and bin arguments, and skip them. + if data[0] == 'None' or data[0] == 'int' or data[0] == 'bin': + continue + + # The argument test. + self.assertRaises(RelaxNoneIntError, self.sequence_fns.display, res_name_col=data[1]) + + + def test_display_argfail_spin_num_col(self): + """The proper failure of the sequence.display() user function for the spin_num_col argument.""" + + # Loop over the data types. + for data in DATA_TYPES: + # Catch the None, int, and bin arguments, and skip them. + if data[0] == 'None' or data[0] == 'int' or data[0] == 'bin': + continue + + # The argument test. + self.assertRaises(RelaxNoneIntError, self.sequence_fns.display, spin_num_col=data[1]) + + + def test_display_argfail_spin_name_col(self): + """The proper failure of the sequence.display() user function for the spin_name_col argument.""" + + # Loop over the data types. + for data in DATA_TYPES: + # Catch the None, int, and bin arguments, and skip them. + if data[0] == 'None' or data[0] == 'int' or data[0] == 'bin': + continue + + # The argument test. + self.assertRaises(RelaxNoneIntError, self.sequence_fns.display, spin_name_col=data[1]) + + + def test_display_argfail_sep(self): + """The proper failure of the sequence.display() user function for the sep argument.""" + + # Loop over the data types. + for data in DATA_TYPES: + # Catch the None and str arguments, and skip them. + if data[0] == 'None' or data[0] == 'str': + continue + + # The argument test. + self.assertRaises(RelaxNoneStrError, self.sequence_fns.display, sep=data[1]) + + def test_read_argfail_file(self): """Test the proper failure of the sequence.read() user function for the file argument.""" Modified: branches/N_state_model/test_suite/unit_tests/sequence_testing_base.py URL: http://svn.gna.org/viewcvs/relax/branches/N_state_model/test_suite/unit_tests/sequence_testing_base.py?rev=3871&r1=3870&r2=3871&view=diff ============================================================================== --- branches/N_state_model/test_suite/unit_tests/sequence_testing_base.py (original) +++ branches/N_state_model/test_suite/unit_tests/sequence_testing_base.py Fri Nov 23 18:15:48 2007 @@ -63,6 +63,27 @@ remove(self.tmpfile) except OSError: pass + + + def test_display_protein_sequence(self): + """Test the display of an amino acid sequence. + + The functions tested are generic_fns.sequence.display() and prompt.sequence.display(). + """ + + # Alias the 'orig' relax data store. + cdp = relax_data_store['orig'] + + # Create a simple animo acid sequence. + cdp.mol[0].res[0].num = 1 + cdp.mol[0].res[0].name = 'GLY' + cdp.mol[0].res.add_item('PRO', 2) + cdp.mol[0].res.add_item('LEU', 3) + cdp.mol[0].res.add_item('GLY', 4) + cdp.mol[0].res.add_item('SER', 5) + + # Try displaying the residue sequence. + self.sequence_fns.display(mol_name_col=None, res_num_col=0, res_name_col=1, spin_num_col=None, spin_name_col=None) def test_read_protein_noe_data(self):