Skip to content

Commit

Permalink
Merge pull request #1 from Delgon95/PseudoknotRemoval_files
Browse files Browse the repository at this point in the history
Add pseudoknot removal algorithm files.
  • Loading branch information
tzok authored Jul 20, 2016
2 parents 7187e36 + 4c0890c commit ba1bc7e
Show file tree
Hide file tree
Showing 6 changed files with 806 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/main/java/pl/poznan/put/structure/secondary/ConflictMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package pl.poznan.put.structure.secondary;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class ConflictMap {

private HashMap<Integer, HashMap<Integer, Boolean>> conflicts = new HashMap<Integer, HashMap<Integer, Boolean>>();


// Create a basic 2DMap from which tells about conflicts. It can return if given Region have conflicts and give these conflicts
public ConflictMap (Map<Integer, Region> idToRegion) {
boolean conflict = false;

for(int i = 0; i < idToRegion.size(); i++) {
conflicts.put(i, new HashMap<Integer, Boolean>());
}

for(int i = 0; i < idToRegion.size(); i++) {
for(int j = i+1; j < idToRegion.size(); j++) {
conflict = isConflicting(idToRegion.get(i), idToRegion.get(j));
if(conflict){
conflicts.get(i).put(j, true);
conflicts.get(j).put(i, true);
}
}
}

for(int i = 0; i < idToRegion.size(); i++) {
if(conflicts.get(i).isEmpty()) conflicts.remove(i);
}
}

// Return array of ids that are still conflicting
public ArrayList<Integer> conflicting() {
ArrayList<Integer> conflictsVector = new ArrayList<Integer>(conflicts.keySet());

return conflictsVector;
}

// Check if given Regions are conflicting
private boolean isConflicting(Region first, Region second) {
int startFirst = first.start, endFirst = first.end, startSecond = second.start, endSecond = second.end;

return (((startFirst < startSecond) && (endFirst < endSecond) && (startSecond < endFirst)) || ((startSecond < startFirst) && (endSecond < endFirst) && (startFirst < endSecond)));
}

// Remove Region and all associated conflicts with it
public void remove(int idToRemove) {
int id;
ArrayList<Integer> conflictingIDs = new ArrayList<Integer>(conflicts.get(idToRemove).keySet());
for(int i = 0; i < conflictingIDs.size(); i++) {
id = conflictingIDs.get(i);
conflicts.get(id).remove(idToRemove);
if(conflicts.get(id).isEmpty()) conflicts.remove(id);
}
conflicts.remove(idToRemove);
}

// Return all Regions (ID) that conflicts with given Region
public ArrayList<Integer> conflictsWith(int id) {
return new ArrayList<Integer>(conflicts.get(id).keySet());
}
}
Loading

0 comments on commit ba1bc7e

Please sign in to comment.