how to order a list of PDB files
2
0
Entering edit mode
9.2 years ago

Hi,

I am new in Python and I have a list of PDB files in a text file appearing like this:

3O8BA 2WHXA 3Q3YA 1D4M1 4F49A 1JQ6A 2FYQA 3W95A 2FMBA 2BBVA 4M0WA 1AT3A 2CXVA 2WV4A 4EKFA 2SNWA 4GUAA 1JEW2 3MMGA 4IZKA

I would like to create a new file with the PDB files ordered by PDBID, something like this 1AT3A 1D4M1 1JEW2 1JQ6A...

I had started reading the text in the file and using the split function in order to create a temporary list of PDBs to be ordered..but then I got stuck on that and I do not how to order them and proceed.

Any suggestion would be really appreciated.

Thank you in advance,
Silvia

Python • 2.0k views
ADD COMMENT
0
Entering edit mode

You mean you need to sort a row or a column?

ADD REPLY
0
Entering edit mode

Yes in row. I mean that I want to re-write the file with the PDBID ordered one after the other, sorted by crescent order of the first number of the PDBID and by alphabet order of the letter following the number in case the number is the same ..I mean that I want something like this:1AT3A 1D4M1 2BBVA 2CXVA.

I hope that this is clearer

Silvia

ADD REPLY
0
Entering edit mode
9.2 years ago
Phil S. ▴ 700

If it does not need to be python and might be bash you can just go with:

cat pdb_files.txt | sort

which sorts this:

3O8BA,2WHXA;3Q3YA;1D4M1;4F49A;1JQ6A;2FYQA;3W95A;2FMBA;2BBVA;4M0WA;1AT3A;2CXVA;2WV4A;4EKFA;2SNWA;4GUAA;1JEW2;3MMGA;4IZKA

into this:

cat pdb_files.txt | sort
1AT3A;1D4M1;1JEW2;1JQ6A;2BBVA;2CXVA;2FMBA;2FYQA;2SNWA;2WHXA;2WV4A;3MMGA;3O8BA;3Q3YA;3W95A;4EKFA;4F49A;4GUAA;4IZKA;4M0WA

HTH

ADD COMMENT
0
Entering edit mode

No actually I am using Python because I am working with Windows.

ADD REPLY
0
Entering edit mode
9.2 years ago

If it is written in a row, not a column, you need to transpose and sort (assuming your delimiter is space):

cat file.txt | sed 's/ /\n/g' | sort
ADD COMMENT
0
Entering edit mode

thank you very much. It works!!

ADD REPLY

Login before adding your answer.

Traffic: 2665 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6