Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/haansi/haplocheck
Browse files Browse the repository at this point in the history
  • Loading branch information
haansi committed Mar 2, 2018
2 parents 44ae967 + fe52c42 commit ed1555d
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/genepi/mitolib/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import genepi.mitolib.contChecker.HaploChecker2;
import genepi.mitolib.contChecker.HaploChecker2Hsd;
import genepi.mitolib.contChecker.HaploChecker3;
import genepi.mitolib.haplogrep.VariantsToHsd;
import genepi.mitolib.lofreq.LoFreqReader;
import genepi.mitolib.splitter.HeteroplasmySplitter;
import genepi.mitolib.splitter.HeteroplasmySplitterRaw;
Expand Down Expand Up @@ -40,6 +41,7 @@ public static void main (String[] args){
tools.addTool("haplochecker2",HaploChecker2.class);
tools.addTool("haplochecker2hsd",HaploChecker2Hsd.class);
tools.addTool("haplochecker3",HaploChecker3.class);
tools.addTool("variants2hsd",VariantsToHsd.class);
try {
tools.start();
} catch (InstantiationException e) {
Expand Down
106 changes: 106 additions & 0 deletions src/main/java/genepi/mitolib/haplogrep/VariantsToHsd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package genepi.mitolib.haplogrep;

import java.io.IOException;
import java.util.HashMap;

import genepi.base.Tool;
import genepi.io.table.reader.CsvTableReader;
import genepi.io.text.LineWriter;

public class VariantsToHsd extends Tool {

public VariantsToHsd(String[] args) {
super(args);
}

@Override
public void init() {
System.out.println("Create Haplogrep Input for stable variants");
}

@Override
public void createParameters() {

addParameter("in", "variants.txt");
addParameter("out", "output file for HaploGrep");
}

@Override
public int run() {

String in = (String) getValue("in");

String out = (String) getValue("out");

CsvTableReader reader = new CsvTableReader(in, '\t');

HashMap<String, String> profiles = new HashMap<String, String>();

while (reader.next()) {

double level = reader.getDouble("Variant-Level");

// only take stable positions!
if (level > 0.5) {

String id = reader.getString("SampleID");

int pos = reader.getInteger("Pos");

String variant = reader.getString("Variant");

String snp = pos + variant;

if (profiles.get(id) == null) {

profiles.put(id, snp);

} else {

String value = profiles.get(id);

profiles.put(id, value + "\t" + snp);

}

}
}

LineWriter writer = null;
try {
writer = new LineWriter(out);

for (String key : profiles.keySet()) {

StringBuilder hsdLine = new StringBuilder();

hsdLine.append(key + "\t" + "1-16569" + "\t" + "?" + "\t");

hsdLine.append(profiles.get(key));

writer.write(hsdLine.toString());
}

writer.close();

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

System.out.println("Done. Written to "+out);

return 0;

}

public static void main(String[] args) throws IOException {

// new AroFilter2(args).start();
VariantsToHsd test = new VariantsToHsd(
new String[] { "--in", "data/haplogrep/variants.txt", "--out", "data/haplogrep/samples.hsd" });
test.start();

}

}

0 comments on commit ed1555d

Please sign in to comment.