Skip to main content

Column subtractor - Python

I am still struggling with the after effects of Linux reinstallation on my system.
Two major problems:
1) Firefox and openoffice is still not in English. Its giving me hard time.
2) The functions in openoffice  version of excel is not working.

I am yet to sort that out. In the mean time, I desperately needed it to do simple task. subtracting values of one column from one in another column and write the difference in next column.

So, I had input in this form:

------------------


0    2.179139    0.951816
1    2.314531    1.006480
2    2.191692    0.951938
3    2.079704    0.952747
4    2.092761    0.939545
5    2.362056    0.984791
6    2.153595    0.957934
7    2.213173    0.951768
8    2.175687    0.953091

--------------------

I needed to subtract  column 3 data from column 2 data. So, I tried this:

---------------------------
#!/usr/bin/env python

fo=open('name.txt' +'_output','w')
with open('name.txt') as fd:
 for line in fd:
   columns=line.split()
   columns=map(float,columns)
   fo.write ("%s \t %s \n" %(line.strip(), columns[1] - columns[2]))

-----------------------------

It creates an output with difference written in next column :


---------------------------------
0    2.179139    0.951816      1.227323
1    2.314531    1.006480      1.308051
2    2.191692    0.951938      1.239754
3    2.079704    0.952747      1.126957
4    2.092761    0.939545      1.153216
5    2.362056    0.984791      1.377265
6    2.153595    0.957934      1.195661
7    2.213173    0.951768      1.261405
8    2.175687    0.953091      1.222596

---------------------------------

It works fine, only problem is it ends with an error:

IndexError: list index out of range

Although it doesn't effect the result.
So, for the moment I got the result I wanted but I will come back and take care of this small issue.








Comments

Popular posts from this blog

Material Studio - selective molecule movement

So, working with Material Studio is awesome. You get to handle bigger, complicated and even unimaginable system. But I am facing problems in very minute functioning. I recently faced two problems, but managed to resolve on my own. Somehow, tutorials doesn't help in resolving them and you end up doing some exercise on your own to get the solution. Among these, the problem of bringing two molecular structures in one window and then adjusting one molecule by moving it around, while other structure remains untouched, as it is. Actually, this should not be a problem to do. There is a simple way of doing this. Select the molecule to be moved and then there is a symbol (button) to select, which allows you to selectively move that molecule only. This is the same way it can be done in Material studio too.  But among all the dozens of symbols, the new person handling MS, kind of gets lost. So, what he does is check the tutorials, for any help. But the tutorials don't talk about suc...

Using Packmol

Packmol is a software that allows you to generate a single combined PDB file for all the molecules you are considering. It is a free software and can be downloaded from this link: http://www.ime.unicamp.br/~martinez/packmol/ The installation guide is also provided on the page and its really easy to follow. http://www.ime.unicamp.br/~martinez/packmol/ You can also find some examples but I tried on my own. Anyway what you need is an input file which looks like: ------------------ tolerance 2.0 output trial.pdb add_amber_ter filetype pdb structure 2a.pdb   number 1   inside cube 0. 0. 0. 10. end structure structure 2d.pdb   number 1   inside cube 0. 0. 0. 10. end structure --------------------------------- IT includes some information like: how close the molecules considered can be.(tolerance) name of output pdb file "add_amber_ter" adds term "TER" after every molecule thus defining the start and end of every molecule. After mentioning the...

AutoDock Vina protocol: For Molecular Docking

There are many softwares available for carrying out molecular docking calculations. Many of these softwares are paid, while some of them are free. AutoDock is one such freely available software. Earlier, there was AutoDock 4.0 version available. One of the problem with the software was the space it would occupy, if you attempt to do multi docking. Recently, there is another algorithm made available under autodock. It is called AutoDock Vina. This is more efficient, robust and fast algorithm. There are many tutorials available to learn AutoDock Vina including: http://autodock.scripps.edu/faqs-help/tutorial/using-autodock-4-with-autodocktools/2012_ADTtut.pdf and also a video tutorial http://vina.scripps.edu/tutorial.html    But for some reason, few changes or explanation in little detail is always required to make it understandable for a beginner to follow.  Here is a protocol designed in our group, which our Master's student follow to get acquainted to Molecular...