use of java.lang.StringBuilder in project MSEC by Tencent.
the class MysqlSink method createTable.
private int createTable() throws IOException, SQLException {
SimpleDateFormat formatter = new SimpleDateFormat("MMdd");
String curTableName = "t_dailylog_" + formatter.format(new Date());
if (curTableName.compareTo(tableName) == 0) {
return 0;
}
DatabaseMetaData md = conn.getMetaData();
ResultSet rs = md.getTables(null, null, curTableName, null);
if (rs.next()) {
tableName = curTableName;
return 1;
}
//create table
File file = new File(createTableSqlFile);
BufferedReader bf = new BufferedReader(new FileReader(file));
StringBuilder sb = new StringBuilder();
String line = "";
while (line != null) {
line = bf.readLine();
if (line == null)
break;
sb.append(line);
}
String createTableSql = sb.toString().replace("$TABLENAME$", curTableName);
Statement stmt = conn.createStatement();
stmt.executeUpdate(createTableSql);
LOG.info("Create table " + curTableName + " using sql statement: " + createTableSql);
tableName = curTableName;
return 2;
}
use of java.lang.StringBuilder in project android_frameworks_base by DirtyUnicorns.
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 Population method formatOutput.
private String formatOutput(String dnaSEQ) {
// TODO Auto-generated method stub
Pattern p = Pattern.compile("(.{" + CHUNK_SIZE + "})", Pattern.DOTALL);
Matcher m = p.matcher(dnaSEQ);
StringBuilder os = new StringBuilder();
os.append(m.replaceAll("$1" + "\n"));
if (os.charAt(os.length() - 1) != '\n')
os.append("\n");
return os.toString();
}
use of java.lang.StringBuilder in project polyGembler by c-zhou.
the class Population method generateChromosome.
public Chromosome0[] generateChromosome(String fastaFilePath) {
List<String> chroms = new ArrayList<String>();
double physicaL = 0.0;
try {
BufferedReader br = getBufferedReader(fastaFilePath);
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
if (line.startsWith(">")) {
sb.setLength(0);
while ((line = br.readLine()) != null && !line.startsWith(">")) sb.append(line);
chroms.add(sb.toString());
physicaL += sb.length();
}
}
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
double CHROM_BASE_LENGTH = GENETIC_LENGTH > 0 ? GENETIC_LENGTH / physicaL : 1e-6;
int N = chroms.size();
Chromosome0[] chromosome = new Chromosome0[N];
for (int i = 0; i < N; i++) {
double cm = chroms.get(i).length() * CHROM_BASE_LENGTH;
chromosome[i] = new Chromosome0("CHROM" + (i + 1), chroms.get(i), chroms.get(i).length(), cm, CENTROMERE_POS * cm, random.nextFloat() / 2 + 0.5, 0.0);
}
return chromosome;
}
use of java.lang.StringBuilder in project polyGembler by c-zhou.
the class GBS method simulate.
public void simulate(final int sim_sample_index) {
try {
// GBSFastqFileBufferedWriter = getGZIPBufferedWriter(GBSFastqFilePath);
String name, line, fastaFilePath;
ArrayList<Integer> cut, recognization;
StringBuilder chromosome;
FastqRead fastq;
int l;
Digest digestion;
fastaFilePath = fastaFileList.get(sim_sample_index);
StringBuilder oos = new StringBuilder();
// try{
BufferedWriter GBSFastqFileBufferedWriter = getGZIPBufferedWriter(GBSFastqFilePath + "_" + sim_sample_index + ".gz", 65536);
BufferedReader br = getBufferedReader(fastaFilePath);
line = br.readLine();
while (line != null) {
name = parseSampleName(fastaFilePath) + "|" + line.replaceFirst(">", "");
chromosome = new StringBuilder();
while ((line = br.readLine()) != null && !line.startsWith(">")) {
chromosome.append(line);
}
l = chromosome.length();
// System.out.println(getSystemTime()+">>> digest starting...");
digestion = new Digest(enzyme, chromosome.toString());
// System.out.println(getSystemTime()+">>> done.");
cut = digestion.getCutsite();
recognization = digestion.getRecognization();
// System.out.println(getSystemTime()+">>> simulate starting...");
// simulate 5'-3' end genome
int coverage;
for (int i = 2; i < cut.size(); i++) {
if (cut.get(i) - cut.get(i - 1) < MIN_FRAGMENT_SIZE)
continue;
coverage = (int) Math.round(meanDepth + random.nextGaussian() * sdDepth);
for (int j = 0; j < coverage; j++) {
fastq = generateFastqRead(chromosome.substring(cut.get(i - 1), cut.get(i)), recognization.get(i - 1), fastaFileBarcodeMap.get(fastaFilePath), "@" + name + "|" + cut.get(i - 1) + "|" + j, false);
// writeFastqRead(fastq);
oos.setLength(0);
oos.append(fastq.identifier);
oos.append(NLS);
oos.append(fastq.sequence);
oos.append(NLS);
oos.append(fastq.plus);
oos.append(NLS);
oos.append(fastq.quality);
oos.append(NLS);
GBSFastqFileBufferedWriter.write(oos.toString());
}
}
// simulate reverse complementary genome
chromosome.reverse();
for (int i = 0; i < l; i++) chromosome.setCharAt(i, baseComplementaryMap.get(chromosome.charAt(i)));
for (int i = 0; i < cut.size(); i++) cut.set(i, l - cut.get(i));
Collections.reverse(cut);
for (int i = 2; i < cut.size(); i++) {
if (cut.get(i) - cut.get(i - 1) < MIN_FRAGMENT_SIZE)
continue;
coverage = (int) Math.round(meanDepth + random.nextGaussian() * sdDepth);
for (int j = 0; j < coverage; j++) {
fastq = generateFastqRead(chromosome.substring(cut.get(i - 1), cut.get(i)), recognization.get(i - 1), fastaFileBarcodeMap.get(fastaFilePath), "@" + name + "|" + cut.get(i - 1) + "|1", true);
// writeFastqRead(fastq);
oos.setLength(0);
oos.append(fastq.identifier);
oos.append(NLS);
oos.append(fastq.sequence);
oos.append(NLS);
oos.append(fastq.plus);
oos.append(NLS);
oos.append(fastq.quality);
oos.append(NLS);
GBSFastqFileBufferedWriter.write(oos.toString());
}
}
// System.out.println(getSystemTime()+">>> done.");
System.out.println(getSystemTime() + ">>> " + name + " done.");
}
br.close();
GBSFastqFileBufferedWriter.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
// GBSFastqFileBufferedWriter.close();
// } catch (IOException | InterruptedException e) {
// } catch (InterruptedException e) {
// e.printStackTrace();
// System.exit(1);
// }
}
Aggregations