Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update EnvironmentFinderMultiMain.java #1

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Binary file added out/ass.jar
Binary file not shown.
Binary file modified out/metacherchant.bat
Binary file not shown.
Binary file modified out/metacherchant.jar
Binary file not shown.
Binary file modified out/metacherchant.sh
100644 → 100755
Binary file not shown.
104 changes: 104 additions & 0 deletions src/algo/AssemblerCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package algo;

import org.apache.log4j.Logger;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
* Created by -- on 13.02.2018.
*/
public class AssemblerCalculator implements Runnable {
private final String assembler;
private final String assemblerPath;
private final String outputPrefix;
private final int readsNumber;
private final Logger logger;

public AssemblerCalculator(String assembler, String assemblerPath, String outputPrefix, int readsNumber, Logger logger) {
this.assembler = assembler;
this.assemblerPath = assemblerPath;
this.outputPrefix = outputPrefix;
this.readsNumber = readsNumber;
this.logger = logger;
}

private void runAssembler() {
if (assembler.equals("spades")) {
try {
String[] commandA = {"python", assemblerPath + "/spades.py", "--12",
outputPrefix + "cutReads" + readsNumber + ".fastq", "-o", outputPrefix + "out_spades" + readsNumber};
String[] commandR = {"mv", outputPrefix + "out_spades" + readsNumber + "/" + "contigs.fasta",
outputPrefix + "contigs" + readsNumber + ".fasta"};
ProcessBuilder procBuilder = new ProcessBuilder(commandA);
ProcessBuilder procBuilderR = new ProcessBuilder(commandR);

procBuilder.redirectErrorStream(true);
Process process = procBuilder.start();
InputStream stdout = process.getInputStream();
InputStreamReader isrStdout = new InputStreamReader(stdout);
BufferedReader brStdout = new BufferedReader(isrStdout);
String line;
while ((line = brStdout.readLine()) != null) {
logger.info(line);
}
// or better take assembly_graph.gfa?

procBuilderR.redirectErrorStream(true);
Process processB = procBuilderR.start();
InputStream stdoutB = processB.getInputStream();
InputStreamReader isrStdoutB = new InputStreamReader(stdoutB);
BufferedReader brStdoutB = new BufferedReader(isrStdoutB);
String lineB;
while ((lineB = brStdoutB.readLine()) != null) {
logger.info(lineB);
}
} catch (IOException e) {
e.printStackTrace();
logger.info(e.getMessage());
}
}
if (assembler.equals("megahit")) {
try {
String[] commandA = {assemblerPath + "/megahit", "--12",
outputPrefix + "cutReads" + readsNumber + ".fastq", "-o", outputPrefix + "out_megahit" + readsNumber};
String[] commandR = {"mv", outputPrefix + "out_megahit" + readsNumber + "/" + "final.contigs.fa",
outputPrefix + "contigs" + readsNumber + ".fasta"};
ProcessBuilder procBuilder = new ProcessBuilder(commandA);
ProcessBuilder procBuilderR = new ProcessBuilder(commandR);

procBuilder.redirectErrorStream(true);
Process process = procBuilder.start();
InputStream stdout = process.getInputStream();
InputStreamReader isrStdout = new InputStreamReader(stdout);
BufferedReader brStdout = new BufferedReader(isrStdout);

String line;
while ((line = brStdout.readLine()) != null) {
logger.info(line);
}

procBuilderR.redirectErrorStream(true);
Process processB = procBuilderR.start();
InputStream stdoutB = processB.getInputStream();
InputStreamReader isrStdoutB = new InputStreamReader(stdoutB);
BufferedReader brStdoutB = new BufferedReader(isrStdoutB);
String lineB;
while ((lineB = brStdoutB.readLine()) != null) {
logger.info(lineB);
}

} catch (IOException e) {
e.printStackTrace();
logger.info(e.getMessage());
}
}
}

@Override
public void run() {
runAssembler();
}
}
4 changes: 2 additions & 2 deletions src/algo/OneSequenceCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class OneSequenceCalculator implements Runnable {
private boolean fail = false;

public OneSequenceCalculator(String sequence, int k, int minOccurences, String outputPrefix, HashFunction hasher, BigLong2ShortHashMap reads, Logger logger, boolean bothDirections, int chunkLength, TerminationMode termMode, boolean trimPaths) {
this.sequence = sequence.toString();
this.sequence = sequence;
this.k = k;
this.outputPrefix = outputPrefix;
this.minOccurences = minOccurences;
Expand Down Expand Up @@ -100,7 +100,7 @@ private void addToSubgraph(String kmer) {
subgraph.put(normalizeDna(kmer), (int) reads.get(getKmerKey(kmer)));
}

private boolean isContainedInSubgraph(String kmer) {
boolean isContainedInSubgraph(String kmer) {
return subgraph.containsKey(normalizeDna(kmer));
}

Expand Down
86 changes: 86 additions & 0 deletions src/algo/ReadsFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package algo;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

import org.apache.log4j.Logger;
import ru.ifmo.genetics.dna.Dna;
import ru.ifmo.genetics.dna.DnaQ;
import ru.ifmo.genetics.io.ReadersUtils;
import ru.ifmo.genetics.io.formats.QualityFormat;
import ru.ifmo.genetics.io.sources.NamedSource;
import ru.ifmo.genetics.utils.tool.ExecutionFailedException;

public class ReadsFilter implements Runnable {
private OneSequenceCalculator calc;
private File file;
private final String outputPrefix;
private final int readsNumber;
private int k;
private int percentFiltration;
private final Logger logger;

public ReadsFilter(File file, OneSequenceCalculator calc, String outputPrefix, int readsNumber, int k, int percentFiltration, Logger logger) {
this.file = file;
this.calc = calc;
this.outputPrefix = outputPrefix;
this.readsNumber = readsNumber;
this.k = k;
this.percentFiltration = percentFiltration;
this.logger = logger;
}

private void reader() throws ExecutionFailedException {
File outputCutReads = new File(outputPrefix + "/cutReads" + readsNumber + ".fastq");
outputCutReads.getParentFile().mkdirs();
NamedSource<Dna> reader = null;
try {
PrintWriter out;
out = new PrintWriter(outputCutReads);
reader = ReadersUtils.readDnaLazy(file);
ReadersUtils.loadDnaQs(file);
QualityFormat qualF = ReadersUtils.determineQualityFormat(file);
NamedSource<DnaQ> quals = ReadersUtils.readDnaQLazy(file);
int indexCutRead = 0;
for (DnaQ qual : quals) {
String read = qual.toString();
int len = read.length();
int kmersInRead = len - k + 1;
int kmersFiltration = kmersInRead * percentFiltration / 100;
kmersFiltration = Math.max(1, kmersFiltration);
int numberCoverageKmers = 0;
for (int i = 0; i < len - k; i++) {
if (calc.isContainedInSubgraph(read.substring(i, i + k))) {
numberCoverageKmers++;
}
if (numberCoverageKmers >= kmersFiltration) {
indexCutRead++;
out.println("@" + indexCutRead + "\n" + read + "\n+");
for (int j = 0; j < len; j++) {
out.print(qualF.getPhredChar(qual.phredAt(j)));
}
out.println();
break;
}
}
}
out.close();
} catch (IOException e) {
throw new ExecutionFailedException("Failed to read from file " + file.getPath());
}

}

@Override
public void run() {
try {
reader();
} catch (ExecutionFailedException e) {
logger.info(e.getMessage());
}
}

}

//--k 3 --reads reads.fastq --seq genes.fasta --maxkmers 100 --coverage 0 -o newfile
4 changes: 2 additions & 2 deletions src/io/writers/GFAWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ private void printEdge(PrintWriter out, SingleNode first, SingleNode second) {
out.print("L\t");
out.print((Math.min(first.rc.id, first.id) + 1) + (first.isGeneNode ? GENE_LABEL_SUFFIX : ""));
out.print('\t');
out.print((first.id < first.rc.id ? "+" : "-"));
out.print((first.id < first.rc.id ? "-" : "+"));
out.print('\t');
out.print((Math.min(second.rc.id, second.id) + 1) + (second.isGeneNode ? GENE_LABEL_SUFFIX : ""));
out.print('\t');
out.print((second.id > second.rc.id ? "+" : "-"));
out.print((second.id > second.rc.id ? "-" : "+"));
out.print('\t');
out.println((k - 1) + "M");
}
Expand Down
Loading