Sponsored Content
Top Forums Shell Programming and Scripting how to calculate all pairwise distances in two dimensions and transform them into a matrix Post 302577333 by Chubler_XL on Monday 28th of November 2011 07:00:19 PM
Old 11-28-2011
Here is a solution using awk:

Code:
awk '
{ for(i=1;i<=NF;i++) D[NR,i]=$i }
END {
  for(i=1;i<=NR;i++) printf "\t" D[i,1];
  print ""
  for(i=1;i<=NR;i++) {
      printf D[i,1];
      for(j=1;j<=NR;j++) {
           TOT=(D[i,2]==D[j,2])?0:100
           for(k=3;k<8;k++) TOT+=D[i,k]>D[j,k]?D[i,k]-D[j,k]:D[j,k]-D[i,k]
           printf "\t" TOT;
      }
      print ""
  }
}' infile


Output for example infile is:
Code:
        IND1    IND2    IND3
IND1    0       105     6
IND2    105     0       109
IND3    6       109     0

 

9 More Discussions You Might Find Interesting

1. Programming

hoe to allocate a 2 dimensions array?

hi . how can I allocate a 2 dimensions array? I used : { int i; /* Allocating the rows */ Schedule = (int **)( malloc( sizeof(int*) * (N-2) ) ); if( Schedule == NULL ) { printf("\nError - couldn't allocate memory! Aborting...\n"); exit(-1); } /* Allocating memory for... (2 Replies)
Discussion started by: azran
2 Replies

2. Shell Programming and Scripting

dimensions 10

Hi, We are using dimensions 10 (source code control system) for our programs. Some programs contain special characters like ‘$' , ‘#' , ‘ , ‘ etc.. During the check-out process of an item , a unix shell script will be called to process the item. If the item contains a ‘$' character, it will... (0 Replies)
Discussion started by: mrs_rajan
0 Replies

3. Shell Programming and Scripting

Removing distances from Newick tree format

I have a large numbers of files containing data that look like this: (ID31:0.01682,(ID-123:0.00000,(ID_24:0.00000,ID&890:0.00000):0.00000):0.00000,ID12876:0.00000); (ID_24:-0.00052,(ID31:0.01697,(ID-123:-0.00059,ID&890:0.03528):0.00037):0.00027,ID12876:0.03484); I need to find ":" anywhere... (6 Replies)
Discussion started by: Xterra
6 Replies

4. Shell Programming and Scripting

awk to log transform on matrix file

Hi Friends, I have an input matrix file like this Col1 Col2 Col3 Col4 R1 1 2 3 4 R2 4 5 6 7 R3 5 6 7 8 I would like to consider only the numeric values without touching the column header and the row header. I looked up on the forum's search, and I found this. But, I donno how to... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

Eliminating sequences based on Distances

I have to remove sequences from a file based on the distance value. I am attaching the file containing the distances (Distance.xls) The second file looks something like this: Sequences.txt >Sample1 Freq 59 ggatatgatgatgaactggt >Sample1 Freq 54 ggatatgatgttgaactggt >Sample1 Freq 44... (2 Replies)
Discussion started by: Xterra
2 Replies

6. Shell Programming and Scripting

Calculate percentage of columns greater than certain value in a matrix using awk

This matrix represents correlation values. Is it possible to calculate the percentage of columns (a1, a2, a3) that have a value >= |0.5| and report the percentage that has positive correlation >0.5 and negative correlation <-0.5 separately. thanx in advance! input name a1 a2 a3... (5 Replies)
Discussion started by: quincyjones
5 Replies

7. Shell Programming and Scripting

Split files by pairwise combination

I have 2 files $ cat tmp A1 File1a B1 File1b A2 File2a B2 File2b A1 File1a B3 File3b and $ cat tmp1 A1/B1 File3 A1/B1 File4 A1/B1 File5 A1/B1 File6 A1/B1 File7 A2/B2 File8 A2/B2 File9 A2/B2 File10 (1 Reply)
Discussion started by: senhia83
1 Replies

8. Shell Programming and Scripting

Transform columns to matrix

The following code transform the matrix to columns. Is it possible to do it other way around ( get the input from the output) ? input y1 y2 y3 y4 y5 x1 0.3 0.5 2.3 3.1 5.1 x2 1.2 4.1 3.5 1.7 1.2 x3 3.1 2.1 1.0 4.1 2.1 x4 5.0 4.0 6.0 7.0 1.1 output x1 y1 0.3 x2 y1 1.2 x3... (1 Reply)
Discussion started by: quincyjones
1 Replies

9. UNIX for Beginners Questions & Answers

Create 'n' number random pairwise combination of words

File 1 contains the list of words that needed to be randomly paired: Tiger Cat Fish Frog Dog Mouse Elephant Monkey File 2 contains the pairs that should not be used (in any solution) during random pairing. Elephant-Dog Cat-Fish Monkey-Frog Dog-Elephant, Fish-Cat, Frog-Monkey... (1 Reply)
Discussion started by: sammy777888
1 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 07:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy