1

I have this data:

String[] a = {"a", "b", "c", "d"};
String[] b = {"c", "d"};
String[] c = {"b", "c"};

Now i need a graphical representation of each intersection of these lists, mostly this will result in a Venn diagram like this: http://manuals.bioinformatics.ucr.edu/_/rsrc/1353282523430/home/R_BioCondManual/r-bioc-temp/venn1.png?height=291&width=400

In my implementation these lists will mostly contain more than 1000 entries and i will have 10+ lists, so a good representation would create a set of strings and would intersect them. in my very simple case this would be result in

set_a = {"c"};      // in all three lists
set_b = {"b", "d"}; // in two of three lists
set_c = {"a"};      // in one of three lists

another requirement is now that the size of the intersection should be proportional to the occurences in the lists. so the size of set_a should be 3 times bigger than set_c.

is there any lib for that requirements?

reox
  • 5,036
  • 11
  • 53
  • 98

1 Answers1

0

I think this program does the transformation you want:

    // The input
    String[][] a = {
        {"a", "b", "c", "d"},
        {"c", "d"},
        {"b", "c"}
    };

    System.out.println("Input: "+ Arrays.deepToString(a));

    // Convert the input to a Set of Sets (so that we can hangle it more easily
    Set<Set<String>> input = new HashSet<Set<String>>();
    for (String[] s : a) {
        input.add(new HashSet<String>(Arrays.asList(s)));
    }

    // The map is used for counting how many times each element appears 
    Map<String, Integer> count = new HashMap<String, Integer>();
    for (Set<String> s : input) {
        for (String i : s) {
            if (!count.containsKey(i)) {
                count.put(i, 1);
            } else {
                count.put(i, count.get(i) + 1);
            }
        }
    }

    //Create the output structure
    Set<String> output[] = new HashSet[a.length + 1];
    for (int i = 1; i < output.length; i++) {
        output[i] = new HashSet<String>();
    }

    // Fill the output structure according the map
    for (String key : count.keySet()) {
        output[count.get(key)].add(key);
    }

    // And print the output
    for (int i = output.length - 1; i > 0; i--) {
        System.out.println("Set_" + i + " = " + Arrays.toString(output[i].toArray()));
    }

Output:

Input: [[a, b, c, d], [c, d], [b, c]]
Set_3 = [c]
Set_2 = [d, b]
Set_1 = [a]
user000001
  • 32,226
  • 12
  • 81
  • 108
  • but there is no graphical representation. the creation of the sets is very easy indeed, but how can i generate diagrams from that? – reox Feb 08 '13 at 15:50