def check_index(self): """ Check self.index exists Returns ------- bool True if index exists. """ if hasattr(self, 'index'): return (pu.check_hisatindex(self.index)) else: return False
def __init__(self, hisat2_index="", **kwargs): super().__init__() self.programName = "hisat2" #check if hisat2 exists if not pe.check_dependencies([self.programName]): raise Exception("ERROR: " + self.programName + " not found.") self.valid_args = [ '-x', '-1', '-2', '-U', '--sra-acc', '-S', '-q', '--qseq', '-f', '-r', '-c', '-s', '-u', '-5', '-3', '--phred33', '--phred64', '--int-quals', '--sra-acc', '--n-ceil', '--ignore-quals', '--nofw', '--norc', '--pen-cansplice', '--pen-noncansplice', '--pen-canintronlen', '--pen-noncanintronlen', '--min-intronlen', '--max-intronlen', '--known-splicesite-infile', '--novel-splicesite-outfile', '--novel-splicesite-infile', '--no-temp-splicesite', '--no-spliced-alignment', '--rna-strandness', '--tmo', '--dta', '--dta-cufflinks', '--avoid-pseudogene', '--no-templatelen-adjustment', '--mp', '--sp', '--no-softclip', '--np', '--rdg', '--rfg', '--score-min', '-k', '-I', '-X', '--fr', '--rf', '--ff', '--no-mixed', '--no-discordant', '-t', '--un', '--al', '--un-conc', '--al-conc', '--un-gz', '--summary-file', '--new-summary', '--quiet', '--met-file', '--met-stderr', '--met', '--no-head', '--no-sq', '--rg-id', '--rgit-sec-seq', '-o', '-p', '--reorder', '--mm', '--qc-filter', '--seed', '--non-deterministic', '--remove-chrname', '--add-chrname', '--version' ] #initialize the passed arguments self.passedArgumentDict = kwargs #if index is passed, update the passed arguments if len(hisat2_index) > 0 and pu.check_hisatindex(hisat2_index): print("HISAT2 index is: " + hisat2_index) self.hisat2_index = hisat2_index self.passedArgumentDict['-x'] = self.hisat2_index self.index = self.hisat2_index else: print( "No Hisat2 index provided. Please build index now to generate an index using build_Index()...." )
def build_index(self, index_path, index_name, *args, threads=None, overwrite=False, verbose=False, quiet=False, logs=True, objectid="NA", **kwargs): """Build a hisat index with given parameters and saves the new index to self.hisat2_index. Parameters ---------- index_path: string Path where the index will be created index_name: string A name for the index args: tuple Path to reference input files threads: int Num threads to use verbose : bool Print stdout and std error quiet : bool Print nothing logs : bool Log this command to pyrpipe logs objectid : string Provide an id to attach with this command e.g. the SRR accession. This is useful for debugging, benchmarking and reports. kwargs: dict Parameters for the hisat2-build command :return: Returns the status of hisat2-build :rtype: bool """ #check input references if len(args) < 1: pu.print_boldred( "No reference sequence provided to hisat2-build. Exiting") return False if not pu.check_files_exist(*args): pu.print_boldred( "Please check input reference sequences provided to hisat2-build. Exiting" ) return False print("Building hisat index...") hisat2Buildvalid_args = [ '-c', '--large-index', '-a', '-p', '--bmax', '--bmaxdivn', '--dcv', '--nodc', '-r', '-3', '-o', '-t', '--localoffrate', '--localftabchars', '--snp', '--haplotype', '--ss', '--exon', '--seed', '-q', '-h', '--usage', '--version' ] #create the out dir if not pu.check_paths_exist(index_path): if not pu.mkdir(index_path): print( "ERROR in building hisat2 index. Failed to create index directory." ) return False if not overwrite: #check if files exists if pu.check_hisatindex(os.path.join(index_path, index_name)): print("Hisat2 index with same name already exists. Exiting...") self.hisat2_index = os.path.join(index_path, index_name) return True #handle threads if not threads: threads = self.threads hisat2Build_Cmd = ['hisat2-build'] newOpts = {"-p": str(threads)} mergedOpts = {**newOpts, **kwargs} #add options hisat2Build_Cmd.extend( pu.parse_unix_args(hisat2Buildvalid_args, mergedOpts)) #add input files hisat2Build_Cmd.append(str(",".join(args))) #add dir/basenae hisat2Build_Cmd.append(os.path.join(index_path, index_name)) #print("Executing:"+str(" ".join(hisat2Build_Cmd))) #start ececution status = pe.execute_command(hisat2Build_Cmd, verbose=verbose, quiet=quiet, logs=logs, objectid=objectid) if not status: pu.print_boldred("hisatBuild failed") return False #check index files if not pu.check_hisatindex(os.path.join(index_path, index_name)): pu.print_boldred("hisatBuild failed") return False #set the index path self.hisat2_index = os.path.join(index_path, index_name) #return status return True
def check_index(self): if hasattr(self, 'hisat2_index'): return (pu.check_hisatindex(self.hisat2_index)) else: return False
def build_index(self, index_path, genome, objectid="NA"): """Build a hisat index with given parameters and saves the new index to self.index. Parameters ---------- index_path: string Path where the index will be created genome: string Path to the reference genome objectid : string Provide an id to attach with this command e.g. the SRR accession. This is useful for debugging, benchmarking and reports. :return: Returns the status of hisat2-build :rtype: bool """ #if index already exists then exit if not _force: #check if files exists if pu.check_hisatindex(index_path): pu.print_green( "Hisat2 index {} already exists.".format(index_path)) self.index = os.path.join(index_path) return True #check input files if not pu.check_files_exist(genome): pu.print_boldred( "Please provide a valid input fasta file to build Hisat2 index" ) raise ValueError("Please check input to hisat2 build index") indexdir = pu.get_file_directory(index_path) #create the out dir if not pu.check_paths_exist(indexdir): if not pu.mkdir(indexdir): raise OSError( "Error creating hisat2 index. Failed to create index directory." ) hisat2Buildvalid_args = valid_args._args_HISAT2BUILD args = (genome, index_path) internal_kwargs = {"-p": self._threads} #read build parameters yamlfile = os.path.join(_params_dir, 'hisat2_index.yaml') if pu.check_files_exist(yamlfile): yaml_params = pl.YAML_loader(yamlfile) yaml_kwargs = yaml_params.get_kwargs() internal_kwargs = {**yaml_kwargs, **internal_kwargs} #add positional args internal_kwargs['--'] = args hisat2Build_Cmd = ['hisat2-build'] hisat2Build_Cmd.extend( pu.parse_unix_args(hisat2Buildvalid_args, internal_kwargs)) #execute command status = pe.execute_command(hisat2Build_Cmd, objectid=objectid) if status: if pu.check_hisatindex(index_path) and not _dryrun: #update object's index self.index = index_path if self.check_index(): return True else: raise OSError("Error building Hisat2 index") return True