-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactore apply task to use collection interface
- Loading branch information
Showing
3 changed files
with
202 additions
and
67 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/java/genepi/riskscore/io/scores/IRiskScoreCollection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package genepi.riskscore.io.scores; | ||
|
||
import java.util.Map.Entry; | ||
import java.util.Set; | ||
import java.util.SortedSet; | ||
|
||
import genepi.riskscore.io.Chunk; | ||
import genepi.riskscore.model.ReferenceVariant; | ||
import genepi.riskscore.model.RiskScoreSummary; | ||
|
||
public interface IRiskScoreCollection { | ||
|
||
public String getBuild(); | ||
|
||
public String getName(); | ||
|
||
public String getVersion(); | ||
|
||
public void buildIndex(String chromosome, Chunk chunk, String dbsnp, String proxies) throws Exception; | ||
|
||
public RiskScoreSummary getSummary(int index); | ||
|
||
public boolean contains(int index, int position); | ||
|
||
public Set<Entry<Integer, ReferenceVariant>> getAllVariants(int index); | ||
|
||
public ReferenceVariant getVariant(int index, int position); | ||
|
||
public int getSize(); | ||
|
||
public boolean isEmpty(); | ||
|
||
public RiskScoreSummary[] getSummaries(); | ||
|
||
} |
147 changes: 147 additions & 0 deletions
147
src/main/java/genepi/riskscore/io/scores/RiskScoreCollection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package genepi.riskscore.io.scores; | ||
|
||
import java.io.File; | ||
import java.util.*; | ||
|
||
import genepi.riskscore.io.Chunk; | ||
import genepi.riskscore.io.RiskScoreFile; | ||
import genepi.riskscore.io.formats.RiskScoreFormatFactory.RiskScoreFormat; | ||
import genepi.riskscore.model.ReferenceVariant; | ||
import genepi.riskscore.model.RiskScoreSummary; | ||
|
||
public class RiskScoreCollection implements IRiskScoreCollection { | ||
|
||
private String build; | ||
|
||
private String name; | ||
|
||
private String version; | ||
|
||
private RiskScoreFile[] riskscores; | ||
|
||
private RiskScoreSummary[] summaries; | ||
|
||
private int numberRiskScores; | ||
|
||
private String[] filenames; | ||
|
||
private boolean verbose = false; | ||
|
||
private Map<String, RiskScoreFormat> formats; | ||
|
||
public RiskScoreCollection(String... filenames) { | ||
this.filenames = filenames; | ||
} | ||
|
||
public RiskScoreCollection(String[] filenames, Map<String, RiskScoreFormat> formats) { | ||
this.filenames = filenames; | ||
this.formats = formats; | ||
} | ||
|
||
@Override | ||
public String getBuild() { | ||
return build; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String getVersion() { | ||
return version; | ||
} | ||
|
||
@Override | ||
public void buildIndex(String chromosome, Chunk chunk, String dbsnp, String proxies) throws Exception { | ||
|
||
numberRiskScores = filenames.length; | ||
|
||
summaries = new RiskScoreSummary[numberRiskScores]; | ||
for (int i = 0; i < numberRiskScores; i++) { | ||
String name = RiskScoreFile.getName(filenames[i]); | ||
summaries[i] = new RiskScoreSummary(name); | ||
} | ||
|
||
int total = 0; | ||
|
||
riskscores = new RiskScoreFile[numberRiskScores]; | ||
for (int i = 0; i < numberRiskScores; i++) { | ||
|
||
if (verbose) { | ||
System.out.println("Loading file " + filenames[i] + "..."); | ||
} | ||
|
||
RiskScoreFormat format = formats.get(filenames[i]); | ||
RiskScoreFile riskscore = new RiskScoreFile(filenames[i], format, dbsnp, proxies); | ||
|
||
if (chunk != null) { | ||
riskscore.buildIndex(chromosome, chunk); | ||
} else { | ||
riskscore.buildIndex(chromosome); | ||
} | ||
|
||
summaries[i].setVariants(riskscore.getTotalVariants()); | ||
summaries[i].setVariantsIgnored(riskscore.getIgnoredVariants()); | ||
|
||
if (verbose) { | ||
System.out.println("Loaded " + riskscore.getLoadedVariants() + " weights for chromosome " + chromosome); | ||
} | ||
total += riskscore.getLoadedVariants(); | ||
riskscores[i] = riskscore; | ||
|
||
} | ||
|
||
if (verbose) { | ||
System.out.println(); | ||
System.out.println("Collection contains " + total + " weights for chromosome " + chromosome); | ||
System.out.println(); | ||
} | ||
} | ||
|
||
@Override | ||
public RiskScoreSummary getSummary(int index) { | ||
return summaries[index]; | ||
} | ||
|
||
@Override | ||
public boolean contains(int index, int position) { | ||
return riskscores[index].contains(position); | ||
} | ||
|
||
@Override | ||
public ReferenceVariant getVariant(int index, int position) { | ||
return riskscores[index].getVariant(position); | ||
} | ||
|
||
@Override | ||
public Set<Map.Entry<Integer, ReferenceVariant>> getAllVariants(int index) { | ||
return riskscores[index].getVariants().entrySet(); | ||
} | ||
|
||
@Override | ||
public int getSize() { | ||
return numberRiskScores; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
for (RiskScoreFile riskscore : riskscores) { | ||
if (riskscore.getLoadedVariants() > 0) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public RiskScoreSummary[] getSummaries() { | ||
return summaries; | ||
} | ||
|
||
public void setVerbose(boolean verbose) { | ||
this.verbose = verbose; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters