Pair wise comparisons


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pair wise comparisons
# 1  
Old 06-10-2013
Pair wise comparisons

Hi,

I have 25 groups and I need to perform all possible pairwise compariosns between them using the formula n(n-1)/2. SO in my case it will be 25(25-1)/2 which is equal to 300 comparisons.

my 25 groups are
Code:
FG1	FG2	FG3	FG4	FG5
NT5E	CD44	CD44	CD44	AXL
ADAM19	CCDC80	L1CAM	L1CAM	CD44
AXL	COL1A1	ADM	RND3	FOSL1
CD44	COL3A1	COL1A1	BMP1	SP100
CD68	COL6A1	COL3A1	COL3A1	ACSL1
FXYD5	COL6A2	COL18A1	COL6A1	ADM
GLIPR1	COL6A3	CTGF	COL6A2	A2M
GM2A	COL18A1	EPAS1	COL6A3	COL1A1
L1CAM	CTGF	FOXC1	COL18A1	COL3A1
ADM	FBN1	GAP43	CTGF	COL6A2
A2M	FOXC1	HMOX1	ITGA4	DUSP4
ALPK2	LOX	HBEGF	ICAM1	FHL2
ANGPTL2	MGP	ITGA4	IL32	GAL
BMP1	MMP2	ICAM1	LOXL2	HMOX1
CALCRL	POSTN	IL1B	MGP	IL1B
CTSL1	PDGFRA	IL6R	POSTN	IL6R
CXCL14	SPARC	IL8	PCDH12	LOX
C18orf1	SPOCK1	LOX	SORBS3	MGP
CCDC80	THSD4	MMP2	SPOCK1	PGF
COL1A1	TFPI2	PGF	TGFB1I1	PDGFRA
COL3A1	TGFB2	PLAU	TGFBI	PTGS2
COL6A1	TGFBI	PTGS2	TNFRSF12A	RCAN1
COL6A2	VCAN	SPOCK1	VCAN	TGFB2
COL6A3		TGFB2		
COL18A1		TNFRSF12A		
CSF1		UNC5B		
CTGF		UNC5C		
CYBRD1		ETS1		
DKK1		VCAN		
DKK3				
EMP1				
FBN1

So for the first comparison which is comparing 1st group to 2nd group( group meaning column) then the result is going to be 10/23 ( here 10 is the number of genes common between 2 functional groups and 23 is the minimum list based on the two columns that we are comparing. In my example 1st column has 32 entries and 2nd column has 23 entries so the minimum of these two is 23. So the calculation is 10/23. I need to do this for all 300 comparisons). I tried doing this by R, but I get duplicates meaning (FG1 vs FG2 and FG2vs FG1). So I am seeing if there is a simple way to do this in awk.

Thanks,
# 2  
Old 06-11-2013
Could this help you ?
Code:
 
#!/bin/ksh
TotFGNumber=25
for (( i=1; i<=$TotFGNumber; i++ ))
do
        awk -vFGNo=$i -F"\t" '$FGNo !~ /^$/ {print $FGNo}' FGFilename > "FGFile_"$i
done
for (( i=1; i<=$TotFGNumber; i++ ))
do
        file1="FGFile_"$i
        k=$(($i + 1))
        for (( j=k; j<=$TotFGNumber; j++ ))
        do
                file2="FGFile_"$j
                LineCnt1=$(wc -l < $file1)
                LineCnt2=$(wc -l < $file2)
                [ $LineCnt1 -lt $LineCnt2 ] && LineCount=$(( $LineCnt1 - 1 )) ||  LineCount=$(( $LineCnt2 - 1))
                CommonFieldNo=$(awk     'NR==FNR{a[$1]++;next} \
                        a[$1]' $file1 $file2 | wc -l)
                Comparision=$(echo "scale=5;$CommonFieldNo / $LineCount" | bc)
                echo "FG${i} vs FG${j} -  $Comparision"
        done
done
rm -f FGFile_*

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

String regex comparisons

Here is the sample code: str1="abccccc" str2="abc?" if ]; then echo "same string" else echo "different string" fi Given that ? implies 0 or 1 match of preceding character, I was expecting the output to be "different string", but I am seeing "same string". Am I not using the... (3 Replies)
Discussion started by: Rameshck
3 Replies

2. Shell Programming and Scripting

File comparisons

Hi all, I want to compare two files based on column value Kindly help me a.txt 123,ABCD 456,DEF 789,SDF b.txt 123,KJI 456,LMN 321,MJK 678,KOL Output file should be like Common on both files c.txt 123,ABCD,KJI (8 Replies)
Discussion started by: aaysa123
8 Replies

3. UNIX for Dummies Questions & Answers

File and if statement comparisons

I'd love to get help on this one please. Ok so say I have a file called README with lines such as this: index:index.html required:file1.1:file2.1:file3.1 I'm having trouble with writing an if statement that compares the items in a list with a file inside README, what I imagine in my head... (7 Replies)
Discussion started by: mistsong1
7 Replies

4. UNIX for Dummies Questions & Answers

Date comparisons

Hi, I want to perform a simple date comparisons, i.e. select all files modified after a certain date (say 12-feb-2011) I do not have the option of creating a file and using find's -newer option. Any simple way to do this? I can do this by reading the stat command's output and comparing... (10 Replies)
Discussion started by: jawsnnn
10 Replies

5. Shell Programming and Scripting

String comparisons

Can someone please tell me what is wrong with this stings comparison? #!/bin/sh #set -xv set -u VAR=$(ping -c 5 -w 10 google.com | grep icmp_req=5 | awk '{print $6}') echo I like cookies echo $VAR if "$VAR" == 'icmp_req=5' then echo You Rock else echo You Stink fiThis is the error.... (6 Replies)
Discussion started by: cokedude
6 Replies

6. UNIX for Dummies Questions & Answers

Command comparisons

Hi guys, Im trying to figure out what is the difference between using a | and the command xargs ... examples of usage: 1) ls * | wc -w => this gives you the number of files in the current directory including all subdirectories 2) find . “*.log” | xargs grep ERROR => this gives... (6 Replies)
Discussion started by: avidrunner
6 Replies

7. Shell Programming and Scripting

Best practice for bracket comparisons?

So, I have no formal higher education in programming at all and am self taught. I am now wondering what would be considered best practices? Like should I hard code a variable, then compare it to what I want to know or achieve, or should I just put the commands with in the brackets? Example, a... (5 Replies)
Discussion started by: tlarkin
5 Replies

8. Shell Programming and Scripting

numeric range comparisons

I have two files.And a sort of matrix analysis. Both files have a string followed by two numbers: File 1: A 2 7 B 3 11 C 5 10 ...... File 2: X 1 10 Y 3 5 Z 5 9 What I'd like to do is for each set of numbers in the second file indicate if the first or second number (or both) in... (7 Replies)
Discussion started by: dcfargo
7 Replies

9. UNIX for Dummies Questions & Answers

Can grep do numerical comparisons?

Say for example I have a list of numbers.. 5 10 13 48 1 could I use grep to show only those numbers that are above 10? For various reasons I can only use grep... not awk or sed etc. (7 Replies)
Discussion started by: Uss_Defiant
7 Replies

10. Shell Programming and Scripting

Script to automate file comparisons

Hi, I need a script that loops through all the files two directories passed to it via parameter, and if two files have the same name, do a cmp comparison on the files. If the files are different, output the specifics returned by cmp. What's the best way to go about writing this, as I am a... (6 Replies)
Discussion started by: herman404
6 Replies
Login or Register to Ask a Question