Skip to content

Commit

Permalink
Merge branch 'release-1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobsonMT committed Mar 12, 2018
2 parents abff87b + 92fd5ec commit 7d4c92f
Show file tree
Hide file tree
Showing 20 changed files with 698 additions and 465 deletions.
29 changes: 15 additions & 14 deletions gotrack/etc/scripts/update/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def __init__(self, directory, database_state, check_ftp=True):
self.missing_go = {}
self.missing_goa = defaultdict(dict)
self.ftp_checked = False
self.missing_data = False

if check_ftp:
self.populate_missing_data()
Expand Down Expand Up @@ -80,7 +79,6 @@ def populate_missing_data(self):
self.missing_go = {}
self.missing_goa = defaultdict(dict)
self.ftp_checked = False
self.missing_data = False

go = self.fetch_go_dates()
self.missing_go = {d: f for d, f in go.iteritems() if d not in self.go and d not in self.db_go}
Expand All @@ -91,11 +89,11 @@ def populate_missing_data(self):
missing = {ed: f for ed, f in goa.iteritems() if ed not in self.goa[sp] and ed not in self.db_goa[sp_id]}
self.missing_goa[sp] = missing

if self.missing_go or sum([len(goa_sp) for goa_sp in self.missing_goa.values()]) or not self.sec_ac:
self.missing_data = True

self.ftp_checked = True

def is_missing_data(self):
return self.missing_go or sum([len(goa_sp) for goa_sp in self.missing_goa.values()]) or not self.sec_ac

@staticmethod
def match_file_patterns(files, pattern):
matches = []
Expand Down Expand Up @@ -168,7 +166,7 @@ def ftp_list(host, directory):
if ftp is not None:
ftp.close()

def ftp_files(self, host, directory, files):
def ftp_files(self, host, directory, files, skip_if_exists=True):
ftp = None
fname_list = []
if files:
Expand All @@ -188,7 +186,7 @@ def ftp_files(self, host, directory, files):
ftp.login()
ftp.cwd(directory)
full_path = os.path.join(self.directory, fname)
if os.path.isfile(full_path):
if skip_if_exists and os.path.isfile(full_path):
log.warn('%s already exists, skipping...', full_path)
continue

Expand Down Expand Up @@ -223,20 +221,23 @@ def fetch_go_dates(self):
files = Resources.ftp_list(Resources.go_ftp_host, Resources.go_ftp_directory)
return self.search_files_for_go(files)

def download_missing_goa_data(self):
def download_missing_goa_data(self, skip_if_exists=True):
for sp, goa_eds in self.missing_goa.iteritems():
files = goa_eds.values()
self.ftp_files(Resources.goa_ftp_host, Resources.goa_ftp_directory_template.format(sp.upper()), files)
self.ftp_files(Resources.goa_ftp_host, Resources.goa_ftp_directory_template.format(sp.upper()), files,
skip_if_exists)

# GPI Files
gpi_files = [Resources.goa_gpi_template.format(sp, ed) for ed in goa_eds]
self.ftp_files(Resources.goa_ftp_host, Resources.goa_ftp_directory_template.format(sp.upper()), gpi_files)
self.ftp_files(Resources.goa_ftp_host, Resources.goa_ftp_directory_template.format(sp.upper()), gpi_files,
skip_if_exists)

def download_missing_go_data(self):
self.ftp_files(Resources.go_ftp_host, Resources.go_ftp_directory, self.missing_go.values())
def download_missing_go_data(self, skip_if_exists=True):
self.ftp_files(Resources.go_ftp_host, Resources.go_ftp_directory, self.missing_go.values(), skip_if_exists)

def download_accession_history(self):
return self.ftp_files(Resources.uniprot_ftp_host, Resources.uniprot_ftp_directory, ['sec_ac.txt'])
def download_accession_history(self, skip_if_exists=True):
return self.ftp_files(Resources.uniprot_ftp_host, Resources.uniprot_ftp_directory, ['sec_ac.txt'],
skip_if_exists)

def get_new_go(self):
return {d: f for d, f in self.go.iteritems() if d not in self.db_go}
Expand Down
9 changes: 6 additions & 3 deletions gotrack/etc/scripts/update/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ def main(resource_directory=None, cron=False, no_download=False):
# Display current state of resource directory, database, and ftp site
LOG.info(res)

# if cron, force download of accession history file
res.sec_ac = None if cron else res.sec_ac

