Skip to content

Instantly share code, notes, and snippets.

@Quarx2k
Last active September 26, 2018 10:44
Show Gist options
  • Save Quarx2k/052769403d26a10e2b0e1e8d2c471bb1 to your computer and use it in GitHub Desktop.
Save Quarx2k/052769403d26a10e2b0e1e8d2c471bb1 to your computer and use it in GitHub Desktop.
WTF KEK
package com.company;
import java.io.*;
import java.nio.CharBuffer;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) {
if (args.length < 2) {
System.out.println(":(");
return;
}
String inPath = args[0];
String outPath = args[1];
long start = System.currentTimeMillis();
try (Stream<String> stream = Files.lines(Paths.get(inPath))) {
final StringBuilder resultString = new StringBuilder();
final StringBuilder header = new StringBuilder();
final AtomicInteger counter = new AtomicInteger(0);
final StringBuilder charsBuilder = new StringBuilder();
try (BufferedWriter out = new BufferedWriter(new FileWriter(outPath, true))) {
out.write("MolID;Target;Ligand;Run;Pose;Rank;dG;VS;Atom;X;Y;Z");
out.newLine();
stream.skip(1).forEach(string -> {
boolean containsSpace = string.contains(" ");
boolean containsComma = string.contains(",");
if (!containsSpace && !containsComma) {
header.setLength(0);
header.append(counter.getAndIncrement());
} else if (containsComma) {
String[] wtfIsThis = string.split(",");
String[] wtfIsThis2 = wtfIsThis[0].split("-");
header.append(";").append(wtfIsThis2[0])
.append(";")
.append(wtfIsThis2[1])
.append(";")
.append(wtfIsThis2[4])
.append(";")
.append(wtfIsThis2[6])
.append(";")
.append(wtfIsThis[1])
.append(";")
.append(wtfIsThis[2])
.append(";")
.append(wtfIsThis[3])
.append(";");
} else {
int cnt = 0;
char[] arr = string.toCharArray();
char[] output = new char[arr.length];
boolean wasSpace = false;
charsBuilder.setLength(0);
for (char c : arr) {
if (Character.isWhitespace(c)) {
wasSpace = true;
} else {
if (wasSpace) {
wasSpace = false;
output[cnt++] = ';';
}
output[cnt++] = c;
}
}
resultString.append(header).append(String.valueOf(output, 0, cnt));
try {
out.write(resultString.toString());
out.newLine();
resultString.setLength(0);
} catch (IOException e) {
e.printStackTrace();
}
}
});
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Elapsed time: " + (System.currentTimeMillis() - start));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment