Create an index on the fasta file compatible with bowtie2.
972799
def index_bowtie(self):
        """"""
        # It returns exit code 1 if the fasta is empty #
        assert self
        # Call the bowtie executable #
        sh.bowtie2_build(self.path, self.path)
        return FilePath(self.path + '.1.bt2')
985513
def assemble_pairs(p, pf, tag, target=["final.contigs.fasta"]):
    
    slink(p, pf, tag)
    assemble_dir(pf, target)
436370
def _createIndexRti(self, index, nodeName):
        
        return PandasIndexRti(index=index, nodeName=nodeName, fileName=self.fileName,
                              iconColor=self._iconColor)
999631
def create_index(group, chunk_size, compression=None, compression_opts=None):
    """"""
    dtype = np.int64
    if chunk_size == 'auto':
        chunks = True
    else:
        chunks = (nb_per_chunk(np.dtype(dtype).itemsize, 1, chunk_size),)

    group.create_dataset(
        'index', (0,), dtype=dtype,
        chunks=chunks, maxshape=(None,),
        compression=compression, compression_opts=compression_opts)
1106032
def _index_document(self, identifier, force=False):
        

        query = text("""
            INSERT INTO identifier_index(identifier, type, name)
            VALUES(:identifier, :type, :name);
        """)
        self.execute(query, **identifier)
563654
def _load_fast(filename):
        """"""
        it = json.load(open("{}_items.json".format(filename)))
        words, unk_index, name = it["items"], it["unk_index"], it["name"]
        vectors = np.load(open("{}_vectors.npy".format(filename), 'rb'))
        return words, unk_index, name, vectors
575773
private void createIndex(long idleTime) {
        try {
            this.sessions.createIndex(
                    new Document(SESSION_TTL, 1),
                    new IndexOptions()
                    .expireAfter(idleTime, TimeUnit.SECONDS)
                    .name(SESSION_INDEX_NAME));
        } catch (MongoException ex) {//update idle time
            this.sessions.dropIndex(SESSION_INDEX_NAME);
            this.sessions.createIndex(
                    new Document(SESSION_TTL, 1),
                    new IndexOptions()
                    .expireAfter(idleTime, TimeUnit.SECONDS)
                    .name(SESSION_INDEX_NAME));
        }
    }
433755
def index(ctx, view):
    """"""
    adapter = ctx.obj['adapter']
    if view:
        click.echo(adapter.indexes())
        return
    adapter.ensure_indexes()
710082
def align(fastq_file, pair_file, ref_file, names, align_dir, data,
          extra_args=None):
    
    num_hits = 1
    if data["analysis"].lower().startswith("smallrna-seq"):
        num_hits = 1000
    config = data['config']
    out_file = os.path.join(align_dir, "{0}-sort.bam".format(dd.get_sample_name(data)))
    if data.get("align_split"):
        final_file = out_file
        out_file, data = alignprep.setup_combine(final_file, data)
        fastq_file, pair_file = alignprep.split_namedpipe_cls(fastq_file, pair_file, data)
    else:
        final_file = None
        if fastq_file.endswith(".gz"):
            fastq_file = "<(gunzip -c %s)" % fastq_file
            if pair_file:
                pair_file = "<(gunzip -c %s)" % pair_file

    if not utils.file_exists(out_file) and (final_file is None or not utils.file_exists(final_file)):
        with postalign.tobam_cl(data, out_file, pair_file is not None) as (tobam_cl, tx_out_file):
            cl = [config_utils.get_program("bowtie", config)]
            cl += _bowtie_args_from_config(data)
            cl += extra_args if extra_args is not None else []
            cl += ["-q",
                   "-v", 2,
                   "-k", num_hits,
                   "-X", 2000, # default is too selective for most data
                   "--best",
                   "--strata",
                   "--sam",
                   ref_file]
            if pair_file:
                cl += ["-1", fastq_file, "-2", pair_file]
            else:
                cl += [fastq_file]
            cl = [str(i) for i in cl]
            fix_rg_cmd = r"samtools addreplacerg -r '%s' -" % novoalign.get_rg_info(data["rgnames"])
            if fix_rg_cmd:
                cmd = " ".join(cl) + " | " + fix_rg_cmd + " | " + tobam_cl
            else:
                cmd = " ".join(cl) + " | " + tobam_cl
            do.run(cmd, "Running Bowtie on %s and %s." % (fastq_file, pair_file), data)
    return out_file
143913
def create_index(self):
        
        self.reset()
        counter = 0
        pre_time = time.time()
        while True:
            if counter % 1000 == 0:
                cur_time = time.time()
                print('time:', cur_time - pre_time, ' count:', counter)
            pos = self.tell()
            cont = self.read()
            if cont is None:
                break
            key = self.key_type(counter)
            self.fidx.write('%s\t%d\n'%(str(key), pos))
            counter = counter + 1