# Deal with missing data
if res.ftp_checked and res.missing_data:
if res.ftp_checked and res.is_missing_data():
missing_cnt = len(res.missing_go)
if missing_cnt:
LOG.warn("Missing %s GO Versions from FTP", missing_cnt)
Expand All @@ -64,14 +67,14 @@ def main(resource_directory=None, cron=False, no_download=False):
if not res.sec_ac:
LOG.warn("Missing secondary accession file (sec_ac.txt)")
if cron or query_yes_no("Download missing secondary accession file?"):
res.download_accession_history()
res.download_accession_history(skip_if_exists=not cron)

LOG.info("Re-checking state of resource directory")
res.populate_existing_files()
res.populate_missing_data()
LOG.info(res)

if res.missing_data or not (cron or query_yes_no("Continue with updates?")):
if res.is_missing_data() or not (cron or query_yes_no("Continue with updates?")):
return

# Insert new GO data
Expand Down
4 changes: 2 additions & 2 deletions gotrack/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>ubc.pavlab</groupId>
<artifactId>gotrack</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<version>1.1</version>
<name>gotrack</name>
<url>http://maven.apache.org</url>

Expand Down Expand Up @@ -321,7 +321,7 @@
<plugin>
<groupId>com.amashchenko.maven.plugin</groupId>
<artifactId>gitflow-maven-plugin</artifactId>
<version>1.6.0</version>
<version>1.9.0</version>
<configuration>
<!-- Do not push to remote -->
<pushRemote>false</pushRemote>
Expand Down
13 changes: 9 additions & 4 deletions gotrack/src/main/java/ubc/pavlab/gotrack/beans/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public class Cache implements Serializable {
private Map<String, Gene> accessionToGene = new ConcurrentHashMap<>();

// Useful derived constants
private ImmutableSet<Integer> availableYears;
private ImmutableList<Integer> availableYears;

// These are used for autocompletion
// *********************************
Expand Down Expand Up @@ -218,7 +218,7 @@ public AnnotationType[] getAnnotationTypes() {
return AnnotationType.values();
}

public ImmutableSet<Integer> getAvailableYears() {
public ImmutableList<Integer> getAvailableYears() {
return availableYears;
}

Expand Down Expand Up @@ -293,7 +293,7 @@ private void createEditions( CacheDAO cacheDAO ) {
}

// Populate derived constants
ImmutableSet.Builder<Integer> availableYearsBuilder = ImmutableSet.builder();
Set<Integer> availableYearsBuilder = Sets.newHashSet();

// Create Edition objects
for ( EditionDTO dto : cacheDAO.getAllEditions( speciesRestrictions ) ) {
Expand Down Expand Up @@ -349,7 +349,12 @@ private void createEditions( CacheDAO cacheDAO ) {
}
}

availableYears = availableYearsBuilder.build();
List<Integer> sortedYears = Lists.newArrayList(availableYearsBuilder);
Collections.sort(sortedYears);

availableYears = ImmutableList.copyOf( sortedYears );

// ImmutableSet.Builder<Integer> availableYearsBuilder = ImmutableSet.builder();

currentGOEdition = Collections.max( allGOEditions.values() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public String getLabel() {
@Inject
private EnrichmentService enrichmentService;

@Inject
private SessionManager session;

// View parameters
private Gene queryGene;
// LEE_LIVER_CANCER
Expand Down Expand Up @@ -217,7 +220,7 @@ public EnrichmentView() {
@PostConstruct
public void postConstruct() {
log.info( "postConstruct" );
currentSpecies = cache.getSpecies( 7 );
currentSpecies = session.getSpecies();

for ( Species species : cache.getSpeciesList() ) {
speciesToSelectedGenes.put( currentSpecies, Lists.<Gene>newArrayList() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public void init() {
// You can do here your initialization thing based on managed properties, if necessary.
log.info( "SessionManager init" );
species = cache.getSpecies( 7 );
if ( species == null) {
species = cache.getSpeciesList().iterator().next();
}
}

@PreDestroy
Expand Down
1 change: 1 addition & 0 deletions gotrack/src/main/java/ubc/pavlab/gotrack/beans/Trends.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public void postConstruct() {
}

public void loadCharts( Species species ) {
RequestContext.getCurrentInstance().addCallbackParam( "species", species );
RequestContext.getCurrentInstance().addCallbackParam( "HC_map", allChartsJSON.get( species ) );
}

Expand Down
Loading

0 comments on commit 7d4c92f

Please sign in to comment.