Skip to content

Commit

Permalink
Fixed minor bugs in conversion-free locus code.
Browse files Browse the repository at this point in the history
  • Loading branch information
tgvaughan committed Apr 24, 2018
1 parent fae524a commit 622ba17
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
25 changes: 19 additions & 6 deletions src/bacter/ConversionGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class ConversionGraph extends Tree {
*/
protected Map<Locus, List<Conversion>> convs;
protected Map<Locus, List<Conversion>> storedConvs;
protected final static List<Conversion> emptyConvList = new ArrayList<>();

/**
* Event and region lists.
Expand Down Expand Up @@ -114,7 +115,7 @@ public void initAndValidate() {
}

regionLists = new HashMap<>();
for (Locus locus : convertibleLoci)
for (Locus locus : loci)
regionLists.put(locus, new RegionList(this, locus));

cfEventList = new CFEventList(this);
Expand Down Expand Up @@ -175,6 +176,9 @@ public void addConversion(Conversion conv) {

Locus locus = conv.getLocus();

if (!locus.conversionsAllowed())
throw new IllegalStateException("Tried to add a conversion to a conversion-free locus.");

int i;
for (i=0; i<convs.get(locus).size(); i++)
if (convs.get(locus).get(i).startSite>conv.startSite)
Expand All @@ -190,7 +194,10 @@ public void addConversion(Conversion conv) {
*/
public void deleteConversion(Conversion conv) {
startEditing(null);


if (!conv.getLocus().conversionsAllowed())
throw new IllegalStateException("Tried to remove a conversion from a conversion-free locus.");

convs.get(conv.getLocus()).remove(conv);
}

Expand All @@ -201,7 +208,10 @@ public void deleteConversion(Conversion conv) {
* @return List of conversions.
*/
public List<Conversion> getConversions(Locus locus) {
return convs.get(locus);
if (locus.conversionsAllowed())
return convs.get(locus);
else
return emptyConvList;
}

/**
Expand All @@ -211,7 +221,10 @@ public List<Conversion> getConversions(Locus locus) {
* @return Number of conversions.
*/
public int getConvCount(Locus locus) {
return convs.get(locus).size();
if (locus.conversionsAllowed())
return convs.get(locus).size();
else
return 0;
}

/**
Expand Down Expand Up @@ -523,7 +536,7 @@ private void generalAssignFrom(StateNode other, boolean fragileAssignment) {
cfEventList = new CFEventList(this);

regionLists.clear();
for (Locus locus : convertibleLoci) {
for (Locus locus : loci) {
regionLists.put(locus, new RegionList(this, locus));
}
}
Expand Down Expand Up @@ -999,7 +1012,7 @@ public void restore() {
convs = tmp;

cfEventList.makeDirty();
for (Locus locus : convertibleLoci)
for (Locus locus : loci)
regionLists.get(locus).makeDirty();
}

Expand Down
9 changes: 3 additions & 6 deletions src/bacter/RegionList.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.function.Consumer;

/**
Expand Down Expand Up @@ -110,11 +107,11 @@ public void updateRegionList() {
if (affectedSiteList.affectedSiteCount.get(conversion)>0)
convOrderedByStart.add(conversion.getCopy());
});
convOrderedByStart.sort((Conversion o1, Conversion o2) -> o1.startSite - o2.startSite);
convOrderedByStart.sort(Comparator.comparingInt((Conversion o) -> o.startSite));

List<Conversion> convOrderedByEnd = new ArrayList<>();
convOrderedByEnd.addAll(convOrderedByStart);
convOrderedByEnd.sort((Conversion o1, Conversion o2) -> o1.endSite - o2.endSite);
convOrderedByEnd.sort(Comparator.comparingInt((Conversion o) -> o.endSite));

Set<Conversion> activeConversions = Sets.newHashSet();

Expand Down

0 comments on commit 622ba17

Please sign in to comment.