Restore GFF3 entry to original format

        Returns:
            str: properly formatted string containing the GFF3 entry
176248
def write(self):
        

        none_type = type(None)

        # Format attributes for writing
        attrs = self.attribute_string()

        # Place holder if field value is NoneType
        for attr in self.__dict__.keys():
            if type(attr) == none_type:
                setattr(self, attr, '.')

        # Format entry for writing
        fstr = '{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}{9}'\
               .format(self.seqid, self.source, self.type, str(self.start),
                       str(self.end), self._score_str, self.strand, 
                       self.phase, attrs, os.linesep)

        return fstr
670797
def saveFormatFileTo(self, buf, encoding, format):
        
        if buf is None: buf__o = None
        else: buf__o = buf._o
        ret = libxml2mod.xmlSaveFormatFileTo(buf__o, self._o, encoding, format)
        return ret
1008508
def get_entry_text(self, fname):
        """"""
        if fname.split('.')[-1] == 'gz':
            with gz.open(fname, 'rt') as f:
                filetext = f.read()
        else:
            with codecs.open(fname, 'r') as f:
                filetext = f.read()
        return filetext
315036
def raw_to_fp(self):
        
        sort = fp.fp.FSort.from_size(self.length)
        return fp.fpToFP(self, sort)
172895
def htmlNodeDumpFileFormat(self, out, cur, encoding, format):
        
        if cur is None: cur__o = None
        else: cur__o = cur._o
        ret = libxml2mod.htmlNodeDumpFileFormat(out, self._o, cur__o, encoding, format)
        return ret
587262
def fh_to_record(self, f):
        """"""
        import unicodecsv as csv

        fn_path = self.file_name

        fr = self.record
        fr.path = fn_path
        rows = []

        # NOTE. There were two cases here, for PY2 and PY3. Py two had
        # encoding='utf-8' in the reader. I've combined them b/c that's the default for
        # unicode csv, so it shouldn't be necessary.

        # Should probably be something like this:
        #if sys.version_info[0] >= 3:  # Python 3
        #    import csv
        #    f = open(self._fstor.syspath, 'rtU', encoding=encoding)
        #    reader = csv.reader(f)
        #else:  # Python 2
        #    import unicodecsv as csv
        #    f = open(self._fstor.syspath, 'rbU')
        #    reader = csv.reader(f, encoding=encoding)

        for row in csv.reader(f):
            row = [e if e.strip() != '' else None for e in row]
            if any(bool(e) for e in row):
                rows.append(row)
        try:
            fr.update_contents(msgpack.packb(rows), 'application/msgpack')
        except AssertionError:
            raise

        fr.source_hash = self.fs_hash
        fr.synced_fs = self.fs_modtime
        fr.modified = self.fs_modtime
26353
def saveCopy(self) :
        ""
        old_key = self._key
        self.reset(self.collection)
        self.save()
        return (old_key, self._key)
1129846
def get_object_format(triple=None):
    
    if triple is None:
        triple = get_default_triple()
    res = ffi.lib.LLVMPY_GetTripleObjectFormat(_encode_string(triple))
    return _object_formats[res]
1289651
def getent(refresh=False, root=None):
    '''
    
    '''
    if 'group.getent' in __context__ and not refresh:
        return __context__['group.getent']

    ret = []
    if root is not None:
        getgrall = functools.partial(_getgrall, root=root)
    else:
        getgrall = functools.partial(grp.getgrall)

    for grinfo in getgrall():
        ret.append(_format_info(grinfo))
    __context__['group.getent'] = ret
    return ret
1007317
def result_str(self):
        
        return '{}, {}, {}'.format(LocalOnlyCounter.plural_fmt('project', self.projects),
                                   LocalOnlyCounter.plural_fmt('folder', self.folders),
                                   LocalOnlyCounter.plural_fmt('file', self.files))
