开发者

Combinations of x, y and z coordinates (stored in three different files)

I am writing a bash script for automatising blind docking (finding binding sites within a protein). For so doing, I have divided a big 3D grid in smaller overlapping grids.

开发者_开发技巧

I have created three files containing the x, y and z coordinates of the sub-grids centres, respectively. In other words, one file contains all the possible x coordinates (one per line), the second all the y coordinates and the third all the z coordinates. The coordinates have three decimal places and can be positive or negative.

Now I would like to find all possible combinations of x,y and z. For each combination I would like to create a folder (called something like x1y1z1, x1y2z1, x1y3z1, etc) containing a text file with x, y and z coordinates that correspond to that particular combination.

I have found solutions to related problems using Python. However, as I am not familiar with Python and I have already a large bash script with a lot of variables defined, I would like to know if there is an easy way for doing this in bash or in any other language that I can easily integrate in my existing bash script.

Kind regards,

Miro

UPDATE:

This is the adapted version of the solution indicated by Matt D (thanks a million):

for x in $(cat centrex.tmp) ; do
 for y in $(cat centrey.tmp) ; do
  for z in $(cat centrez.tmp) ; do
      xvar=$(expr "$x" : '\(.*\)=.*')
      yvar=$(expr "$y" : '\(.*\)=.*')
      zvar=$(expr "$z" : '\(.*\)=.*')
      folder="${xvar}${yvar}${zvar}"
      mkdir $folder
      echo "center_x = "${x#*=} >> vinapar.conf
      echo "center_y = "${y#*=} >> vinapar.conf
      echo "center_z = "${z#*=} >> vinapar.conf
      cp vinapar.conf $folder/
      rm vinapar.conf
   done
 done
done

The reason to do this is that finally I formated my centreX.tmp files in this way:

x00=-15.349
x01=-10.349
x02=-5.349
...

This allows me to name the folders according to the chunk before the equals sign (x01y23z09) and then create files containing the actual coordinates.


If you want all the combinations of the contents, this will be a triple-nested loop.

#!/bin/bash
for x in $(cat xfile) ; do
  for y in $(cat yfile) ; do
    for z in $(cat zfile) ; do
      filename="$x$y$z"
      mkdir $filename
      # makes a file called xyz in dir xyz with contents "xyz"
      echo $filename > $filename/$filename 
    done
  done
done

Edit: This form would use read (haven't tested)

#!/bin/bash
while read x ; do
  while read y ; do
    while read z ; do
      filename="$x$y$z"
      mkdir $filename
      # makes a file called xyz in dir xyz with contents "xyz"
      echo $filename > $filename/$filename 
    done < zfile
  done < yfile
done < xfile
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