1089341
def align(fastq_file, pair_file, index_dir, names, align_dir, data):
    
    umi_ext = "-cumi" if "umi_bam" in data else ""
    out_file = os.path.join(align_dir, "{0}-sort{1}.bam".format(dd.get_sample_name(data), umi_ext))
    num_cores = data["config"]["algorithm"].get("num_cores", 1)
    rg_info = novoalign.get_rg_info(names)
    preset = "sr"

    pair_file = pair_file if pair_file else ""
    if data.get("align_split"):
        final_file = out_file
        out_file, data = alignprep.setup_combine(final_file, data)
        fastq_file, pair_file = alignprep.split_namedpipe_cls(fastq_file, pair_file, data)
    else:
        final_file = None

    if not utils.file_exists(out_file) and (final_file is None or not utils.file_exists(final_file)):
        with postalign.tobam_cl(data, out_file, pair_file != "") as (tobam_cl, tx_out_file):
            index_file = None
            # Skip trying to use indices now as they provide only slight speed-ups
            # and give inconsitent outputs in BAM headers
            # If a single index present, index_dir points to that
            # if index_dir and os.path.isfile(index_dir):
            #     index_dir = os.path.dirname(index_dir)
            #     index_file = os.path.join(index_dir, "%s-%s.mmi" % (dd.get_genome_build(data), preset))
            if not index_file or not os.path.exists(index_file):
                index_file = dd.get_ref_file(data)
            cmd = ("minimap2 -a -x {preset} -R '{rg_info}' -t {num_cores} {index_file} "
                   "{fastq_file} {pair_file} | ")
            do.run(cmd.format(**locals()) + tobam_cl, "minimap2 alignment: %s" % dd.get_sample_name(data))
    data["work_bam"] = out_file
    return data
622562
def bowtie(self):
        
        for i in range(self.cpus):
            # Send the threads to the merge method. :args is empty as I'm using
            threads = Thread(target=self.align, args=())
            # Set the daemon to true - something to do with thread management
            threads.setDaemon(True)
            # Start the threading
            threads.start()
        with progressbar(self.metadata) as bar:
            for sample in bar:
                # Initialise the mapping GenObject
                sample.mapping = GenObject()
                # Set an easier to write shortcut for sample.general
                sagen = sample.general
                if sagen.bestassemblyfile != "NA":
                    sagen.QualimapResults = os.path.join(sagen.outputdirectory, 'qualimap_results')
                    # Set the results folder
                    # Create this results folder if necessary
                    make_path(sagen.QualimapResults)
                    # Set file names
                    sagen.sortedbam = os.path.join(sagen.QualimapResults, '{}_sorted.bam'.format(sample.name))
                    filenoext = os.path.splitext(sagen.filteredfile)[0]
                    sagen.filenoext = filenoext
                    sagen.bowtie2results = os.path.join(sagen.QualimapResults, sample.name)
                    # Use fancy new bowtie2 wrapper
                    bowtie2build = Bowtie2BuildCommandLine(reference=sagen.bestassemblyfile,
                                                           bt2=sagen.bowtie2results)
                    sample.mapping.BamFile = sagen.bowtie2results + "_sorted.bam"
                    # SAMtools sort v1.3 has different run parameters
                    samsort = SamtoolsSortCommandline(input=sample.mapping.BamFile,
                                                      o=True,
                                                      out_prefix="-")
                    samtools = [SamtoolsViewCommandline(b=True, S=True, input_file="-"), samsort]
                    indict = {'D': 5, 'R': 1, 'num_mismatches': 0, 'seed_length': 22, 'i_func': "S,0,2.50"}
                    #  Update the dictionary with the appropriate parameters for paired- vs. single-ended assemblies
                    try:
                        _ = sample.general.mergedreads
                        if len(sample.general.trimmedcorrectedfastqfiles) == 2:
                            indict.update({'m1': sample.general.trimmedcorrectedfastqfiles[0],
                                           'm2': sample.general.trimmedcorrectedfastqfiles[1]})
                        else:
                            indict.update({'U': sample.general.trimmedcorrectedfastqfiles[0]})
                    except AttributeError:
                        if len(sample.general.assemblyfastq) == 2:
                            indict.update({'m1': sample.general.assemblyfastq[0],
                                           'm2': sample.general.assemblyfastq[1]})
                        else:
                            indict.update({'U': sample.general.assemblyfastq[0]})
                    bowtie2align = Bowtie2CommandLine(bt2=sagen.bowtie2results,
                                                      threads=self.threads,
                                                      samtools=samtools,
                                                      **indict)

                    # Convert the commands to strings to allow them to be JSON serialized
                    sample.commands.bowtie2align = str(bowtie2align)
                    sample.commands.bowtie2build = str(bowtie2build)
                    self.bowqueue.put((sample, sample.commands.bowtie2build, sample.commands.bowtie2align))
                else:
                    sample.commands.samtools = "NA"
                    sample.mapping.MeanInsertSize = 'NA'
                    sample.mapping.MeanCoveragedata = 'NA'
        self.bowqueue.join()
103150
def create_index(self, name, recreate=False, _type='default'):
        
        if name not in self.indexes or recreate:
            self.build_index(name, _type)
87326
def load_fasta_file(filename):
    

    with open(filename, "r") as handle:
        records = list(SeqIO.parse(handle, "fasta"))
    return records
1331205
function createIndices(callback) {
      const q = queue();
      geojson_files.forEach((gj) => {
        q.defer(createIndex, gj);
      });

      q.awaitAll((err) => {
        if (err) return callback(err);
        return callback();
      });
    }
466037
def write_index(self):
        """"""
        self.fileobj.seek(self.last_offset)
        index = index_header.build(dict(entries=self.entries))
        self.fileobj.write(index)
        self.filesize = self.fileobj.tell()
319485
def tofasta(args):
    
    p = OptionParser(tofasta.__doc__)
    p.add_option("--prefix", default="gbfasta",
            help="prefix of output files [default: %default]")
    filenames, accessions, idfile, opts, args = preparegb(p, args)
    prefix = opts.prefix

    GenBank(filenames=filenames, accessions=accessions, idfile=idfile).\
        write_fasta(output=prefix, individual=opts.individual)

    if opts.individual:
        logging.debug("Output written dir {0}".format(prefix))
    else:
        logging.debug("Output written to {0}.fasta".format(prefix))