use of PedigreeSim.Chromosome in project polyGembler by c-zhou.
the class Population method writeGenomeFile.
public void writeGenomeFile(int sim_sample_index) {
final int N = popData.chromCount();
String[][] indall;
// StringBuilder chr;
ArrayList<Locus> loci;
int pos;
String str2write;
Individual indiv = popData.getIndiv(sim_sample_index);
try (BufferedWriter bw = getGZIPBufferedWriter(filePath + SEP + scenario + SEP + indiv.getIndivName() + ".fasta.gz")) {
for (int c = 0; c < N; c++) {
Chromosome chrom = popData.getChrom(c);
Chromosome0 chr = chromosome[c];
loci = chrom.getLocus();
indall = new String[PLOIDY][loci.size()];
for (int l = 0; l < loci.size(); l++) {
String[] inds = indiv.getLocusAllele(c, l);
for (int h = 0; h < PLOIDY; h++) {
indall[h][l] = inds[h];
}
}
for (int h = 0; h < PLOIDY; h++) {
// debug
// println(getSystemTime()+" >>> StringBulder starting...");
/**
* String builder is slow
* chr = new StringBuilder(ref.substring(cutsite[c],cutsite[c+1]));
* for(int l=0; l<loci.size(); l++) {
* pos = SNPs2PosMap.get(loci.get(l).getLocusName());
* chr.replace(pos,pos+indall[h][l].length(),indall[h][l]);
* }
*/
// debug
// println(getSystemTime()+" >>> Done. BufferedWriter Start writing...");
String header = ">" + chr.getName() + "|" + (h + 1) + ":" + PLOIDY;
bw.write(header + NLS);
final StringBuilder oos = new StringBuilder();
int j0 = 0, j1 = chr.getLBasePairs();
for (int l = 0; l < loci.size(); l++) {
pos = SNPs2PosMap.get(loci.get(l).getLocusName());
str2write = indall[h][l];
oos.append(chr.getDnaSEQ().substring(j0, pos - str2write.length() + 1));
oos.append(str2write);
j0 = pos + str2write.length();
}
if (j0 < j1)
oos.append(chr.getDnaSEQ().substring(j0, j1));
bw.write(this.formatOutput(oos.toString()));
// debug
myLogger.info(getSystemTime() + " " + header + " >>> done.");
}
}
bw.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
Aggregations