def to_js(self, output="krona.html", onweb=False): if self._data_created == False: status = self.kraken_to_krona() execute("ktImportText %s -o %s" % (self.output_filename, output)) if onweb is True: import easydev easydev.onweb(output)
def gdsctools_help(name=None): if name is None: easydev.onweb('http://gdsctools.readthedocs.org') else: url = "http://gdsctools.readthedocs.org/en/master/references.html" try: url += '#module-' + name.__module__ except: print("Not a known gdsctools class or function") easydev.onweb(url)
def gdsctools_help(name=None): import easydev if name is None: easydev.onweb('http://gdsctools.readthedocs.org') else: url = "http://gdsctools.readthedocs.org/en/master/references.html" try: url += '#module-' + name.__module__ except: print("Not a known gdsctools class or function") easydev.onweb(url)
def on_web(self, identifier): """Open a tab related to the COSMIC identifier (in your browser)""" from easydev import onweb url = self._get_url(identifier) onweb(url)
def main(args=None): """Mostly checking the options provided by the user and then call :func:`sequana_init` function to create the pre-filled config file + snakemake + README +runme.sh in a dedicated project directory. """ import sequana if args is None: args = sys.argv[:] user_options = Options(prog="sequana") # If --help or no options provided, show the help if len(args) == 1: sa = Tools() sa.purple("Welcome to Sequana standalone application") logger.critical("You must use --pipeline <valid pipeline name>\nuse " "--show-pipelines or --help for more information. ") return else: options = user_options.parse_args(args[1:]) # these imports must be local. This also speed up the --help sa = Tools(verbose=options.verbose) sa.purple("Welcome to Sequana standalone application") # Those options are mutually exclusive flag = int( "%s%s%s%s%s%s" % (int(bool(options.issue)), int(bool(options.version)), int(bool(options.info)), int(bool(options.show_pipelines)), int(bool(options.pipeline)), int(bool(options.get_config))), 2) if flag not in [1, 2, 4, 8, 16, 3, 32]: logger.critical("You must use one of --pipeline, --info, " "--show-pipelines, --issue, --version, --get-config") sys.exit(1) # OPTIONS that gives info and exit if options.issue: onweb('https://github.com/sequana/sequana/issues') return if options.version: sa.purple("Sequana version %s" % sequana.version) return if options.show_pipelines: sa.purple("Valid pipeline names:") for this in sorted(valid_pipelines): m = Module(this) sa.green(" - " + this) print(textwrap(m.overview, indent=8)) return if options.info: module = Module(options.info) module.onweb() return if options.pipeline: # check validity of the pipeline name if options.pipeline not in valid_pipelines: txt = "".join([" - %s\n" % this for this in valid_pipelines]) logger.critical("%s not a valid pipeline name. Use of one:\n" % options.pipeline + txt) sys.exit(1) # copy locally the request config file from a specific pipeline if flag == 3: #--get-config and --pipeline used module = Module(options.pipeline) copy_config_from_sequana(module) return # pipeline should be defined by now. Let us start the real work here Module("dag").check("warning") Module(options.pipeline).check("warning") # If user provides file1 and/or file2, check the files exist if options.file1 and os.path.exists(options.file1) is False: raise ValueError("%s does not exist" % options.file1) if options.file2 and os.path.exists(options.file2) is False: raise ValueError("%s does not exist" % options.file2) if options.kraken and os.path.exists(options.kraken) is False: raise ValueError("%s does not exist" % options.kraken) if options.input_directory and os.path.exists( options.input_directory) is False: raise ValueError("%s does not exist" % options.input_directory) # check valid combo of arguments flag = int( "%s%s%s%s%s" % ( int(bool(options.pattern)), int(bool(options.input_directory)), int(bool(options.file1)), int(bool(options.file2)), int(bool(options.config)), ), 2) # config file has flag 1, others have flag 2,4,8,16 # config file alone : 1 # --input-directory alone: 2 # --file1 alone: 4 # --file1 + --file2 : 2+4=6 # --input-pattern alone: 16 # none of those options redirect to input_directory=local if flag not in [0, 1, 2, 4, 6, 8, 16]: logger.critical(help_input + "\n\nUse --help for more information") sys.exit(1) assert options.extension in ["fastq", "fq", "fastq.gz", "fq.gz", "bam"] # Note that we use abspath to make it more robust and easier to debug # If no options, we use input_directory and set it to "." if flag == 0 or options.input_directory: if flag == 0: options.input_directory = "." options.input_directory = os.path.abspath(options.input_directory) data = options.input_directory + os.sep + "*" + options.extension options.file1 = "" options.file2 = "" options.pattern = "" if options.verbose: logger.info("Looking for sample files matching %s" % data) elif options.pattern: options.pattern = os.path.abspath(options.pattern) data = os.path.abspath(options.pattern) options.input_directory = "" options.extension = "" options.file1 = "" options.file2 = "" elif options.config: pass elif options.file1: data = [options.file1] options.file1 = os.path.abspath(options.file1) if options.file2: data = [options.file2] options.file2 = os.path.abspath(options.file2) options.input_directory = "" options.pattern = "" options.extension = "" if options.extension == 'bam' or options.pattern.endswith('bam') or \ options.pattern.endswith('bed'): ff = FileFactory(data) else: ff = FastQFactory(data, read_tag=options.input_readtag, verbose=options.verbose) if options.pipeline == 'quality_control' or options.pipeline == 'rnaseq': # check combo flag = int( "%s%s%s%s%s" % (int(bool(options.no_adapters)), int(bool(options.design)), int(bool(options.adapters)), int(bool( options.adapter_fwd)), int(bool(options.adapter_rev))), 2) if flag not in [16, 12, 6, 4, 2, 3]: logger.critical( "You must use a design experimental file using --design" " and --adapters to indicate the type of adapters (PCRFree" " or Nextera), or provide the adapters directly as a " " string (or a file) using --adapter_fwd (AND --adapter_" "rev for paired-end data). A third way is to set --adapters" " to either Nextera, PCRFree, Rubicon or universal in which case " " all adapters will be used (slower). Finally, you may use " " --no-adapters for testing purpose or if you know there " " is no adapters") sys.exit(1) # flag 12 (design + adapters when wrong args provided) if options.design and options.adapters not in adapters_choice: raise ValueError( "When using --design, you must also " "provide the type of adapters using --adapters (set to " "one of %s )" % adapters_choice) if options.design and options.adapters: from sequana import FindAdaptersFromDesign fa = FindAdaptersFromDesign(options.design, options.adapters) fa.check() # flag 12 (design + adapters with correct args) elif options.design and options.adapters in adapters_choice: options.adapters_fwd = options.adapters options.adapters_rev = options.adapters elif options.no_adapters: options.adapter_fwd = "XXXX" options.adapter_rev = "XXXX" else: if options.adapter_fwd is None: if options.adapters not in ["universal"] + adapters_choice: msg = "Incorrect adapter choice %s. " % options.adapters msg += "Correct values are :\n" for this in ['universal'] + adapters_choice: msg += " - {}\n ".format(this) logger.error(msg) raise ValueError # flag 4 if options.adapters == "universal": options.adapter_fwd = "GATCGGAAGAGCACACGTCTGAACTCCAGTCACCGATGTATCTCGTATGCCGTCTTCTGC" options.adapter_rev = "TCTAGCCTTCTCGCAGCACATCCCTTTCTCACATCTAGAGCCACCAGCGGCATAGTAA" # flag 4 else: # Let the pipeline handle the names options.adapter_fwd = options.adapters options.adapter_rev = options.adapters # flag 2/3 else: if options.adapter_fwd: # Could be a string or a file. If a file, check the format if os.path.exists(options.adapter_fwd): AdapterReader(options.adapter_fwd) options.adapter_fwd = "file:%s" % options.adapter_fwd if options.adapter_rev: # Could be a string or a file. If a file, check the format if os.path.exists(options.adapter_rev): AdapterReader(options.adapter_rev) options.adapter_rev = "file:%s" % options.adapter_rev if options.design: # Just check the format adapter_finder = FindAdaptersFromDesign(options.design, options.adapters) # If all options are valid, we can now create the tree structure sequana_init(options)
def main(args=None): if args is None: args = sys.argv[:] user_options = Options(prog="sequana") # If --help or no options provided, show the help if len(args) == 1: user_options.parse_args(["prog", "--help"]) else: options = user_options.parse_args(args[1:]) sequana_debug_level(options.logging_level) if options.download_reference: logger.info("Downloading reference %s from %s\n" % (options.download_reference, options.database)) from bioservices.apps import download_fasta as df df.download_fasta(options.download_reference, method=options.database) if options.download_genbank is None: return if options.download_genbank: logger.info("Downloading genbank %s from %s\n" % (options.download_reference, options.database)) from sequana.snpeff import download_fasta_and_genbank download_fasta_and_genbank(options.download_genbank, options.download_genbank, genbank=True, fasta=False) return if options.genbank: assert os.path.exists(options.genbank), \ "%s does not exists" % options.genbank if options.verbose: logger.info("Reading %s. This may take time depending on " "your input file" % options.input) # Convert BAM to BED if options.input.endswith(".bam"): bedfile = options.input.replace(".bam", ".bed") if options.verbose: logger.info("Converting BAM into BED file") shellcmd("bedtools genomecov -d -ibam %s > %s" % (options.input, bedfile)) elif options.input.endswith(".bed"): bedfile = options.input else: raise ValueError("Input file must be a BAM or BED file") # Set the thresholds if options.low_threshold is None: options.low_threshold = -options.threshold if options.high_threshold is None: options.high_threshold = options.threshold # and output directory config.output_dir = options.output_directory config.sample_name = os.path.basename(options.input).split('.')[0] # Now we can create the instance of GenomeCoverage gc = GenomeCov(bedfile, options.genbank, options.low_threshold, options.high_threshold, 0.5, 0.5) # if we have the reference, let us use it if options.reference: logger.info('Computing GC content') gc.compute_gc_content(options.reference, options.w_gc, options.circular) # Now we scan the chromosomes, if len(gc.chr_list) == 1: if options.verbose: logger.warning("There is only one chromosome. Selected automatically.") chrom = gc.chr_list[0] chromosomes = [chrom] run_analysis(chrom, options, gc.feature_dict) elif options.chromosome <=-1 or options.chromosome > len(gc.chr_list): raise ValueError("invalid chromosome index ; must be in [1-{}]".format(len(gc.chr_list)+1)) else: # chromosome index is zero # For user, we start at position 1 but in python, we start at zero if options.chromosome: chromosomes = [gc[options.chromosome-1]] else: chromosomes = gc if options.verbose: print("There are %s chromosomes/contigs." % len(gc)) for this in gc.chr_list: print(" {}".format(this.chrom_name)) for i, chrom in enumerate(chromosomes): if options.verbose: print("==================== analysing chrom/contig %s/%s (%s)" % (i + options.chromosome, len(gc), chrom.chrom_name)) run_analysis(chrom, options, gc.feature_dict) if options.verbose: logger.info("Creating report in %s. Please wait" % config.output_dir) if options.chromosome: cc = options.chromosome - 1 datatable = CoverageModule.init_roi_datatable(gc[cc]) ChromosomeCoverageModule(chromosomes[0], datatable, None) page = "{0}{1}{2}.cov.html".format(config.output_dir, os.sep, chrom.chrom_name) else: CoverageModule(gc) page = "{0}{1}coverage.html".format(config.output_dir, os.sep) if options.show_html: from easydev import onweb onweb(page)
def show(self): """Opens the filename defined in the constructor""" from easydev import onweb onweb(self.output)
def onweb(self): from easydev import onweb onweb(self.settings.directory + os.sep + 'index.html')
def onweb(self): """Open the HTML document in a browser""" from easydev import onweb onweb(self.abspath)