use of java.lang.StringBuilder in project android_frameworks_base by crdroidandroid.
the class VrManagerService method formatSettings.
private static String formatSettings(Collection<String> c) {
if (c == null || c.isEmpty()) {
return "";
}
StringBuilder b = new StringBuilder();
boolean start = true;
for (String s : c) {
if ("".equals(s)) {
continue;
}
if (!start) {
b.append(':');
}
b.append(s);
start = false;
}
return b.toString();
}
use of java.lang.StringBuilder in project polyGembler by c-zhou.
the class GBS method generateFastqRead.
public FastqRead generateFastqRead(String dnaInsert, int recognization, String barcode, String identifier, boolean reverse) {
int i = reverse ? 1 : 0;
String toSequence = barcode + enzymeOverhang[recognization][i] + dnaInsert + enzymeRemainWithCommanAdapter[recognization][i];
StringBuilder sequence = new StringBuilder();
StringBuilder quality = new StringBuilder();
Character prev_base = null, prev_qual = null;
int b = 0, p = 0, indel, l = toSequence.length(), u;
while (b < readLength && p < l) {
if (random.nextFloat() < baseSubIndelErrorRate) {
indel = random.nextInt(3);
if (indel == 0) {
/**
* substitution
*/
prev_base = baseSubstitutionErrorProbabilityMap.get(toSequence.charAt(p)).get(random.nextInt(INV_PROBS_PRECISION));
prev_qual = qualityTransitionProbabilityMap.get(b).get(prev_qual).get(random.nextInt(INV_PROBS_PRECISION));
sequence.append(prev_base);
quality.append(prev_qual);
p++;
b++;
} else if (indel == 1) {
/**
* insertion
*/
u = (int) Math.ceil(-Math.log(1.0 - random.nextFloat()) / baseIndelErrorProbabilityLambda);
u = Math.min(u, readLength - b);
sequence.append(insertionSeqFactory(u));
for (int t = 0; t < u; t++) {
prev_qual = qualityTransitionProbabilityMap.get(b).get(prev_qual).get(random.nextInt(INV_PROBS_PRECISION));
quality.append(prev_qual);
b++;
}
prev_base = sequence.charAt(b - 1);
} else {
/**
* deletion
*/
p += Math.ceil(-Math.log(1.0 - random.nextFloat()) / baseIndelErrorProbabilityLambda);
}
} else {
if (prev_base == MISSING_BASE_SYMBOL && random.nextFloat() < probabilityBaseMissingSucceeding[b]) {
sequence.append(MISSING_BASE_SYMBOL);
quality.append(MISSING_QUAL_SCORE);
} else if (random.nextFloat() < probabilityBaseMissingInitialization[b]) {
prev_base = MISSING_BASE_SYMBOL;
prev_qual = null;
sequence.append(MISSING_BASE_SYMBOL);
quality.append(MISSING_QUAL_SCORE);
} else {
prev_base = toSequence.charAt(p);
prev_qual = qualityTransitionProbabilityMap.get(b).get(prev_qual).get(random.nextInt(INV_PROBS_PRECISION));
sequence.append(prev_base);
quality.append(prev_qual);
}
p++;
b++;
}
}
while (b++ < readLength) {
sequence.append(MISSING_BASE_SYMBOL);
quality.append(MISSING_QUAL_SCORE);
}
return new FastqRead(identifier, sequence.toString(), "+", quality.toString());
}
use of java.lang.StringBuilder 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);
}
}
use of java.lang.StringBuilder in project android_packages_apps_Snap by LineageOS.
the class SettingsManager method getSupportedQcfaDimension.
public String getSupportedQcfaDimension(int cameraId) {
int[] qcfaDimension = mCharacteristics.get(cameraId).get(CaptureModule.QCFA_SUPPORT_DIMENSION);
if (qcfaDimension == null) {
return null;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < qcfaDimension.length; i++) {
sb.append(qcfaDimension[i]);
if (i == 0) {
sb.append("x");
}
}
return sb.toString();
}
use of java.lang.StringBuilder in project MassBank-web by MassBank.
the class MSDBUpdateUtil method updateSubStructData.
/**
*/
public static boolean updateSubStructData(String serverUrl) {
boolean ret = true;
String cgiUrl = serverUrl + "cgi-bin/GenSubstructure.cgi";
try {
URL url = new URL(cgiUrl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setConnectTimeout(10 * 1000);
con.setReadTimeout(60 * 1000);
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String line = "";
StringBuilder res = new StringBuilder();
while ((line = in.readLine()) != null) {
res.append(line);
}
if (res.indexOf("OK") == -1) {
ret = false;
}
} catch (IOException e) {
e.printStackTrace();
ret = false;
}
return ret;
}
Aggregations