Skip to content

Commit

Permalink
Merge pull request #65 from SanojPunchihewa/bug-fixes
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
SanojPunchihewa authored Oct 29, 2019
2 parents 3cbb317 + 6725303 commit 439713a
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ public static void createPipeline() {
public static void runPipeline() {
for (PipelineComponent pipelineComponent : pipelineComponents) {
long start = System.currentTimeMillis();
pipelineComponent.run();
int returnCode = pipelineComponent.run();
long time = System.currentTimeMillis() - start;
pipelineComponent.setRuntime(TimeFormat.millisToShortDHMS(time));
String status = returnCode == 0 ? "Success" : "Error";
pipelineComponent.setRuntime(TimeFormat.millisToShortDHMS(time) + " status = " + status);
if (returnCode != 0) {
break;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mobilegenomics.f5n.activity;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.AsyncTask;
Expand All @@ -14,11 +14,12 @@
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.widget.NestedScrollView;
import com.mobilegenomics.f5n.GUIConfiguration;
import com.mobilegenomics.f5n.R;
import com.mobilegenomics.f5n.core.PipelineComponent;
Expand All @@ -41,11 +42,13 @@ public class ConfirmationActivity extends AppCompatActivity {

private static final String TAG_SAMTOOLS = "samtools-native";

private ProgressDialog progressDialog;
private int isPipelineRunning = 0;

private boolean logWrittenToFile = false;

TextView txtLogs;

ScrollView scrollView;
NestedScrollView scrollView;

LinearLayout linearLayout;

Expand Down Expand Up @@ -101,7 +104,7 @@ public void onClick(final View v) {
separator1.setBackgroundColor(Color.parseColor("#000000"));
linearLayout.addView(separator1);

scrollView = new ScrollView(this);
scrollView = new NestedScrollView(this);
linearLayout.addView(scrollView);

txtLogs = new TextView(this);
Expand Down Expand Up @@ -134,6 +137,7 @@ public class RunPipeline extends AsyncTask<String, Integer, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
isPipelineRunning = 1;
}

@Override
Expand Down Expand Up @@ -161,6 +165,7 @@ protected void onPostExecute(final String s) {
pipelineComponent.getPipelineStep().getCommand() + " took " + pipelineComponent.getRuntime());
linearLayout.addView(txtRuntime);
}
isPipelineRunning = 2;
btnWriteLog.setVisibility(View.VISIBLE);
btnProceed.setEnabled(true);
mProgressBar.setVisibility(View.GONE);
Expand Down Expand Up @@ -265,12 +270,68 @@ private void writeLogToFile() {
myOutWriter.close();
fOut.close();
Toast.makeText(getApplicationContext(), "Finished writing to mobile-genomics in home", Toast.LENGTH_LONG)
.show(); //##5
.show();
logWrittenToFile = true;
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Write failure", Toast.LENGTH_SHORT).show(); //##6
Log.e("TAG", e.toString());
}

}

@Override
public void onBackPressed() {
if (isPipelineRunning == 0) {
super.onBackPressed();
} else if (isPipelineRunning == 1) {
showStopPipelineDialog();
} else if (isPipelineRunning == 2) {
if (!logWrittenToFile) {
showWriteToFileDialog();
} else {
super.onBackPressed();
}
}
}

private void showWriteToFileDialog() {

new AlertDialog.Builder(ConfirmationActivity.this)
.setTitle("Save log")
.setMessage("Are you sure you want to save log?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
writeLogToFile();
ConfirmationActivity.super.onBackPressed();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
ConfirmationActivity.super.onBackPressed();
}
})
.show();

}

private void showStopPipelineDialog() {

new AlertDialog.Builder(ConfirmationActivity.this)
.setTitle("Stop Running")
.setMessage("Are you sure to stop the pipeline?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Kill the native process
ConfirmationActivity.super.onBackPressed();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
dialog.dismiss();
}
})
.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
Log.e(TAG, "Error : " + e);
}
}

registerReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

try {
fOut = new FileOutputStream(logFile, true);
myOutWriter = new OutputStreamWriter(fOut);
Expand Down Expand Up @@ -117,14 +114,15 @@ public void onClick(final View v) {
btnRunPipeline.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
GUIConfiguration.eraseSelectedPipeline();
for (PipelineStep step : PipelineStep.values()) {
GUIConfiguration.addPipelineStep(step);
}
GUIConfiguration.printList();
GUIConfiguration.configureSteps(DemoActivity.this,
Environment.getExternalStorageDirectory() + "/" + folderName + "/"
+ fileName.substring(0, fileName.lastIndexOf(".")));
startActivity(new Intent(DemoActivity.this, ConfirmationActivity.class));
startActivity(new Intent(DemoActivity.this, TerminalActivity.class));
}
});
linearLayout.addView(btnRunPipeline);
Expand Down Expand Up @@ -172,10 +170,21 @@ public void onReceive(Context context, Intent intent) {
}
};

@Override
protected void onStart() {
super.onStart();
registerReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

@Override
protected void onPause() {
super.onPause();
unregisterReceiver(onDownloadComplete);
}

@Override
protected void onStop() {
super.onStop();
unregisterReceiver(onDownloadComplete);
try {
myOutWriter.append("-------------------- End of Log --------------------\n\n");
myOutWriter.flush();
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/mobilegenomics/f5n/core/Argument.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ public String toString() {
// TODO Check for NULL
if (this.setByUser) {
if (this.argValue != null) {
return this.hasFlag ? this.flag + " " + this.argValue : this.argValue;
if (this.hasFlag) {
return this.flag.endsWith("=") ? this.flag + this.argValue : this.flag + " " + this.argValue;
} else {
return this.argValue;
}
} else {
return this.flag;
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/raw/minimap2.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
{
"args": [
{
"argName": "Temporary Prefix for multi-part index",
"argValue": "temp.minimap",
"argDescription": "Prefix to create temporary files. Typically used for a multi-part index",
"flag": "--multi-prefix=",
"argID": "MINIMAP2_TEMP_FILE",
"isDependentOn": "null",
"hasFlag": true,
"flagOnly": false,
"required": false,
"isFile": true
},
{
"argName": "reference index",
"argValue": null,
Expand Down

0 comments on commit 439713a

Please sign in to comment.