use of org.molgenis.data.vcf.datastructures.Trio in project molgenis by molgenis.
the class VcfUtils method getPedigree.
/**
* Get pedigree data from VCF Now only support child, father, mother No fancy data structure either Output:
* result.put(childID, Arrays.asList(new String[]{motherID, fatherID}));
*/
public static HashMap<String, Trio> getPedigree(Scanner inputVcfFileScanner) {
HashMap<String, Trio> result = new HashMap<>();
while (inputVcfFileScanner.hasNextLine()) {
String line = inputVcfFileScanner.nextLine();
// quit when we don't see header lines anymore
if (!line.startsWith(VcfRepository.PREFIX)) {
break;
}
// expecting e.g. ##PEDIGREE=<Child=100400,Mother=100402,Father=100401>
if (line.startsWith("##PEDIGREE")) {
System.out.println("Pedigree data line: " + line);
String childID = null;
String motherID = null;
String fatherID = null;
String lineStripped = line.replace("##PEDIGREE=<", "").replace(">", "");
String[] lineSplit = lineStripped.split(",", -1);
for (String element : lineSplit) {
if (element.startsWith("Child")) {
childID = element.replace("Child=", "");
} else if (element.startsWith("Mother")) {
motherID = element.replace("Mother=", "");
} else if (element.startsWith("Father")) {
fatherID = element.replace("Father=", "");
} else {
throw new MolgenisDataException("Expected Child, Mother or Father, but found: " + element + " in line " + line);
}
}
if (childID != null && motherID != null && fatherID != null) {
// good
result.put(childID, new Trio(new Sample(childID), new Sample(motherID), new Sample(fatherID)));
} else {
throw new MolgenisDataException("Missing Child, Mother or Father ID in line " + line);
}
}
}
return result;
}
Aggregations