-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/haansi/haplocheck
- Loading branch information
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
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
106 changes: 106 additions & 0 deletions
106
src/main/java/genepi/mitolib/haplogrep/VariantsToHsd.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,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(); | ||
|
||
} | ||
|
||
} |