Fw: Re: Re: joining files
Note: Forwarded message attached -- Original Message -- From: mannu jhamannu_0...@rediffmail.com To: tuomas.vesteri...@iki.fi Subject: Re: Re: joining files---BeginMessage--- import os def merge_sources(sources): # sources is a list of tuples (source_name, source_data) data = [] keysets = [] for nme, sce in sources: lines = {} for line in sce.split(os.linesep): lst = line.split() lines[lst[0]] = (nme, lst) keysets.append(set(lines.keys())) data.append(lines) common_keys = keysets[0] for keys in keysets[1:]: common_keys = common_keys.intersection(keys) result = {} for key in common_keys: result[key] = dict(d[key] for d in data if key in d) return result if __name__ == __main__: # Your test files here are replaced by local strings print merge_sources([(file1, file1), (file2, file2), (file3, file3)]) print merge_sources([(input1, input1), (input2, input2)]) Test_results = ''' {'22': {'file3': ['22', 'C'], 'file2': ['22', '0'], 'file1': ['22', '110.1', '33', '331.5', '22.7', '5', '271.9' '17.2', '33.4']}} {'194': {'input2': ['194', 'C'], 'input1': ['194', '8.00', '121.23', '54.79', '4.12', '180.06']}, '175': {'input2': ['175', 'H', '176', 'H', '180', 'H'], 'input1': ['175', '8.42', '120.50', '55.31', '4.04', '180.33']}, '15': {'input2': ['15', 'H', '37', 'H', '95', 'T'], 'input1': ['15', '8.45', '119.04', '55.02', '4.08', '178.89']}, '187': {'input2': ['187', 'H', '190', 'T'], 'input1': ['187', '7.79', '122.27', '54.37', '4.26', '179.75']}} Dear Sir, I tried above program but with that it is showing error: nmru...@caf:~ python join1.py Traceback (most recent call last): File join1.py, line 24, in print merge_sources([(file1, file1), (file2, file2), (file3,file3)]) NameError: name 'file1' is not defined nmru...@caf:~ Add test data to the code as: file1 = '''22 110.1 33 331.5 22.7 5 271.9 17.2 33.4 4 55.1''' Thankyou very much sir it is working..Thankyou once again for your kind help. only one problem I am now facing i.e. when I tried to replace test data with filename 1.e. file1 = open(input11.txt) file2 = open(output22.txt) print merge_sources([(file1, file1), (file2, file2)]) then it is showing error ph08...@linux-af0n:~ python new.py Traceback (most recent call last): File new.py, line 25, in print merge_sources([(file1, file1), (file2, file2)]) File new.py, line 9, in merge_sources for line in sce.split(os.linesep): AttributeError: 'file' object has no attribute 'split' ph08...@linux-af0n:~ where my input11.txt is: '''187 7.79 122.27 54.37 4.26 179.75 194 8.00 121.23 54.79 4.12 180.06 15 8.45 119.04 55.02 4.08 178.89 176 7.78 118.68 54.57 4.20 181.06 180 7.50 119.21 53.93 179.80 190 7.58 120.44 54.62 4.25 180.02 152 8.39 120.63 55.10 4.15 179.10 154 7.79 119.62 54.47 4.22 180.46 175 8.42 120.50 55.31 4.04 180.33''' and output22.txt is: '''15 H 37 H 95 T 124 H 130 H 152 H 154 H 158 H 164 H 175 H 176 H 180 H 187 H 190 T 194 C''' since my files are very big hence i want to give filename as input. ---End Message--- -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: joining files
On Mon, 17 May 2010 23:57:18 +0530 wrote Try: file = open(input11.txt) file1 = file.read() # file1 is a string file.close() or file1 = open(input11.txt) # file1 is an open file object and replace lines: for line in sce.split(os.linesep): lst = line.split() lines[lst[0]] = (nme, lst) with lines: for line in sce: lst = line.split() lines[lst[0]] = (nme, lst) sce.close() Thankyou very much sir it has worked. Thankyou once again. -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: joining files
On Sun, 16 May 2010 23:51:10 +0530 wrote On 05/16/2010 05:04 PM, Dave Angel wrote: (You forgot to include the python-list in your response. So it only went to me. Normally, you just do reply-all to the message) mannu jha wrote: On Sun, 16 May 2010 13:52:31 +0530 wrote mannu jha wrote: Hi, I have few files like this: file1: 22 110.1 33 331.5 22.7 5 271.9 17.2 33.4 4 55.1 file1 has total 4 column but some of them are missing in few row. file2: 5 H 22 0 file3: 4 T 5 B 22 C 121 S in all these files first column is the main source of matching their entries. So What I want in the output is only those entries which is coming in all three files. output required: 5 271.9 17.2 33.4 5 H 5 T 22 110.1 22 0 22 C I am trying with this : from collections import defaultdict def merge(sources): blanks = [blank for items, blank, keyfunc in sources] d = defaultdict(lambda: blanks[:]) for index, (items, blank, keyfunc) in enumerate(sources): for item in items: d[keyfunc(item)][index] = item for key in sorted(d): yield d[key] if __name__ == __main__: a = open(input1.txt) c = open(input2.txt) def key(line): return line[:2] def source(stream, blank=, key=key): return (line.strip() for line in stream), blank, key for m in merge([source(x) for x in [a,c]]): print |.join(c.ljust(10) for c in m) but with input1.txt: 187 7.79 122.27 54.37 4.26 179.75 194 8.00 121.23 54.79 4.12 180.06 15 8.45 119.04 55.02 4.08 178.89 176 7.78 118.68 54.57 4.20 181.06 180 7.50 119.21 53.93 179.80 190 7.58 120.44 54.62 4.25 180.02 152 8.39 120.63 55.10 4.15 179.10 154 7.79 119.62 54.47 4.22 180.46 175 8.42 120.50 55.31 4.04 180.33 and input2.txt: 15 H 37 H 95 T 124 H 130 H 152 H 154 H 158 H 164 H 175 H 176 H 180 H 187 H 190 T 194 C 196 H 207 H 210 H 232 H it is giving output as: | |124 H |130 H 154 7.79 119.62 54.47 4.22 180.46|158 H |164 H 175 8.42 120.50 55.31 4.04 180.33|176 H 180 7.50 119.21 53.93 179.80|187 H 190 7.58 120.44 54.62 4.25 180.02|196 H |207 H |210 H |232 H |37 H |95 T so it not matching it properly, can anyone please suggest where I am doing mistake. import os def merge_sources(sources): # sources is a list of tuples (source_name, source_data) data = [] keysets = [] for nme, sce in sources: lines = {} for line in sce.split(os.linesep): lst = line.split() lines[lst[0]] = (nme, lst) keysets.append(set(lines.keys())) data.append(lines) common_keys = keysets[0] for keys in keysets[1:]: common_keys = common_keys.intersection(keys) result = {} for key in common_keys: result[key] = dict(d[key] for d in data if key in d) return result if __name__ == __main__: # Your test files here are replaced by local strings print merge_sources([(file1, file1), (file2, file2), (file3, file3)]) print merge_sources([(input1, input1), (input2, input2)]) Test_results = ''' {'22': {'file3': ['22', 'C'], 'file2': ['22', '0'], 'file1': ['22', '110.1', '33', '331.5', '22.7', '5', '271.9', '17.2', '33.4']}} {'194': {'input2': ['194', 'C'], 'input1': ['194', '8.00', '121.23', '54.79', '4.12', '180.06']}, '175': {'input2': ['175', 'H', '176', 'H', '180', 'H'], 'input1': ['175', '8.42', '120.50', '55.31', '4.04', '180.33']}, '15': {'input2': ['15', 'H', '37', 'H', '95', 'T'], 'input1': ['15', '8.45', '119.04', '55.02', '4.08', '178.89']}, '187': {'input2': ['187', 'H', '190', 'T'], 'input1': ['187', '7.79', '122.27', '54.37', '4.26', '179.75']}} Dear Sir, I tried above program but with that it is showing error: nmru...@caf:~ python join1.py Traceback (most recent call last): File join1.py, line 24, in print merge_sources([(file1, file1), (file2, file2), (file3, NameError: name 'file1' is not defined nmru...@caf:~ -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Fw: Re: Re: Re: joining files
Note: Forwarded message attached -- Original Message -- From: mannu jhamannu_0...@rediffmail.com To: mannu_0...@rediffmail.com Subject: Re: Re: Re: joining files---BeginMessage--- On Sun, 16 May 2010 23:51:10 +0530 wrote On 05/16/2010 05:04 PM, Dave Angel wrote: (You forgot to include the python-list in your response. So it only went to me. Normally, you just do reply-all to the message) mannu jha wrote: On Sun, 16 May 2010 13:52:31 +0530 wrote mannu jha wrote: Hi, I have few files like this: file1: 22 110.1 33 331.5 22.7 5 271.9 17.2 33.4 4 55.1 file1 has total 4 column but some of them are missing in few row. file2: 5 H 22 0 file3: 4 T 5 B 22 C 121 S in all these files first column is the main source of matching their entries. So What I want in the output is only those entries which is coming in all three files. output required: 5 271.9 17.2 33.4 5 H 5 T 22 110.1 22 0 22 C I am trying with this : from collections import defaultdict def merge(sources): blanks = [blank for items, blank, keyfunc in sources] d = defaultdict(lambda: blanks[:]) for index, (items, blank, keyfunc) in enumerate(sources): for item in items: d[keyfunc(item)][index] = item for key in sorted(d): yield d[key] if __name__ == __main__: a = open(input1.txt) c = open(input2.txt) def key(line): return line[:2] def source(stream, blank=, key=key): return (line.strip() for line in stream), blank, key for m in merge([source(x) for x in [a,c]]): print |.join(c.ljust(10) for c in m) but with input1.txt: 187 7.79 122.27 54.37 4.26 179.75 194 8.00 121.23 54.79 4.12 180.06 15 8.45 119.04 55.02 4.08 178.89 176 7.78 118.68 54.57 4.20 181.06 180 7.50 119.21 53.93 179.80 190 7.58 120.44 54.62 4.25 180.02 152 8.39 120.63 55.10 4.15 179.10 154 7.79 119.62 54.47 4.22 180.46 175 8.42 120.50 55.31 4.04 180.33 and input2.txt: 15 H 37 H 95 T 124 H 130 H 152 H 154 H 158 H 164 H 175 H 176 H 180 H 187 H 190 T 194 C 196 H 207 H 210 H 232 H it is giving output as: | |124 H |130 H 154 7.79 119.62 54.47 4.22 180.46|158 H |164 H 175 8.42 120.50 55.31 4.04 180.33|176 H 180 7.50 119.21 53.93 179.80|187 H 190 7.58 120.44 54.62 4.25 180.02|196 H |207 H |210 H |232 H |37 H |95 T so it not matching it properly, can anyone please suggest where I am doing mistake. import os def merge_sources(sources): # sources is a list of tuples (source_name, source_data) data = [] keysets = [] for nme, sce in sources: lines = {} for line in sce.split(os.linesep): lst = line.split() lines[lst[0]] = (nme, lst) keysets.append(set(lines.keys())) data.append(lines) common_keys = keysets[0] for keys in keysets[1:]: common_keys = common_keys.intersection(keys) result = {} for key in common_keys: result[key] = dict(d[key] for d in data if key in d) return result if __name__ == __main__: # Your test files here are replaced by local strings print merge_sources([(file1, file1), (file2, file2), (file3, file3)]) print merge_sources([(input1, input1), (input2, input2)]) Test_results = ''' {'22': {'file3': ['22', 'C'], 'file2': ['22', '0'], 'file1': ['22', '110.1', '33', '331.5', '22.7', '5', '271.9', '17.2', '33.4']}} {'194': {'input2': ['194', 'C'], 'input1': ['194', '8.00', '121.23', '54.79', '4.12', '180.06']}, '175': {'input2': ['175', 'H', '176', 'H', '180', 'H'], 'input1': ['175', '8.42', '120.50', '55.31', '4.04', '180.33']}, '15': {'input2': ['15', 'H', '37', 'H', '95', 'T'], 'input1': ['15', '8.45', '119.04', '55.02', '4.08', '178.89']}, '187': {'input2': ['187', 'H', '190', 'T'], 'input1': ['187', '7.79', '122.27', '54.37', '4.26', '179.75']}} Dear Sir, I tried above program but with that it is showing error: nmru...@caf:~ python join1.py Traceback (most recent call last): File join1.py, line 24, in print merge_sources([(file1, file1), (file2, file2), (file3, NameError: name 'file1' is not defined nmru...@caf:~ I tried with this: import os def merge_sources(sources): # sources is a list of tuples (source_name, source_data) data = [] keysets = [] for nme, sce in sources: lines = {} for line in sce.split(os.linesep): lst = line.split() lines[lst[0]] = (nme, lst) keysets.append(set(lines.keys())) data.append(lines) common_keys = keysets[0] for keys in keysets[1:]: common_keys = common_keys.intersection(keys) result = {} for key in common_keys: result[key] = dict(d[key] for d in data if key in d) return result if __name__ == __main__: # Your test files here are replaced by local strings file1 = [22 110.1 33 331.5 22.7 5 271.9 17.2 33.4, 4 55.1] file2 = [5 H, 22 0] print merge_sources([(file1, file1), (file2, file2)]) but with this it is showing error: nmru...@caf:~ python join1.py Traceback (most recent call last): File join1.py, line 28, in print merge_sources([(file1, file1), (file2, file2)]) File join1.py, line 9, in merge_sources for line
joining files
Hi, I have few files like this: file1: 22 110.1 33 331.5 22.7 5 271.9 17.2 33.4 4 55.1 file1 has total 4 column but some of them are missing in few row. file2: 5 H 22 0 file3: 4 T 5 B 22 C 121 S in all these files first column is the main source of matching their entries. So What I want in the output is only those entries which is coming in all three files. output required: 5 271.9 17.2 33.4 5 H 5 T 22 110.1 22 0 22 C -- http://mail.python.org/mailman/listinfo/python-list
Fw: Re: Re: joining files
Note: Forwarded message attached -- Original Message -- From: mannu jhamannu_0...@rediffmail.com To: da...@ieee.org Subject: Re: Re: joining files---BeginMessage--- On Sun, 16 May 2010 13:52:31 +0530 wrote mannu jha wrote: Hi, I have few files like this: file1: 22 110.1 33 331.5 22.7 5 271.9 17.2 33.4 4 55.1 file1 has total 4 column but some of them are missing in few row. file2: 5 H 22 0 file3: 4 T 5 B 22 C 121 S in all these files first column is the main source of matching their entries. So What I want in the output is only those entries which is coming in all three files. output required: 5 271.9 17.2 33.4 5 H 5 T 22 110.1 22 0 22 C I am trying with this : from collections import defaultdict def merge(sources): blanks = [blank for items, blank, keyfunc in sources] d = defaultdict(lambda: blanks[:]) for index, (items, blank, keyfunc) in enumerate(sources): for item in items: d[keyfunc(item)][index] = item for key in sorted(d): yield d[key] if __name__ == __main__: a = open(input1.txt) c = open(input2.txt) def key(line): return line[:2] def source(stream, blank=, key=key): return (line.strip() for line in stream), blank, key for m in merge([source(x) for x in [a,c]]): print |.join(c.ljust(10) for c in m) but with input1.txt: 1877.79 122.27 54.37 4.26 179.75 1948.00 121.23 54.79 4.12 180.06 158.45 119.04 55.02 4.08 178.89 1767.78 118.68 54.57 4.20 181.06 1807.50 119.21 53.93 179.80 1907.58 120.44 54.62 4.25 180.02 1528.39 120.63 55.10 4.15 179.10 1547.79 119.62 54.47 4.22 180.46 1758.42 120.50 55.31 4.04 180.33 and input2.txt: 15 H 37 H 95 T 124 H 130 H 152 H 154 H 158 H 164 H 175 H 176 H 180 H 187 H 190 T 194 C 196 H 207 H 210 H 232 H it is giving output as: | |124 H |130 H 1547.79 119.62 54.47 4.22 180.46|158 H |164 H 1758.42 120.50 55.31 4.04 180.33|176 H 1807.50 119.21 53.93 179.80|187 H 1907.58 120.44 54.62 4.25 180.02|196 H |207 H |210 H |232 H |37 H |95 T so it not matching it properly, can anyone please suggest where I am doing mistake. ---End Message--- -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: joining two column
On Sat, 15 May 2010 00:14:05 +0530 wrote On 05/14/2010 12:55 PM, James Mills wrote: file1: a1 a2 a3 a4 a5 a6 a7 a8 file2: b1 b2 b3 b4 b5 b6 b7 b8 and I want to join them so the output should look like this: a1 a2 b1 b2 a3 a4 b3 b4 a5 a6 b5 b6 a7 a8 b7 b8 This is completely untested, but this should (tm) work: from itertools import chain input1 = open(input1.txt, r).readlines() input2 = open(input2.txt, r).readlines() open(output.txt, w).write(.join(chain(input1, input2))) I think you meant izip() instead of chain() ... the OP wanted to be able to join the two lines together, so I suspect it would look something like # OPTIONAL_DELIMITER = f1 = file(input1.txt) f2 = file(input2.txt) out = open(output.txt, 'w') for left, right in itertools.izip(f1, f2): out.write(left.rstrip('\r\n')) # out.write(OPTIONAL_DELIMITER) out.write(right) out.close() This only works if the two files are the same length, or (if they're of differing lengths) you want the shorter version. The itertools lib also includes an izip_longest() function with optional fill, as of Python2.6 which you could use instead if you need all the lines -tkc -- with this from itertools import chain # OPTIONAL_DELIMITER = f1 = file(input1.txt) f2 = file(input2.txt) out = open(output.txt, 'w') for left, right in itertools.izip(f1, f2): out.write(left.rstrip('\r\n')) # out.write(OPTIONAL_DELIMITER) out.write(right) out.close() it is showing error: ph08...@linux-af0n:~ python join.py Traceback (most recent call last): File join.py, line 6, in for left, right in itertools.izip(f1, f2): NameError: name 'itertools' is not defined ph08...@linux-af0n:~ -- http://mail.python.org/mailman/listinfo/python-list
joining two column
Hi, I have two different file file1: a1 a2 a3 a4 a5 a6 a7 a8 file2: b1 b2 b3 b4 b5 b6 b7 b8 and I want to join them so the output should look like this: a1 a2 b1 b2 a3 a4 b3 b4 a5 a6 b5 b6 a7 a8 b7 b8 how to do that? -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: column selection
On Fri, 07 May 2010 18:58:59 +0530 wrote mannu jha wrote: On Thu, 06 May 2010 18:54:59 +0530 wrote mannu jha wrote: I tried with this: for line in open('1.txt'): columns = line.split() print columns[0], columns[1] if not line: continue but it is showing error: nmru...@caf:~ python split.py 24 ALA Traceback (most recent call last): File split.py, line 3, in print columns[0], columns[1] IndexError: list index out of range nmru...@caf:~ Thanks, On Thu, 06 May 2010 15:44:07 +0530 wrote If your files have two blank lines between each useful line, you have to do something to avoid trying to print those items for the blank lines. Depending how sure you are about your formatting, you could either do a if not line: continue or a if columns 3: continue DaveA with this for line in open('8.txt'): columns = line.split() if columns python split.py 24 ALA Traceback (most recent call last): File split.py, line 4, in print columns[0], columns[1] IndexError: list index out of range nmru...@caf:~ (Don't top-post. It makes the message very confusing to someone else trying to follow it. Also, enable your mail program's quoting feature -- currently it's not adding the marks at the beginning of each line you quote.) If you're going to skip over blank lines, it'd be good to do it before trying to print from it. Move the test up by a line. DaveA You forgot to include the list in your reply. Use reply-all, it's much easier. No clue what that if columns... line is supposed to be. It should get a parse error. DaveA Thankyou very much sirThanks a lot. -- http://mail.python.org/mailman/listinfo/python-list
column selection
Hi, I have few files like this: 24 ALA helix (helix_alpha, helix2) 27 ALA helix (helix_alpha, helix2) 51 ALA helix (helix_alpha, helix4) 58 ALA helix (helix_alpha, helix5) 63 ALA helix (helix_alpha, helix5) now with this program: for line in open('1.txt'): columns = line.split() print columns[0], columns[2] I am trying to print only 1st and third column but it showing error like: mru...@caf:~ python split.py 24 helix Traceback (most recent call last): File split.py, line 3, in print columns[0], columns[2] IndexError: list index out of range nmru...@caf:~ how to rectify it. Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: column selection
I tried with this: for line in open('1.txt'): columns = line.split() print columns[0], columns[1] if not line: continue but it is showing error: nmru...@caf:~ python split.py 24 ALA Traceback (most recent call last): File split.py, line 3, in print columns[0], columns[1] IndexError: list index out of range nmru...@caf:~ Thanks, On Thu, 06 May 2010 15:44:07 +0530 wrote mannu jha wrote: Hi, I have few files like this: 24 ALA helix (helix_alpha, helix2) 27 ALA helix (helix_alpha, helix2) 51 ALA helix (helix_alpha, helix4) 58 ALA helix (helix_alpha, helix5) 63 ALA helix (helix_alpha, helix5) now with this program: for line in open('1.txt'): columns = line.split() print columns[0], columns[2] I am trying to print only 1st and third column but it showing error like: mru...@caf:~ python split.py 24 helix Traceback (most recent call last): File split.py, line 3, in print columns[0], columns[2] IndexError: list index out of range nmru...@caf:~ how to rectify it. Thanks, If your files have two blank lines between each useful line, you have to do something to avoid trying to print those items for the blank lines. Depending how sure you are about your formatting, you could either do a if not line: continue or a if columns 3: continue DaveA -- http://mail.python.org/mailman/listinfo/python-list
[no subject]
Dear all, I am trying my problem in this way: import re expr = re.compile(Helix Helix| Sheet Sheet| Turn Turn| Coil Coil) f = open(CalcSecondary4.txt) for line in f: if expr.search(line): print line but with this it is printing only those line in which helix, sheet, turn and coil are coming twice. Kindly suggest how should I modify it so that whatever secondary structure is coming more than or equal to two times it should write that as final secondary structure and if two seconday structure are coming two-two times in one line itself like: 4 ALA Helix Sheet Helix Sheet then it should write that as doubtful and rest it should write as error. Thanks, Dear all, I have a file like: 1 ALA Helix Sheet Helix Coil 2 ALA Coil Coil Coil Sheet 3 ALA Helix Sheet Coil Turn now what I want is that write a python program in which I will put the condition that in each line whatever secondary structure is coming more than or equal to two times it should write that as final secondary structure and if two seconday structure are coming two-two times in one line itself like: 4 ALA Helix Sheet Helix Sheet then it should write that as doubtful and rest it should write as error. Thanks,-- http://mail.python.org/mailman/listinfo/python-list
[no subject]
Dear all, I have a file like: 1 ALA Helix Sheet Helix Coil 2 ALA Coil Coil Coil Sheet 3 ALA Helix Sheet Coil Turn now what I want is that write a python program in which I will put the condition that in each line whatever secondary structure is coming more than or equal to two times it should write that as final secondary structure and if two seconday structure are coming two-two times in one line itself like: 4 ALA Helix Sheet Helix Sheet then it should write that as doubtful and rest it should write as error. Thanks, -- http://mail.python.org/mailman/listinfo/python-list
how to select column
Dear all, I am new in python, can anyone help me that how can I select two column out of 6 column from a file. For example if I have file like: a1 a2 a3 a4 a5 a6 b1 b2 b3 b4 b5 b6 c1 c2 c3 c4 c5 c6 d1 d2 d3 d4 d5 d6 and I want output like: a1 a4 b1 b4 c1 c4 d1 d4 then how to do Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: how to select column
Dear Sir, Thanks for your help..but yes my files are having column like: # RESIDUE AA STRUCTURE BP1 BP2 ACC N-H--OO--H-NN-H--O O--H-NTCO KAPPA ALPHA PHI PSIX-CA Y-CA Z-CA 12 A I 0 0 91 0, 0.038,-0.1 0, 0.0 5,-0.0 0.000 360.0 360.0 360.0 156.1 38.1 24.6 -5.0 23 A R - 0 0 86 1,-0.1 4,-1.838,-0.1 3,-1.0 -0.377 360.0-116.9 -66.2 144.2 35.1 25.2 -7.3 34 A P H 3 S+ 0 0 81 0, 0.0 4,-2.7 0, 0.0 5,-0.2 0.843 111.7 60.4 -55.3 -36.8 34.6 28.8 -8.2 and in the output I want just: 2 A I 3 A R - 4 A P H 3 S+ i.e. residue no., aa and seconday structure. Thanks On Mon, 26 Apr 2010 20:40:55 +0530 wrote mannu jha wrote: Dear all, I am new in python, can anyone help me that how can I select two column out of 6 column from a file. For example if I have file like: a1 a2 a3 a4 a5 a6 b1 b2 b3 b4 b5 b6 c1 c2 c3 c4 c5 c6 d1 d2 d3 d4 d5 d6 and I want output like: a1 a4 b1 b4 c1 c4 d1 d4 then how to do Thanks Do you know how to open a file, and how to read individual lines from it? If so, then you can split a line at the spaces into a list by using fields = line.split() Then print fields[0], fields[3] would do what you ask. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list