432,009 Members | 1,643 Online
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

# How to add multiple lists to a script to count number of residues

 P: 6 #!/usr/bin/python import os d={} path=os.getcwd() print path list_of_filenames=os.listdir(os.path.join(path, 'newfiles')) print list_of_filenames residue=[] for f in list_of_filenames: f1=open(os.path.join(path, 'newfiles', f)).readlines() d[f]=0 for line in f1: if line.startswith('ATOM'): res_number=line[22:26] if res_number not in residue and line[17:20]!='HOH': residue.append(res_number) d[f]+=1 else: continue else: continue print(len(residue)) print(d) Herewith I attach a txt file of my sample input. in that file column 1 represents ATOM or HETATM column 2 represents atom number column 3 represents atom type column 4 represents name of the residue column 5 represents the type of the chain column 6 represents residue number My question is how many residues are in this file? It's complicated to find it because of even atom number changes in every line, residue number stands as a constant. Because in one residue there are different atoms. Another thing is both in chain A and chain B, ALA is residue 542, but in chain A there is no 543rd residue, but in chain B there is 543rd residue. Therefore newly addition from chain B is only 543rd residue, otherwise values will be repeated. I want to count number of residues of the file except water (HOH) molecules ? So how can I count number of residues in this file? Mar 15 '17 #1