[Biojava-l] RichLocation.Tools.merge(Collection members) method

Arnaud Kerhornou arnaud at ebi.ac.uk
Fri Feb 29 16:58:36 UTC 2008


Hi everyone,

I don't think the RichLocation.Tools.merge(Collection members) method is 
doing it right.

e.g. Input: 
biojavax:join:[1157624..1158025,1158025..1158420,1158420..1158893]
Expected output:1157624..1158895

But I get: join:[1157624..1158420,1158420..1158894]

I think the code should have the extra line: parent = union;
just after c=p; statement line 18 (See source code below),
otherwise it doesn't take into account the newly generated location.

Is that right ?

Thanks
Arnaud

Source code:

1    public static Collection merge(Collection members) {
2            // flatten them out first so we don't end up recursing
3            List membersList = new ArrayList(flatten(members));
4            // all members are now singles so we can use single vs 
single union operations
5            if (membersList.size()>1) {
6                for (int p = 0; p < (membersList.size()-1); p++) {
7                    RichLocation parent = (RichLocation)membersList.get(p);
8                    for (int c = p+1; c < membersList.size(); c++) {
9                        RichLocation child = 
(RichLocation)membersList.get(c);
10                       RichLocation union = 
(RichLocation)parent.union(child);
11                        // if parent can merge with child
12                        if (union.isContiguous()) {
13                           // replace parent with union
14                            membersList.set(p,union);
15                            // remove child
16                            membersList.remove(c);
17                            // check all children again
18                            c=p;
19                        }
20                    }
21                }
22            }
23            return membersList;
24        }
       



More information about the Biojava-l mailing list