Skip to content

Commit

Permalink
cluster - uid labeling
Browse files Browse the repository at this point in the history
  • Loading branch information
endixk committed Oct 5, 2023
1 parent 6030ad9 commit 0057f95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/leb/main/EzAAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public EzAAI(String module) {
String label = null; // convert, extract
String input2 = null, mtxout = null; int thread = 10; double identity = 0.4, coverage = 0.5; // calculate
int program = PROGRAM_MMSEQS; // calculate
boolean useid = false; // cluster

private int parseArguments(String[] args) {
String modstr = "";
Expand Down Expand Up @@ -171,6 +172,9 @@ else if(!arg.get("-s").equals("nucl")) {
if(arg.get("-mtx") != null) mtxout = arg.get("-mtx");
if(arg.get("-t") != null) thread = Integer.parseInt(arg.get("-t"));
}
if(module == MODULE_CLUSTER) {
if(arg.get("-u") != null) useid = true;
}

if(arg.get("-prodigal") != null) path_prodigal = arg.get("-prodigal");
if(arg.get("-mmseqs") != null) path_mmseqs = arg.get("-mmseqs");
Expand Down Expand Up @@ -486,6 +490,7 @@ private int runCluster() {

// parse input file
Map<Integer, Integer> imap = new HashMap<>();
List<Integer> ids = new ArrayList<>();
List<String> labels = new ArrayList<>();
List<String> bufs = new ArrayList<>();
try {
Expand All @@ -498,10 +503,12 @@ private int runCluster() {
String lab1 = buf.split("\t")[2], lab2 = buf.split("\t")[3];
if(!imap.containsKey(id1)) {
imap.put(id1, labels.size());
ids.add(id1);
labels.add(lab1);
}
if(!imap.containsKey(id2)) {
imap.put(id2, labels.size());
ids.add(id2);
labels.add(lab2);
}
}
Expand Down Expand Up @@ -551,7 +558,7 @@ private int runCluster() {
Prompt.print("AAI matrix identified. Running hierarchical clustering with UPGMA method...");

// produce UPGMA tree
ProcUPGMA upgma = new ProcUPGMA(dmat, labels);
ProcUPGMA upgma = new ProcUPGMA(dmat, ids, labels, useid);
BufferedWriter bw = new BufferedWriter(new FileWriter(output));
bw.write(upgma.getTree() + "\n");
bw.close();
Expand Down Expand Up @@ -741,6 +748,7 @@ private static void printHelp(int module) {
System.out.println(ANSIHandler.wrapper(" Argument\tDescription", 'c'));
System.out.printf(" %s\t\t%s%n", "-i", "Input EzAAI result file containing all-by-all pairwise AAI values");
System.out.printf(" %s\t\t%s%n", "-o", "Output result file");
System.out.printf(" %s\t\t%s%n", "-u", "Use ID instead of label for tree");
System.out.println();
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/leb/process/ProcUPGMA.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ public class ProcUPGMA {
private final List<Integer> counts = new LinkedList<>();
private int N;

public ProcUPGMA(double[][] dmat, List<String> labels) {
public ProcUPGMA(double[][] dmat, List<Integer> ids, List<String> labels, boolean useid) {
this.dmat = dmat;
this.leaves.addAll(labels);
if(useid) {
for(int id : ids) {
this.leaves.add(String.format("%d", id));
}
} else {
this.leaves.addAll(labels);
}

N = labels.size();
for(int i = 0; i < N; i++) {
Expand Down

0 comments on commit 0057f95

Please sign in to comment.