712008
def format(self, version=0x10, wipe=None):
        
        return super(FelicaLite, self).format(version, wipe)
212278
def get_gaf_format(self):
        
        sep = '\t'
        return sep.join(
            [self.gene, self.db_ref, self.term.id, self.evidence,
             '|'.join(self.db_ref), '|'.join(self.with_)])
907661
def restore(self):
        
        # If there are no backup keys, do nothing...
        if len(list(self.backup.keys())) == 0:
            return
        for key in self.backup.keys():
            if key != 'WCSCDATE':
                self.__dict__[self.wcstrans[key]] = self.orig_wcs[self.backup[key]]

        self.update()
137586
def get_dexseq_gff(config, default=None):
    
    dexseq_gff = tz.get_in(tz.get_in(['dexseq_gff', 'keys'], LOOKUPS, {}),
                           config, None)
    if not dexseq_gff:
        return None
    gtf_file = get_gtf_file(config)
    if gtf_file:
        base_dir = os.path.dirname(gtf_file)
    else:
        base_dir = os.path.dirname(dexseq_gff)
    base, _ = os.path.splitext(dexseq_gff)
    gff_file = os.path.join(base_dir, base + ".gff")
    if file_exists(gff_file):
        return gff_file
    gtf_file = os.path.join(base_dir, base + ".gff3")
    if file_exists(gtf_file):
        return gtf_file
    else:
        return None
247320
def restore(self):
        
        sql_files = []
        for root, dirs, files in os.walk(self.directory):
            for f in files:
                if f.endswith(".sql.gz"):
                    path = os.path.join(self.directory, f)
                    self._run_cmd(["gunzip", path])
                    sql_files.append(f.rstrip(".gz"))

                elif f.endswith('.sql'):
                    sql_files.append(f)

        sql_files.sort() # we want to go in the order the tables were dumped
        r = re.compile('\d{3,}_([^\.]+)')
        for f in sql_files:
            path = os.path.join(self.directory, f)
            m = r.match(f)
            if m:
                table = m.group(1)
                logger.info('------- restoring table {}'.format(table))

                #psql_args = self._get_args('psql', '-X', '--echo-queries', '-f {}'.format(path))
                psql_args = self._get_args('psql', '-X', '--quiet', '--file={}'.format(path))
                self._run_cmd(psql_args)

                logger.info('------- restored table {}'.format(table))

        return True
168430
def restore(self):
        
        # NOTE: dup2 makes `self._from_fd` inheritable unconditionally
        self.redir_file.flush()
        os.dup2(self.orig_file.fileno(), self._from_fd)
1233290
def gtf_to_fasta(gtf_file, ref_fasta, cds=False, out_file=None):
    
    if out_file and file_exists(out_file):
        return out_file

    if not out_file:
        out_file = tempfile.NamedTemporaryFile(delete=False, suffix=".fa").name

    tmp_file = out_file + ".tmp"
    if cds:
        cmd = "gffread -g {ref_fasta} -x {tx_tmp_file} {gtf_file}"
    else:
        cmd = "gffread -g {ref_fasta} -w {tx_tmp_file} {gtf_file}"
    message = "Converting %s to FASTA format." % gtf_file
    with file_transaction(tmp_file) as tx_tmp_file:
        do.run(cmd.format(**locals()), message)

    transcript = ""
    skipping = False
    with file_transaction(out_file) as tx_out_file:
        with open(tmp_file) as in_handle, open(tx_out_file, "w") as out_handle:
            for line in in_handle:
                if line.startswith(">"):
                    cur_transcript = line.split(" ")[0][1:]
                    if transcript == cur_transcript:
                        logger.info("Transcript %s has already been seen, skipping this "
                                    "version." % cur_transcript)
                        skipping = True
                    else:
                        transcript = cur_transcript
                        skipping = False
                    line = ">" + transcript + "\n"
                if not skipping:
                    out_handle.write(line)
    os.remove(tmp_file)
    return out_file