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

Encode #1594

Merged
merged 5 commits into from
Oct 7, 2024
Merged

Encode #1594

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions scripts/mac.app/Contents/MacOS/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
//
// main.c
// igv-launcher
//
// Created by James Robinson on 9/14/24.
//
// Launch IGV on MacOS (https://github.com/igvteam/igv).
//
// Code adapted from https://incenp.org/notes/2023/universal-java-app-on-macos.html
//

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <string.h>
#include <err.h>
#include <mach-o/dyld.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <CoreFoundation/CoreFoundation.h>


/* Remove the last n components of a pathname. The pathname
* is modified in place. Returns 0 if the requested number
* of components have been removed, -1 otherwise. */
static int remove_last_component(char *buffer , unsigned n)
{
char *last_slash = NULL;
while ( n-- > 0 ) {
if ( (last_slash = strrchr(buffer, '/')) )
*last_slash = '\0';
}
return last_slash ? 0 : -1;
}

/*
* Test if a given path exists and if it is a directory.
* It returns 1 if given path is directory and exists
* otherwise returns 0.
*/
static int isDirectoryExists(const char *path)
{
struct stat stats;
stat(path, &stats);

// Check for file existence
if (S_ISDIR(stats.st_mode))
return 1;

return 0;
}

static int simpleLauncher(int argc, char **argv)
{
char app_path[PATH_MAX];
uint32_t path_size = PATH_MAX;
int ret = 0;

(void) argc;
(void) argv;

/* Get the path to the "Contents" directory. */
if ( _NSGetExecutablePath(app_path, &path_size) == -1 )
err(EXIT_FAILURE, "Cannot get application directory");
if ( remove_last_component(app_path, 2) == -1 )
errx(EXIT_FAILURE, "Cannot get application directory");

/* Move to that directory. */
if ( chdir(app_path) == -1 )
err(EXIT_FAILURE, "Cannot change current directory");

char* cmd;

/* See if there is a bundled JDK */
if(isDirectoryExists("jdk-21")) {
char jdkPath[2048] = {'\0'};
snprintf(jdkPath, sizeof(jdkPath), "%s/jdk-21", app_path);

setenv("JAVA_HOME", jdkPath, true);

char javaPath[2048] = {'\0'};
snprintf(javaPath, sizeof(javaPath), "%s/bin/java", jdkPath);
cmd = javaPath;

printf("Using bundled JDK");

//PATH=$JAVA_HOME/bin:$PATH
} else {

cmd = "java";
printf("Using System JDK\n");
}

/* Get user defined extra arguments, if any */
char extraArgumentsPath[2048] = {'\0'};
const char *homeDir = getenv("HOME");
snprintf(extraArgumentsPath, sizeof(extraArgumentsPath), "%s/.igv/java_arguments", homeDir);

if(access(extraArgumentsPath, F_OK) == 0) {
char extraArguments[2048] = {'\0'};
snprintf(extraArguments, sizeof(extraArguments), "@%s", extraArgumentsPath);

/* Run IGV with user extra arguments */


char* args[] = {
"java",
"-showversion",
"--module-path=Java/lib",
"-Xmx8g",
"@Java/igv.args",
"-Xdock:name=IGV",
"-Xdock:icon=Resources/IGV_64.png",
"-Dapple.laf.useScreenMenuBar=true",
extraArguments,
"--module=org.igv/org.broad.igv.ui.Main",
NULL};

ret = execvp(cmd, args);
return ret;

} else {

/* Run IGV without user extra arguments */

char* args[] = {
"java",
"-showversion",
"--module-path=Java/lib",
"-Xmx8g",
"@Java/igv.args",
"-Xdock:name=IGV",
"-Xdock:icon=Resources/IGV_64.png",
"--module=org.igv/org.broad.igv.ui.Main",
NULL};

ret = execvp(cmd, args);
return ret;
}
}

int main(int argc, char **argv)
{
return simpleLauncher(argc, argv);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* THE SOFTWARE.
*/

package org.broad.igv.util.encode;
package org.broad.igv.encode;

/**
* Created by jrobinso on 6/4/15.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* THE SOFTWARE.
*/

package org.broad.igv.util.encode;
package org.broad.igv.encode;

import java.io.File;
import java.util.Collection;
Expand Down Expand Up @@ -70,11 +70,8 @@ public Collection<String> getAttributeNames() {
return attributes.keySet();
}

public boolean containsText(String filter) {
for (String value : attributes.values()) {
if (value.contains(filter)) return true;
}
return false;
public Map<String, String> getAttributes() {
return attributes;
}

boolean isSelected() {
Expand Down Expand Up @@ -108,14 +105,4 @@ public String getTrackName() {

}

/**
* Test if record has a eough of meta-data to be interpretable
*
* @return
*/
public boolean hasMetaData() {

return (attributes.containsKey("cell")) || (attributes.containsKey("antibody"));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,16 @@
* THE SOFTWARE.
*/

package org.broad.igv.util.encode;
package org.broad.igv.encode;

import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import javax.swing.table.TableStringConverter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* //wgEncodeBroadHistoneGm12878H3k4me1StdSig.bigWig
* // size=346M;
* // dateSubmitted=2009-01-05;
* // dataType=ChipSeq;
* // cell=GM12878;
* // antibody=H3K4me1;
* // control=std;
* // expId=33;
* // setType=exp;
* // controlId=GM12878/Input/std;
* // subId=2804;
* // dataVersion=ENCODE Jan 2011 Freeze;
* // dateResubmitted=2010-11-05;
* // grant=Bernstein;
* // lab=Broad;
* // view=Signal;
* // type=bigWig;
* // dccAccession=wgEncodeEH000033;
* // origAssembly=hg18
*
* @author jrobinso
* Date: 10/31/13
* Time: 10:09 PM
Expand All @@ -68,7 +43,7 @@ public class EncodeTableModel extends AbstractTableModel {
private List<EncodeFileRecord> records;
private final TableRowSorter<EncodeTableModel> sorter;

public EncodeTableModel(String [] headings, List<EncodeFileRecord> records) {
public EncodeTableModel(List<String> headings, List<EncodeFileRecord> records) {

this.records = records;

Expand All @@ -80,11 +55,10 @@ public EncodeTableModel(String [] headings, List<EncodeFileRecord> records) {
tmp.add(heading);
}
}
//tmp.add("path");
columnHeadings = tmp.toArray(new String[tmp.size()]);

columnHeadings = tmp.toArray(new String[tmp.size()]);

sorter = new TableRowSorter<EncodeTableModel>(this);
sorter = new TableRowSorter<>(this);

sorter.setStringConverter(new TableStringConverter() {
@Override
Expand Down Expand Up @@ -149,6 +123,8 @@ public void setValueAt(Object value, int row, int col) {
fireTableCellUpdated(row, col);
}



public List<EncodeFileRecord> getRecords() {
return records;
}
Expand Down
Loading
Loading