Skip to content

Commit

Permalink
fix outpudir issue with annotate; add pid to logfile to avoid collision
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Palmer committed Aug 2, 2019
1 parent 1931635 commit 8ad5165
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 68 deletions.
34 changes: 11 additions & 23 deletions bin/funannotate-functional.py
Expand Up @@ -349,7 +349,7 @@ def parseEggNoggMapper(input, output, GeneDict):

#start here rest of script
#create log file
log_name = 'funannotate-annotate.log'
log_name = 'funannotate-annotate.'+str(os.getpid())+'.log'
if os.path.isfile(log_name):
os.remove(log_name)

Expand Down Expand Up @@ -444,12 +444,14 @@ def parseEggNoggMapper(input, output, GeneDict):
sys.exit(1)
else:
outputdir = args.out
#create outputdir and subdirs
if not os.path.isdir(outputdir):
os.makedirs(outputdir)
os.makedirs(os.path.join(outputdir, 'annotate_misc'))
os.makedirs(os.path.join(outputdir, 'annotate_results'))
os.makedirs(os.path.join(outputdir, 'logfiles'))
if os.path.isdir(outputdir):
lib.log.error("Output directory %s already exists, will use any existing data. If this is not what you want, exit, and provide a unique name for output folder" % (outputdir))
#create outputdir and subdirs if not already present
lib.createdir(outputdir)
lib.createdir(os.path.join(outputdir, 'annotate_misc'))
lib.createdir(os.path.join(outputdir, 'annotate_results'))
lib.createdir(os.path.join(outputdir, 'logfiles'))

if not args.genbank:
if not args.fasta or not args.gff:
lib.log.error("You did not specifiy the apropriate input files, either: \n1) GenBank \n2) Genome FASTA + GFF3")
Expand All @@ -465,21 +467,7 @@ def parseEggNoggMapper(input, output, GeneDict):
prefix = args.rename.replace('_', '')
lib.log.info("Parsing annotation and preparing annotation files.")
GeneCounts = lib.convertgff2tbl(GFF, prefix, Scaffolds, Proteins, Transcripts, annotTBL)
else:
#create output directories
if not os.path.isdir(outputdir):
os.makedirs(outputdir)
os.makedirs(os.path.join(outputdir, 'annotate_misc'))
os.makedirs(os.path.join(outputdir, 'annotate_results'))
os.makedirs(os.path.join(outputdir, 'logfiles'))
else:
lib.log.error("Output directory %s already exists, will use any existing data. If this is not what you want, exit, and provide a unique name for output folder" % (outputdir))
if not os.path.isdir(os.path.join(outputdir, 'annotate_misc')):
os.makedirs(os.path.join(outputdir, 'annotate_misc'))
if not os.path.isdir(os.path.join(outputdir, 'annotate_results')):
os.makedirs(os.path.join(outputdir, 'annotate_results'))
if not os.path.isdir(os.path.join(outputdir, 'logfiles')):
os.makedirs(os.path.join(outputdir, 'logfiles'))
else:
genbank = args.genbank
Scaffolds = os.path.join(outputdir, 'annotate_misc', 'genome.scaffolds.fasta')
Proteins = os.path.join(outputdir, 'annotate_misc', 'genome.proteins.fasta')
Expand Down Expand Up @@ -1290,4 +1278,4 @@ def parseEggNoggMapper(input, output, GeneDict):
if os.path.isfile(log_name):
if not os.path.isdir(os.path.join(outputdir, 'logfiles')):
os.makedirs(os.path.join(outputdir, 'logfiles'))
os.rename(log_name, os.path.join(outputdir, 'logfiles', log_name))
os.rename(log_name, os.path.join(outputdir, 'logfiles', 'funannotate-annotate.log'))
17 changes: 8 additions & 9 deletions dockerbuild/Dockerfile-base
Expand Up @@ -27,19 +27,18 @@ COPY repeatmodeler.txt \

WORKDIR /home/linuxbrew

RUN wget --quiet https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O ~/miniconda.sh && \
RUN wget --quiet https://repo.continuum.io/miniconda/Miniconda2-4.6.14-Linux-x86_64.sh -O ~/miniconda.sh && \
sudo /bin/bash ~/miniconda.sh -b -p /home/linuxbrew/conda && rm ~/miniconda.sh && sudo chown -R linuxbrew: /home/linuxbrew/conda && \
conda update -y conda && conda config --add channels r && conda config --add channels defaults && \
conda config --add channels etetoolkit && conda config --add channels conda-forge && conda config --add channels bioconda && \
conda install -y numpy pandas scipy matplotlib seaborn natsort scikit-learn psutil biopython requests snap glimmerhmm=3.0.4=pl526h0a44026_3 \
goatools fisher bedtools blat hmmer exonerate diamond tbl2asn hisat2 ucsc-pslcdnafilter stringtie perl-dbd-sqlite \
samtools raxml trimal mafft phyml kallisto bowtie2 infernal perl-threaded perl-db-file perl-bioperl perl-dbd-mysql \
conda config --add channels r && conda config --add channels defaults && \
conda config --add channels etetoolkit && conda config --add channels bioconda && conda config --add channels conda-forge && \
conda install -y numpy pandas scipy matplotlib seaborn natsort scikit-learn psutil biopython requests snap glimmerhmm \
goatools fisher bedtools blat hmmer exonerate diamond tbl2asn hisat2 ucsc-pslcdnafilter stringtie perl-dbd-sqlite perl-json \
samtools raxml trimal mafft phyml kallisto bowtie2 infernal perl-threaded perl-db-file perl-bioperl perl-dbd-mysql perl-clone \
perl-app-cpanminus mummer ete3 ete_toolchain minimap2 salmon=0.9.1 jellyfish htslib nano perl-text-soundex perl-scalar-util-numeric && \
conda clean --all && \
sudo ln -s /home/linuxbrew/conda/bin/ete3_apps/bin/raxmlHPC-PTHREADS-SSE3 /home/linuxbrew/conda/bin/ete3_apps/bin/raxmlHPC-PTHREADS && \
cpanm Getopt::Long Pod::Usage File::Basename \
Thread::Queue Carp Data::Dumper YAML Hash::Merge Logger::Simple Parallel::ForkManager \
DBI Clone JSON LWP::UserAgent && \
cpanm Getopt::Long Pod::Usage File::Basename Thread::Queue Carp Data::Dumper \
YAML Hash::Merge Logger::Simple Parallel::ForkManager DBI LWP::UserAgent && \
wget https://sourceforge.net/projects/codingquarry/files/CodingQuarry_v2.0.tar.gz && \
tar -zxvf CodingQuarry_v2.0.tar.gz && rm CodingQuarry_v2.0.tar.gz && cd CodingQuarry_v2.0 && make && cd /home/linuxbrew/ && \
wget --no-check-certificate https://tandem.bu.edu/trf/downloads/trf409.linux64 && \
Expand Down
81 changes: 45 additions & 36 deletions lib/library.py
@@ -1,5 +1,6 @@
from __future__ import division
import os, subprocess, logging, sys, argparse, inspect, csv, time, re, shutil, datetime, platform, multiprocessing, itertools, hashlib, math, types, gzip, operator, textwrap
import errno
from natsort import natsorted
from lib.interlap import InterLap
from collections import defaultdict
Expand Down Expand Up @@ -251,42 +252,50 @@ class colr:
WARN = '\033[93m'

class gzopen(object):
"""Generic opener that decompresses gzipped files
if needed. Encapsulates an open file or a GzipFile.
Use the same way you would use 'open()'.
"""
def __init__(self, fname):
f = open(fname)
# Read magic number (the first 2 bytes) and rewind.
magic_number = f.read(2)
f.seek(0)
# Encapsulated 'self.f' is a file or a GzipFile.
if magic_number == '\x1f\x8b':
self.f = gzip.GzipFile(fileobj=f)
else:
self.f = f

# Define '__enter__' and '__exit__' to use in
# 'with' blocks. Always close the file and the
# GzipFile if applicable.
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
try:
self.f.fileobj.close()
except AttributeError:
pass
finally:
self.f.close()

# Reproduce the interface of an open file
# by encapsulation.
def __getattr__(self, name):
return getattr(self.f, name)
def __iter__(self):
return iter(self.f)
def next(self):
return next(self.f)
"""Generic opener that decompresses gzipped files
if needed. Encapsulates an open file or a GzipFile.
Use the same way you would use 'open()'.
"""
def __init__(self, fname):
f = open(fname)
# Read magic number (the first 2 bytes) and rewind.
magic_number = f.read(2)
f.seek(0)
# Encapsulated 'self.f' is a file or a GzipFile.
if magic_number == '\x1f\x8b':
self.f = gzip.GzipFile(fileobj=f)
else:
self.f = f

# Define '__enter__' and '__exit__' to use in
# 'with' blocks. Always close the file and the
# GzipFile if applicable.
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
try:
self.f.fileobj.close()
except AttributeError:
pass
finally:
self.f.close()

# Reproduce the interface of an open file
# by encapsulation.
def __getattr__(self, name):
return getattr(self.f, name)
def __iter__(self):
return iter(self.f)
def next(self):
return next(self.f)

def createdir(name):
try:
os.makedirs(name)
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
pass

def softwrap2(input):
return textwrap.fill(input, width=80)
Expand Down

0 comments on commit 8ad5165

Please sign in to comment.