-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFastaVsFasta.java
More file actions
64 lines (55 loc) · 1.49 KB
/
FastaVsFasta.java
File metadata and controls
64 lines (55 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
public class FastaVsFasta {
HashMap<String,HashSet<String>> map = new HashMap<String,HashSet<String>>();
ArrayList<String> files = new ArrayList<String>();
public FastaVsFasta(String[] args) {
if(args.length < 1)
System.err.println("Usage: a.fasta b.fasta [c.fasta] ... [n.fasta]\nProduces stats on all pairwise comparisons of sequences.");
for(String s: args)
{
map.put(s, new HashSet<String>());
SuperScanner ss = new SuperScanner(s);
files.add(s);
while(ss.hasMore())
{
ss.getLine();
map.get(s).add(ss.getLine());
}
ss.close();
}
for(int i = 0; i < files.size(); i++)
{
for(int j = i+1; j < files.size(); j++)
{
System.out.println("Uniq to "+files.get(i)+"\tUniq to "+files.get(j)+"\tIn both\tTotal");
int[] counts = compare(map.get(files.get(i)), map.get(files.get(j)));
System.out.println(String.format("%d\t%d\t%d\t%d",counts[0],counts[1],counts[2],counts[0]+counts[1]+counts[2]));
}
}
}
private int[] compare(HashSet<String> a, HashSet<String> b) {
int[] result = new int [3];
HashSet<String> both = new HashSet<String>();
both.addAll(a); both.addAll(b);
for(String s: both)
{
if(a.contains(s))
{
if(b.contains(s))
result[2]++;
else
result[0]++;
}
else
result[1]++;
}
return result;
}
public static void main(String[] args) {
new FastaVsFasta(args);
}
}