コード例 #1
0
 def __init__(self):
     if Config.ini:
         self.fh = Config.ini
     else:
         self.fh = get_path() + '/config/sv2.ini'
     self.json = get_path() + '/config/sv2_clf.json'
     self.fasta_chr_flag = False
     self.clfs = None
     self.gtclf = {}  # classifiers for genotyping
     self.gcfh = get_path() + '/resources/GC_content_reference.txt'
     self.gc_dict = {}
     self.resource = None  # directory to resource files
     if not os.path.isfile(self.fh):
         print 'FATAL ERROR: {} config file is missing! Please reinstall sv2: [$ pip uninstall sv2 -y && pip install sv2-VERSION.tar.gz]'.format(
             self.fh)
         sys.stderr.write(
             'FATAL ERROR: {} config file is missing! Please reinstall sv2: [$ pip uninstall sv2 -y && pip install sv2-VERSION.tar.gz]\n'
             .format(self.fh))
         sys.exit(1)
     if not os.path.isfile(self.json):
         print 'FATAL ERROR: {} json file is missing! Please reinstall sv2: [$ pip uninstall sv2 -y && pip install sv2-VERSION.tar.gz]'.format(
             self.json)
         sys.stderr.write(
             'FATAL ERROR: {} json file is missing! Please reinstall sv2: [$ pip uninstall sv2 -y && pip install sv2-VERSION.tar.gz]\n'
             .format(self.json))
         sys.exit(1)
     if not os.path.isfile(self.gcfh):
         print 'FATAL ERROR: {} file is missing! Please reinstall sv2: [$ pip uninstall sv2 -y && pip install sv2-VERSION.tar.gz]'.format(
             self.gcfh)
         sys.stderr.write(
             'FATAL ERROR: {} file is missing! Please reinstall sv2: [$ pip uninstall sv2 -y && pip install sv2-VERSION.tar.gz]\n'
             .format(self.gcfh))
         sys.exit(1)
     with open(self.json) as data_file:
         self.clfs = json.load(data_file)
コード例 #2
0
 def load_clf(self, jsonfh=None):
     import shutil
     errFH(jsonfh)
     clfs = {}
     with open(jsonfh) as f:
         clfs = json.load(f)
     realpaths = []
     for name in clfs:
         print 'loading {} classifier ...'.format(name)
         clf_dir = get_path() + '/resources/training_sets/' + name + '/'
         if not os.path.exists(clf_dir): os.makedirs(clf_dir)
         for x in clfs[name]:
             clffh = str(clfs[name][x])
             if not os.path.isfile(clffh):
                 sys.stderr.write(
                     'WARNING: {} does not exist. Please check the paths in {}\n'
                     .format(clffh, jsonfh))
             else:
                 clfname = clffh.split('/').pop()
                 newpath = clf_dir + clfname
                 clfreplace = True
                 if os.path.isfile(newpath):
                     clfreplace = query_yes_no(
                         'WARNING: {} exists... Replace?'.format(newpath),
                         'no')
                 if clfreplace == True:
                     if self.clfs.get(name) == None: self.clfs[name] = {}
                     self.clfs[name][x] = newpath
                     realpaths.append(newpath)
                     shutil.copyfile(clffh, newpath)
     for x in realpaths:
         print 'installed classifier {}'.format(x)
     print 'appending to {}... DO NOT ALTER {}'.format(self.json, self.json)
     dump_json(self.json, self.clfs)
コード例 #3
0
 def download_resource(self, ):
     install_loc = get_path() + '/resources/'
     change_loc = query_yes_no(
         'Install sv2 resource files to the default location? < {} >'.
         format(install_loc))
     if change_loc == False:
         sys.stdout.write('Enter sv2 resource file destination:\n')
         install_loc = raw_input()
         if not install_loc.endswith('/'): install_loc = install_loc + '/'
         if not os.path.isdir(install_loc):
             sys.stderr.write(
                 'FATAL ERROR: {} not a directory\n'.format(install_loc))
             sys.stdout.write(
                 'FATAL ERROR: {} not a directory\n'.format(install_loc))
             sys.exit(1)
     install_ok = query_yes_no(
         'sv2 resource files will require {} of free space in {}. Proceed with installation?'
         .format(__memsize__, install_loc))
     if install_ok == False: sys.exit(1)
     else:
         zip_file = install_loc + 'sv2_resources.zip'
         wget.download(__resource_url__, zip_file)
         zip_fh = zipfile.ZipFile(zip_file)
         if zip_fh.testzip() is not None:
             sys.stdout.write(
                 'FATAL ERROR: {} corrupted. Try <sv2 -download> again\n'.
                 format(zip_file))
             sys.stderr.write(
                 'FATAL ERROR: {} corrupted. Try <sv2 -download> again\n'.
                 format(zip_file))
             sys.exit(1)
         zip_fh.extractall(install_loc)
         zip_fh.close()
         os.remove(zip_file)
         self.resource = install_loc
         self.write_config(None, None, None)
     sys.stdout.write(
         'INSTALL COMPLETE\nRun < sv2 -hg19 FASTA [-hg38,-mm10] > to configure sv2\n'
     )
コード例 #4
0
 def write_config(self, hg19=None, hg38=None, mm10=None):
     conf = ConfigParser()
     for x in self.clfs['default']:
         clf_fh = str(self.clfs['default'][x])
         if not os.path.isfile(clf_fh):
             realpath = get_path() + '/resources/training_sets/' + clf_fh
             if os.path.isfile(realpath): self.clfs['default'][x] = realpath
             else:
                 print 'FATAL ERROR: {} pickle file not found. If this file is missing, reinstall sv2: pip uninstall sv2 -y && pip install sv2-VERSION.tar.gz'.format(
                     realpath)
                 sys.stderr.write(
                     'FATAL ERROR: {} pickle file not found. If this file is missing, reinstall sv2: pip uninstall sv2 -y && pip install sv2-VERSION.tar.gz\n'
                     .format(realpath))
                 sys.exit(1)
     dump_json(self.json, self.clfs)
     if not os.path.isfile(self.fh):
         conf_fh = open(self.fh, 'w')
         conf.add_section('FASTA_PATHS')
         conf.set('FASTA_PATHS', 'hg19', hg19)
         conf.set('FASTA_PATHS', 'hg38', hg38)
         conf.set('FASTA_PATHS', 'mm10', mm10)
         conf.set('RESOURCE_DIR', 'sv2_resource', self.resource)
         conf.write(conf_fh)
         conf_fh.close()
     else:
         conf.read(self.fh)
         if hg19 != None:
             errFH(hg19)
             conf.set('FASTA_PATHS', 'hg19', hg19)
         if hg38 != None:
             errFH(hg38)
             conf.set('FASTA_PATHS', 'hg38', hg38)
         if mm10 != None:
             errFH(mm10)
             conf.set('FASTA_PATHS', 'mm10', mm10)
         if self.resource != None:
             conf.set('RESOURCE_DIR', 'sv2_resource', self.resource)
         with open(self.fh, 'w') as conf_fh:
             conf.write(conf_fh)