Sponsored Content
Top Forums Shell Programming and Scripting how to calculate all pairwise distances in two dimensions and transform them into a matrix Post 302577238 by Bemar on Monday 28th of November 2011 12:19:49 PM
Old 11-28-2011
how to calculate all pairwise distances in two dimensions and transform them into a matrix

Hello to all,



I am very new in the shell scripting and I need help. I have data for several individuals in several rows followed by a tag and by 5 values per row, with the name of the individual in the first column, e.g.:
Code:
  IND1 H1 12 13 12 15 14
  IND2 H2 12 12 15 14 14
  IND3 H1 12 15 12 14 11

I would like to calculate the sum of the absolute values of the pairwise differences between individuals. For instance:
Code:
  Distance between IND1 and IND2=|12-12|+|13-12|+|12-15|+|15-14|+|14-14|= 5
  Distance between IND1 and IND3=|12-12|+|13-15|+|12-12|+|15-14|+|14-11|= 6
  Distance between IND2 and IND3=|12-12|+|12-15|+|15-12|+|14-14|+|14-11|= 9

Additionally, if the tags of two individuals are different, I would like to sum 100 to the final number. So finally the distance between:
IND1 and IND2 would be = 5 + 100 = 105
IND1 and IND3 would be = 6 + 0 = 6
IND2 and IND3 would be = 9 + 100 = 109


After this, I would like to transform this list of distances into a matrix:
Code:
  IND1   IND2   IND3
  IND1   
  IND2   105
  IND3   6        109

Could some one help me with this? Thanks a lot in advance! Best!
Moderator's Comments:
Mod Comment Please use code tags!
 

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
Info::Layer3::AlcatelLucent(3pm)			User Contributed Perl Documentation			  Info::Layer3::AlcatelLucent(3pm)

NAME
SNMP::Info::Layer3::AlcatelLucent - SNMP Interface to Alcatel-Lucent OmniSwitch AUTHOR
Bill Fenner SYNOPSIS
# Let SNMP::Info determine the correct subclass for you. my $alu = new SNMP::Info( AutoSpecify => 1, Debug => 1, # These arguments are passed directly to SNMP::Session DestHost => 'myswitch', Community => 'public', Version => 2 ) or die "Can't connect to DestHost. "; my $class = $alu->class(); print "SNMP::Info determined this device to fall under subclass : $class "; DESCRIPTION
Subclass for Alcatel-Lucent OmniSwitch devices Inherited Classes SNMP::Info::Layer3 SNMP::Info::MAU SNMP::Info::LLDP Required MIBs ALCATEL-IND1-DEVICES ALCATEL-IND1-CHASSIS-MIB ALU-POWER-ETHERNET-MIB Note that Alcatel-Lucent distributes their own proprietary version of the POWER-ETHERNET-MIB, but the MIB module name that they distribute is simply POWER-ETHERNET-MIB. This module must be hand-edited to change the module name to ALU-POWER-ETHERNET-MIB so that it can be used simultaneously with the standard POWER-ETHERNET-MIB. Inherited Classes' MIBs See "Required MIBs" in SNMP::Info::Layer3 for its own MIB requirements. See "Required MIBs" in SNMP::Info::MAU for its own MIB requirements. See "Required MIBs" in SNMP::Info::LLDP for its own MIB requirements. GLOBALS
These are methods that return scalar value from SNMP $alu->vendor() Returns 'alcatel-lucent' $alu->hasCDP() Returns whether LLDP is enabled. $alu->model() Tries to reference $alu->id() to one of the product MIBs listed above Removes 'device' from the name for readability. $alu->os() Returns 'AOS' $alu->os_ver() Grabs the os version from "sysDescr" $alu->ps1_type() Return the type of the first power supply from the ENTITY-MIB $alu->ps2_type() Return the type of the second power supply from the ENTITY-MIB $alu->ps1_status() Return the status of the first power supply from the ALCATEL-IND1-CHASSIS-MIB $alu->ps2_status() Return the status of the second power supply from the ALCATEL-IND1-CHASSIS-MIB Global Methods imported from SNMP::Info::Layer3 See documentation in "GLOBALS" in SNMP::Info::Layer3 for details. Global Methods imported from SNMP::Info::MAU See documentation in "GLOBALS" in SNMP::Info::MAU for details. Global Methods imported from SNMP::Info::Layer3 See documentation in "GLOBALS" in SNMP::Info::Layer3 for details. TABLE METHODS
These are methods that return tables of information in the form of a reference to a hash. $alu->interfaces() Returns interface name from "ifName", since the default return value of "ifDescr" includes the OS version. $alu->fw_mac() Use the Q-BRIDGE-MIB instead of BRIDGE-MIB $alu->fw_port() Use the Q-BRIDGE-MIB instead of BRIDGE-MIB $alu->bp_index() Work around various bugs in the BRIDGE-MIB and Q-BRIDGE-MIB implementations, by returning both "ifIndex" and "dot1dBasePort" mappings to "ifIndex" values. $alu->c_id() Returns LLDP information. $alu->c_if() Returns LLDP information. $alu->c_ip() Returns LLDP information. $alu->c_platform() Returns LLDP information. $alu->c_port() Returns LLDP information. $alu->i_duplex_admin() Returns info from MAU-MIB $alu->i_speed_admin() Returns info from MAU-MIB $alu->peth_port_ifindex() Returns the "ifIndex" value for power-ethernet ports using the OmniSwitch algorithm. Table Methods imported from SNMP::Info::Layer3 See documentation in "TABLE METHODS" in SNMP::Info::Layer3 for details. Table Methods imported from SNMP::Info::MAU See documentation in "TABLE METHODS" in SNMP::Info::MAU for details. Table Methods imported from SNMP::Info::LLDP See documentation in "TABLE METHODS" in SNMP::Info::LLDP for details. perl v5.12.4 2011-09-28 Info::Layer3::AlcatelLucent(3pm)
All times are GMT -4. The time now is 02:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy