473,386 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Renumbering

Hi;

I would like to renumber, starting from 1, column 6 (i.e, 428 become
1, 429 becomes 2, etc for a very long list)

ATOM 3424 N LEU B 428 143.814 87.271 77.726 1.00115.20 2SG3426
ATOM 3425 CA LEU B 428 142.918 87.524 78.875 1.00115.20 2SG3427
ATOM 3426 CB LEU B 428 141.559 88.057 78.392 1.00115.20 2SG3428
ATOM 3427 CG LEU B 428 140.577 88.341 79.544 1.00115.20 2SG3429
ATOM 3428 CD1 LEU B 428 141.102 89.464 80.454 1.00115.20 2SG3430
ATOM 3429 CD2 LEU B 428 139.159 88.615 79.017 1.00115.20 2SG3431
ATOM 3430 C LEU B 428 142.680 86.253 79.615 1.00115.20 2SG3432
ATOM 3431 O LEU B 428 142.725 86.226 80.842 1.00115.20 2SG3433
ATOM 3432 N SER B 429 142.432 85.155 78.878 1.00134.86 2SG3434
ATOM 3433 CA SER B 429 142.175 83.908 79.534 1.00134.86 2SG3435
ATOM 3434 CB SER B 429 141.666 82.805 78.590 1.00134.86 2SG3436
ATOM 3435 OG SER B 429 140.392 83.155 78.069 1.00134.86 2SG3437
ATOM 3436 C SER B 429 143.451 83.432 80.141 1.00134.86 2SG3438
ATOM 3437 O SER B 429 144.543 83.756 79.676 1.00134.86 2SG3439

Distinctive character is column 5, i.e., it must be set that only
lines containing "B" should be renumbered.

As you can see, the number of lines for a particular value in column 6
changes from situation to situation, and may even be different for the
same name in column 4. For example, LEU can have a different number of
lines depending on the position of this amino acid (leucine).

I was unable to set non-proportional characters, sorry.

Thanks for help

francesco pietra
Sep 2 '08 #1
4 1577
On Sep 3, 6:57 am, "Francesco Pietra" <chiendar...@gmail.comwrote:
Hi;

I would like to renumber, starting from 1, column 6 (i.e, 428 become
1, 429 becomes 2, etc for a very long list)

ATOM 3424 N LEU B 428 143.814 87.271 77.726 1.00115.20 2SG3426
[snip]
ATOM 3437 O SER B 429 144.543 83.756 79.676 1.00134.86 2SG3439

Distinctive character is column 5, i.e., it must be set that only
lines containing "B" should be renumbered.

As you can see, the number of lines for a particular value in column 6
changes from situation to situation, and may even be different for the
same name in column 4. For example, LEU can have a different number of
lines depending on the position of this amino acid (leucine).
The above paragraph is extremely unclear.
>
Thanks for help
You haven't asked a question, and haven't given any background. What
is your experience with Python? Any other language? Are you expecting
somebody to write a script for you, or just give you a few hints? Is
this homework? Have you put any effort into trying to write a script
yourself? Etc etc etc
Sep 2 '08 #2
Francesco Pietra, few notes:
- In Python and C item numbering generally starts from 0, so you talk
about column 0, 1, etc.
- You can also use the Italian Python newsgroup if know Italian.
- The number of lines with a particular number doesn't seem important
to solve your problem.
- You don't need to try to set non-proportional characters on usenet.

This is a first try at a solution, you can tell us if it's correct:

data = """\
ATOM 3424 N LEU B 428 143.814 87.271 77.726
1.00115.20 2SG3426
ATOM 3425 CA LEU B 428 142.918 87.524 78.875
1.00115.20 2SG3427
ATOM 3426 CB LEU B 428 141.559 88.057 78.392
1.00115.20 2SG3428
ATOM 3427 CG LEU B 428 140.577 88.341 79.544
1.00115.20 2SG3429
ATOM 3428 CD1 LEU B 428 141.102 89.464 80.454
1.00115.20 2SG3430
ATOM 3429 CD2 LEU B 428 139.159 88.615 79.017
1.00115.20 2SG3431
ATOM 3430 C LEU B 428 142.680 86.253 79.615
1.00115.20 2SG3432
ATOM 3431 O LEU B 428 142.725 86.226 80.842
1.00115.20 2SG3433
ATOM 3432 N SER B 429 142.432 85.155 78.878
1.00134.86 2SG3434
ATOM 3433 CA SER B 429 142.175 83.908 79.534
1.00134.86 2SG3435
ATOM 3434 CB SER B 429 141.666 82.805 78.590
1.00134.86 2SG3436
ATOM 3435 OG SER B 429 140.392 83.155 78.069
1.00134.86 2SG3437
ATOM 3436 C SER B 429 143.451 83.432 80.141
1.00134.86 2SG3438
ATOM 3437 O SER B 429 144.543 83.756 79.676
1.00134.86 2SG3439"""

lines = (line.split() for line in data.splitlines())
for parts in lines:
if parts[4] == "B":
parts[5] = str( int(parts[5]) - 427)
parts[2] = parts[2].ljust(4)
print " ".join(parts)

It prints:

ATOM 3424 N LEU B 1 143.814 87.271 77.726 1.00115.20
2SG3426
ATOM 3425 CA LEU B 1 142.918 87.524 78.875 1.00115.20
2SG3427
ATOM 3426 CB LEU B 1 141.559 88.057 78.392 1.00115.20
2SG3428
ATOM 3427 CG LEU B 1 140.577 88.341 79.544 1.00115.20
2SG3429
ATOM 3428 CD1 LEU B 1 141.102 89.464 80.454 1.00115.20
2SG3430
ATOM 3429 CD2 LEU B 1 139.159 88.615 79.017 1.00115.20
2SG3431
ATOM 3430 C LEU B 1 142.680 86.253 79.615 1.00115.20
2SG3432
ATOM 3431 O LEU B 1 142.725 86.226 80.842 1.00115.20
2SG3433
ATOM 3432 N SER B 2 142.432 85.155 78.878 1.00134.86
2SG3434
ATOM 3433 CA SER B 2 142.175 83.908 79.534 1.00134.86
2SG3435
ATOM 3434 CB SER B 2 141.666 82.805 78.590 1.00134.86
2SG3436
ATOM 3435 OG SER B 2 140.392 83.155 78.069 1.00134.86
2SG3437
ATOM 3436 C SER B 2 143.451 83.432 80.141 1.00134.86
2SG3438
ATOM 3437 O SER B 2 144.543 83.756 79.676 1.00134.86
2SG3439

Your data is probably in a file, so you have to change the first line
of the code:

lines = (line.split() for line in open("namefile.txt"))

If your output file must to hard-coded columns (and generally those
files don't need such property) then you have to make that code of
mine more complex...

Bye,
bearophile
Sep 2 '08 #3
John Machin:
Is this homework? Have you put any effort into trying to write a script
yourself? Etc etc etc
You are right, I am sorry -.-

Bye,
bearophile
Sep 2 '08 #4
Francesco Pietra <ch*********@gmail.comwrote:
ATOM 3424 N LEU B 428 143.814 87.271 77.726 1.00115.20 2SG3426
ATOM 3425 CA LEU B 428 142.918 87.524 78.875 1.00115.20 2SG3427
[...]
As you can see, the number of lines for a particular value in column 6
changes from situation to situation, and may even be different for the
same name in column 4. For example, LEU can have a different number of
lines depending on the position of this amino acid (leucine).
Others have alreade given good hints but I would like to add a bit of
advice.

The data you show appears to be a PDB protein structure file. It is
important to realize that these are fixed-width files and columns can be
empty so splitting on tab or whithespace will often fail. It is also
important to know that the residue numbering (cols 23-26) is not
necessarily contiguous and is not even unique without taking into
account the 'insertion code' in column 27 which happens to be empty in
your example. I would recommend to use a full-blown PDB parser to read
the data and then iterate over the residues and do whatever you would
like to acomplish that way. Biopython has such a parser:

www.biopython.org

cu
Philipp

--
Dr. Philipp Pagel
Lehrstuhl f. Genomorientierte Bioinformatik
Technische Universität München
http://mips.gsf.de/staff/pagel
Sep 3 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: amywolfie | last post by:
This is an interesting one..... I have a field on FORM!FORMDATA (no, I did not name this) called KEY. There can be multiple KEYS per record (equates to FIELDS on a given DOCUMENT). The...
2
by: Chris Potter | last post by:
I have a problem. I am constructing a database of eople's names and addresses for business purposes. This requires all of the people to be numbered eg: 1,2,3,4,5,6,7,8,9,10 But the problem lies...
20
by: Prakash | last post by:
Hi ! I have a field "sub_tran_no" in my form in continuous view. When the user presses a button "Re-Number", I'd like to: 1) Save the current record pointer position 2) Save the current...
2
by: Pekka | last post by:
Could somebody say why the piece of code below does not work? My purpose is to renumber keys in a SortedList (after removal of an item) so that the keys would always contain an unbroken sequence of...
0
by: Johnny | last post by:
I'm looking for an algorithm that will manage the line numbers within a grid. The user should be able to add rows, delete rows, and insert rows anywhere in the grid and the line numbers should be...
10
by: jpatchak | last post by:
Hi, I have a form with a delete button. Each record is stored with a list name (e.g. "October" or "November"). Each record within a list name is consecutively numbered from 1 to n. This number...
2
by: tehgreatmg | last post by:
Ok I have two tables both with an ID field, whenever a record is deleted these need to be renumbered to keep corresponding data. Here is the code I am using to do this: Dim db As DAO.Database ...
21
by: no1zson | last post by:
I do not even know how to correctly ask this question. I have an item field in the code I am about to post. Simple intger meant to be an item number for a cd. The user enters this number. Over the...
0
by: Terry Reedy | last post by:
Francesco Pietra wrote: Hi, Let L be a data line So you want to subtract 427 from each entry in L if L ==
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.