-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These are the same files as discussed in https://www.synapse.org/#!Synapse:syn7349259/wiki/407357
- Loading branch information
1 parent
4784983
commit a61486d
Showing
14 changed files
with
1,442 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
import java.io.BufferedReader; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.Vector; | ||
|
||
/** | ||
* | ||
*/ | ||
|
||
/** | ||
* @author zuccong | ||
* | ||
*/ | ||
public class CogeneMatrix { | ||
|
||
|
||
HashMap<Integer, HashMap<Integer,Double>> fusedCogeneMatrix = new HashMap<Integer, HashMap<Integer,Double>>(); | ||
HashMap<Integer,Double> networkweights = new HashMap<Integer,Double>(); | ||
|
||
/** | ||
* @return the networkweights | ||
*/ | ||
public HashMap<Integer, Double> getNetworkweights() { | ||
return networkweights; | ||
} | ||
|
||
/** | ||
* @param networkweights the networkweights to set | ||
*/ | ||
public void setNetworkweights(HashMap<Integer, Double> networkweights) { | ||
this.networkweights = networkweights; | ||
} | ||
|
||
public void readNetworkNumberVote(String filePath) throws FileNotFoundException, IOException { | ||
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) { | ||
String line; | ||
while ((line = br.readLine()) != null) { | ||
String[] networkLine = line.split("\t", -1); | ||
for(int i = 2; i<networkLine.length;i++) { | ||
int nodeA = Integer.parseInt(networkLine[i]); | ||
for(int j = 2; j<networkLine.length;j++) { | ||
int nodeB = Integer.parseInt(networkLine[j]); | ||
if(nodeA!=nodeB) { | ||
HashMap<Integer,Double> tmp = new HashMap<Integer,Double>(); | ||
if(fusedCogeneMatrix.containsKey(nodeA)) { | ||
tmp = fusedCogeneMatrix.get(nodeA); | ||
double value = 1.0/6.0; | ||
if(tmp.containsKey(nodeB)) | ||
value = value + tmp.get(nodeB); | ||
tmp.put(nodeB, value); | ||
}else { | ||
double value = 1.0/6.0; | ||
tmp.put(nodeB, value); | ||
} | ||
fusedCogeneMatrix.put(nodeA, tmp); | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
|
||
public void readNetworkWeightedVote(String filePath, int networkid) throws FileNotFoundException, IOException { | ||
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) { | ||
String line; | ||
while ((line = br.readLine()) != null) { | ||
String[] networkLine = line.split("\t", -1); | ||
for(int i = 2; i<networkLine.length;i++) { | ||
int nodeA = Integer.parseInt(networkLine[i]); | ||
for(int j = 2; j<networkLine.length;j++) { | ||
int nodeB = Integer.parseInt(networkLine[j]); | ||
if(nodeA!=nodeB) { | ||
System.out.println(nodeA + " " + nodeB); | ||
if(nodeA!=nodeB) { | ||
HashMap<Integer,Double> tmp = new HashMap<Integer,Double>(); | ||
if(fusedCogeneMatrix.containsKey(nodeA)) { | ||
tmp = fusedCogeneMatrix.get(nodeA); | ||
double value = networkWeight(networkid); | ||
if(tmp.containsKey(nodeB)) | ||
value = value + tmp.get(nodeB); | ||
tmp.put(nodeB, value); | ||
}else { | ||
double value = networkWeight(networkid); | ||
tmp.put(nodeB, value); | ||
} | ||
fusedCogeneMatrix.put(nodeA, tmp); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
|
||
public void printCogeneMatrix() { | ||
Iterator<Entry<Integer, HashMap<Integer, Double>>> it = fusedCogeneMatrix.entrySet().iterator(); | ||
while (it.hasNext()) { | ||
Map.Entry pair = (Map.Entry)it.next(); | ||
int nodeA = (int) pair.getKey(); | ||
HashMap<Integer, Double> tmp = (HashMap<Integer, Double>) pair.getValue(); | ||
Iterator ittmp = tmp.entrySet().iterator(); | ||
while (ittmp.hasNext()) { | ||
Map.Entry pairtmp = (Map.Entry)ittmp.next(); | ||
//System.out.println(nodeA + " " + (int)pairtmp.getKey() + " = " + (double)pairtmp.getValue()); | ||
} | ||
} | ||
} | ||
|
||
public void printCogeneMatrixOnFile(PrintWriter out) { | ||
Iterator<Entry<Integer, HashMap<Integer, Double>>> it = fusedCogeneMatrix.entrySet().iterator(); | ||
while (it.hasNext()) { | ||
Map.Entry pair = (Map.Entry)it.next(); | ||
int nodeA = (int) pair.getKey(); | ||
HashMap<Integer, Double> tmp = (HashMap<Integer, Double>) pair.getValue(); | ||
Iterator ittmp = tmp.entrySet().iterator(); | ||
while (ittmp.hasNext()) { | ||
Map.Entry pairtmp = (Map.Entry)ittmp.next(); | ||
out.println(nodeA + "\t" + (int)pairtmp.getKey() + "\t" + (double)pairtmp.getValue()); | ||
} | ||
} | ||
out.flush(); | ||
} | ||
|
||
public double networkWeight(int networkid) { | ||
switch (networkid) { | ||
case 1: return networkweights.get(1); | ||
case 2: return networkweights.get(2); | ||
case 3: return networkweights.get(3); | ||
case 4: return networkweights.get(4); | ||
case 5: return networkweights.get(5); | ||
case 6: return networkweights.get(6); | ||
default: return networkweights.get(1); | ||
} | ||
} | ||
|
||
|
||
|
||
/** | ||
* @param args | ||
* @throws IOException | ||
* @throws FileNotFoundException | ||
*/ | ||
public static void main(String[] args) throws FileNotFoundException, IOException { | ||
CogeneMatrix cm1 = new CogeneMatrix(); | ||
System.out.println("Reading network"); | ||
|
||
Vector<String> networkFiles = new Vector<String>(); | ||
for(int i = 0; i < args.length; i++) { | ||
networkFiles.add(args[i]); | ||
System.out.println(args[i]); | ||
} | ||
for(String file : networkFiles) { | ||
cm1.readNetworkNumberVote(file); | ||
} | ||
|
||
/*cm1.readNetworkNumberVote("/Users/zuccong/Dropbox/DMI_challenge/results/sc2_round4/run3/1_ppi_anonym_aligned_v2.txt"); | ||
cm1.readNetworkNumberVote("/Users/zuccong/Dropbox/DMI_challenge/results/sc2_round4/run3/2_ppi_anonym_aligned_v2.txt"); | ||
cm1.readNetworkNumberVote("/Users/zuccong/Dropbox/DMI_challenge/results/sc2_round4/run3/3_signal_anonym_aligned_undirected_v3_normalised.txt"); | ||
cm1.readNetworkNumberVote("/Users/zuccong/Dropbox/DMI_challenge/results/sc2_round4/run3/4_coexpr_anonym_aligned_v2.txt"); | ||
cm1.readNetworkNumberVote("/Users/zuccong/Dropbox/DMI_challenge/results/sc2_round4/run3/5_cancer_anonym_aligned_v2.txt"); | ||
cm1.readNetworkNumberVote("/Users/zuccong/Dropbox/DMI_challenge/results/sc2_round4/run3/6_homology_anonym_aligned_v2_normalised.txt"); | ||
*/ | ||
System.out.println("Network read"); | ||
//cm1.printCogeneMatrix(); | ||
PrintWriter out1 = new PrintWriter("../data/subchallenge2/communities_graph_uniform_voting.txt"); | ||
|
||
cm1.printCogeneMatrixOnFile(out1); | ||
out1.close(); | ||
|
||
CogeneMatrix cm2 = new CogeneMatrix(); | ||
|
||
System.out.println("Reading network"); | ||
cm2.networkweights.put(1, 13.0/52.0); | ||
cm2.networkweights.put(2, 9.0/52.0); | ||
cm2.networkweights.put(3, 7.0/52.0); | ||
cm2.networkweights.put(4, 9.0/52.0); | ||
cm2.networkweights.put(5, 5.0/52.0); | ||
cm2.networkweights.put(6, 9.0/52.0); | ||
|
||
int i =1; | ||
for(String file : networkFiles) { | ||
cm2.readNetworkWeightedVote(file, i); | ||
i++; | ||
} | ||
|
||
/* | ||
cm2.readNetworkWeightedVote("/Users/zuccong/Dropbox/DMI_challenge/results/sc2_round4/run3/1_ppi_anonym_aligned_v2.txt", 1); | ||
cm2.readNetworkWeightedVote("/Users/zuccong/Dropbox/DMI_challenge/results/sc2_round4/run3/2_ppi_anonym_aligned_v2.txt", 2); | ||
cm2.readNetworkWeightedVote("/Users/zuccong/Dropbox/DMI_challenge/results/sc2_round4/run3/3_signal_anonym_aligned_undirected_v3_normalised.txt", 3); | ||
cm2.readNetworkWeightedVote("/Users/zuccong/Dropbox/DMI_challenge/results/sc2_round4/run3/4_coexpr_anonym_aligned_v2.txt", 4); | ||
cm2.readNetworkWeightedVote("/Users/zuccong/Dropbox/DMI_challenge/results/sc2_round4/run3/5_cancer_anonym_aligned_v2.txt", 5); | ||
cm2.readNetworkWeightedVote("/Users/zuccong/Dropbox/DMI_challenge/results/sc2_round4/run3/6_homology_anonym_aligned_v2_normalised.txt", 6); | ||
*/ | ||
System.out.println("Network read"); | ||
//cm2.printCogeneMatrix(); | ||
PrintWriter out2 = new PrintWriter("../data/subchallenge2/communities_graph_weighted_voting.txt"); | ||
|
||
cm2.printCogeneMatrixOnFile(out2); | ||
out2.close(); | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
|
||
####################### | ||
# Assumed structure # | ||
# and required files # | ||
####################### | ||
|
||
# Two folders, "data" and "code" | ||
|
||
# The "data" folder contains two folders, "subchallenge1" and "subchallenge2", which contain the input networks | ||
|
||
# The "code" folder contains our code, as well as a folder "louvain" which contains the executable files "convert", "matrix", "louvain" and "hierarchy", which are all compiled from the file "louvain-generic.tar.gz" downloaded from http://sourceforge.net/projects/louvain/ | ||
|
||
# File pageRank.c needs to be compiled to an executable called "pageRank" (in the "code" folder) | ||
|
||
# The following commands assume that "code" is the working directory | ||
|
||
|
||
###################### | ||
# Pre-processing for # | ||
# networks 3 and 6 # | ||
###################### | ||
|
||
# Note: this needs to run only once | ||
|
||
python convertToUndirected.py | ||
python normaliseWeights.py 3_signal_anonym_undirected_v3 | ||
python normaliseWeights.py 6_homology_anonym_v2 | ||
|
||
|
||
######################## | ||
# Calculating PageRank # | ||
# on all six networks # | ||
######################## | ||
|
||
# Note: this needs to run only once | ||
|
||
# Usage: ./pageRank <nb_nodes> <nb_edges> <input_file> <output_file> <directed|undirected> | ||
|
||
# Network 1 | ||
|
||
./pageRank 17397 2232405 ../data/subchallenge1/1_ppi_anonym_v2.txt ./PR_1_ppi_anonym_v2.txt undirected | ||
|
||
# Network 2 | ||
|
||
./pageRank 12420 397309 ../data/subchallenge1/2_ppi_anonym_v2.txt ./PR_2_ppi_anonym_v2.txt undirected | ||
|
||
# Network 3 | ||
|
||
./pageRank 5254 21826 ../data/subchallenge1/3_signal_anonym_undirected_v3_normalised.txt ./PR_3_signal_anonym_undirected_v3_normalised.txt undirected | ||
|
||
# Network 4 | ||
|
||
./pageRank 12588 1000000 ../data/subchallenge1/4_coexpr_anonym_v2.txt ./PR_4_coexpr_anonym_v2.txt undirected | ||
|
||
# Network 5 | ||
|
||
./pageRank 14679 1000000 ../data/subchallenge1/5_cancer_anonym_v2.txt ./PR_5_cancer_anonym_v2.txt undirected | ||
|
||
# Network 6 | ||
|
||
./pageRank 10475 4223606 ../data/subchallenge1/6_homology_anonym_v2_normalised.txt ./PR_6_homology_anonym_v2_normalised.txt undirected | ||
|
||
|
||
######################## | ||
# Running our method # | ||
# on the six networks # | ||
######################## | ||
|
||
# Usage: python enhancedRecursiveLouvain_recPR_sc1.py <network> <threshold for recursion> | ||
|
||
python enhancedRecursiveLouvain_recPR_sc1.py 1_ppi_anonym_v2 80 | ||
python enhancedRecursiveLouvain_recPR_sc1.py 2_ppi_anonym_v2 80 | ||
python enhancedRecursiveLouvain_recPR_sc1.py 3_signal_anonym_undirected_v3_normalised 80 | ||
python enhancedRecursiveLouvain_recPR_sc1.py 4_coexpr_anonym_v2 95 | ||
python enhancedRecursiveLouvain_recPR_sc1.py 5_cancer_anonym_v2 90 | ||
python enhancedRecursiveLouvain_recPR_sc1.py 6_homology_anonym_v2_normalised 80 | ||
|
||
python finaliseEnhancedLouvain_sc1.py | ||
|
Oops, something went wrong.