---
# System prepended metadata

title: 用perl 多類別的交集聯集

---

# 　用perl 多類別的交集聯集


利用　hash unique key 的特性
每讀過一次就用質數去加，列出所有質數的加總可能，並計算這一些質數被算到的數即可。

---


以下面的例子

####   first  please prepeare 4 result name list in .txt format!
＃首先要先準備好每種清單的　ｌｉｓｔ

假如我有四群資料：　RS_DE, RS_ed, ex_DE, ex_ed
我就假設他們為四個質數

```
3	RS_DE	
5	RS_ed	
7	ex_DE 
11	ex_ed 
```
所以這四筆之間的交集、聯集和差集就是這四個質數的加總排列組合，如下：

1. class.pl  ----> count any kind of result count


```
3	RS_DE							   5
5	RS_ed							3018
7	ex_DE                                          　     1869
11	ex_ed                                                  32
8	RS_DE | RS_ed                                        2382
10	RS_DE  |ex_DE                                           0
14	RS_DE   |ex_ed                                          1
12	RS_ed  |ex_DE                                         306
18	ex_DE   |ex_ed                                       1227
16	RS_ed  |ex_ed                                      　　  8
15	RS_DE  |RS_ed | ex_DE                          　      627
19	RS_DE  |RS_ed |ex_ed                  　　　　　　　　　  15
21	RS_DE  |ex_DE | ex_ed                                    0
23	RS_ed  |ex_DE  |ex_ed                                  246
26	RS_DE  |RS_ed  |ex_DE | ex_ed                          655
=======================================
```

2. class_U.pl  ---->out put all of 聯集

>out put will be name list  in "name.txt"


3. 15_name_list.pl  -----> will out put each kind of result name list in independent fill by number!

 > "1"~ "26" files     , only the "result number" file will content the name!!!
 > 
 >1 , 2 ,3 , 5 ,7 ,8, 10, 11, 12, 14, 15, 16, 18, 19, 21, 23, 26 




### 每讀過一次＋3
```
#!/usr/bin/perl
 open(file1,"gene_rs_DE.txt")||die"can't open $sInFleNm :$!";


while(<file1>){
 	chomp;
 	$genename=$_;
 	$list{$genename}=$list{$genename}+3;
 	}
```
### 每讀過一次＋5
```
 open(file2,"gene_rs_ed.txt")||die"can't open $sInFleNm :$!";
 while(<file2>){
 	chomp;
 	$genename=$_;
 	$list{$genename}=$list{$genename}+5;
 	}
```
### 每讀過一次＋7

```
 open(file3,"gene_ex_DE.txt")||die"can't open $sInFleNm :$!";
 while(<file3>){
 	chomp;
 	$genename=$_;
 	$list{$genename}=$list{$genename}+7;
 	}
 ```
### 每讀過一次＋11
```
 open(file4,"gene_ex_ed.txt")||die"can't open $sInFleNm :$!";
  while(<file4>){
 	chomp;
 	$genename=$_;
 	$list{$genename}=$list{$genename}+11;
 	}
```

### 全部印出來　
```
 	for($n=0;$n<=26;$n++){
		open (filew,'>',"$n");
		foreach(keys %list){
			if($list{$_}==$n){
			print filew "$_\n";
			}
		}
	}

```

# 用Ｒ去繪製出來


![](https://i.imgur.com/luNMdL8.png)
