Exemplo n.º 1
0
def decmin_to_decdeg(pos, return_string=False):
    #    print type(pos),pos
    try:
        if utils.is_sequence(pos):
            output = []
            for p in pos:
                #                 print p, type(p)
                p = float(p)
                if p >= 0:
                    output.append(np.floor(p / 100.) + (p % 100) / 60.)
                else:
                    output.append(np.ceil(p / 100.) - (-p % 100) / 60.)
        else:
            pos = float(pos)
            if pos >= 0:
                output = np.floor(pos / 100.) + (pos % 100) / 60.
            else:
                output = np.ceil(pos / 100.) - (-pos % 100) / 60.

        if return_string:
            if utils.is_sequence(output):
                #                 print 'if-if'
                return map(unicode, output)
            else:
                #                 print 'if-else'
                return unicode(output)
        else:
            #             print 'else'
            return output
    except:
        return pos
Exemplo n.º 2
0
def data_type(obj):
    """Identify format of data object. Returns `str` or `None`"""
    # inspired by pyqtgraph.graphicsitems.PlotDataItem
    logger.debug(f"data_type {type(obj), repr(obj)}")
    if obj is None:
        return None
    if isinstance(obj, DictArray):
        return 'DictArray'
    if hasattr(obj, '__len__'):
        if isinstance(obj, np.ndarray):
            pass
        elif len(obj) == 0:
            return 'empty'
    if isinstance(obj, dict):
        first = obj[list(obj.keys())[0]]
        if utils.is_sequence(first):
            return 'dictOfLists'
        else:
            return 'dictOfValues'
    if utils.is_sequence(obj):
        # if (hasattr(obj, 'implements') and obj.implements('MetaArray')):
        #     return 'MetaArray'
        if isinstance(obj, np.ndarray):
            if obj.ndim <= 1:
                if obj.dtype.names is None:
                    return 'listOfValues'
                elif obj.dtype.names:
                    return 'recarray'
            # elif obj.ndim == 2 and obj.dtype.names is None and obj.input[1] == 2:
            #     return 'Nx2array'
            elif obj.ndim == 2:
                if obj.dtype.names is None:
                    return 'ndarray'
                else:
                    return 'recarray'
            else:
                raise Exception(
                    'array input must be (N points, N keys); got %s instead' %
                    str(obj.shape))

        first = obj[0]

        if isinstance(first, dict):
            return 'listOfDicts'
        elif utils.is_sequence(first):
            if isinstance(first, np.ndarray) and first.ndim == 0:
                return 'listOfValues'
            else:
                return 'listOfLists'
        else:
            return 'listOfValues'
    raise NotImplementedError(f"Unknown data_type, {repr(obj)}")
Exemplo n.º 3
0
def p_listadecl(t):
    ''' listadecl : tipo listaids SEMI '''
    if t[2]:
        logger.debug(
            "listadecl : tipo listaids SEMI Tipo de t[2] es {t}".format(
                t=type(t[2])))
        if is_sequence(t[2]):
            l = []
            for x in t[2]:
                logger.debug(
                    "x en t[2] es de tipo {t} y tiene valor {v}".format(
                        t=type(x), v=x))
                var = DeclaracionNodo(get_decl_total(t[1], x),
                                      delete_brackets(x),
                                      en_declvariables=True,
                                      tam_nodo=numeros_bracket(x))
                l.append(var)
                logger.debug("Listadecl es : {}".format(t[0]))
            t[0] = l
        else:
            t[0] = [
                DeclaracionNodo(get_decl_total(t[1], t[2]),
                                delete_brackets(t[2]),
                                en_declvariables=True,
                                tam_nodo=numeros_bracket(t[2]))
            ]
    else:
        logger.warning("listadecl: listaids vacia")
Exemplo n.º 4
0
    def __init__(self, email, password, roles=None):
        self.email = email.lower()

        # If only a string is passed for roles, convert it to a list containing
        # that string
        if roles and isinstance(roles, basestring):
            roles = [roles]

        # If a sequence is passed for roles (or if roles has been converted to
        # a sequence), fetch the corresponding database objects and make a list
        # of those.
        if roles and is_sequence(roles):
            role_list = []
            for role in roles:
                role_list.appen(Role.query.filter_by(name=role).first())
            self.roles = role_list
        # Otherwise, assign the default 'user' role. Create that role if it
        # doesn't exist.
        else:
            r = Role.query.filter_by(name='user').first()
            if not r:
                r = Role('user')
                db.session.add(r)
                db.session.commit()
            self.roles = [r]

        self.set_password(password)
Exemplo n.º 5
0
def decdeg_to_decmin(pos, string_type=False, decimals=False):
    # TODO, add if else for negative position (longitude west of 0 degrees)
    if utils.is_sequence(pos):
        output = []
        for p in pos:
            p = float(p)
            deg = np.floor(p)
            minut = p % deg * 60.0
            if string_type:
                if decimals is not False:
                    output.append('%%2.%sf' % decimals % (deg * 100.0 + minut))
                else:
                    output.append(unicode(deg * 100.0 + minut))
            else:
                output.append(deg * 100.0 + minut)
    else:
        pos = float(pos)
        deg = np.floor(pos)
        minut = pos % deg * 60.0
        if string_type:
            if decimals is not False:
                output = ('%%2.%sf' % decimals % (deg * 100.0 + minut))
            else:
                output = (unicode(deg * 100.0 + minut))
        else:
            output = (deg * 100.0 + minut)

    return output
Exemplo n.º 6
0
def check_lists_in_dict(filter_dict, use_string=False):
    for key in filter_dict:
        if not utils.is_sequence(filter_dict[key]):
            if type(filter_dict[key]) == str and use_string:
                pass
            else:
                filter_dict[key] = [filter_dict[key]]
    return filter_dict
Exemplo n.º 7
0
 def brackets_necesarias(self):
     logger.debug("Calculando las brackets necesarias")
     if not is_sequence(self.tam_vec):
         logger.debug("No necesitamos ninguna")
         return 0
     ret = len(self.tam_vec)
     logger.debug("{} pares necesarios".format(ret))
     return ret
Exemplo n.º 8
0
 def esta_en_limites(self, posicion):
     logger.debug("Calculando si simbolo esta en limites")
     if not is_sequence(self.tam_vec):
         logger.debug("No esta en secuencia, retornamos True")
         return True
     ret = esta_en_limites(posicion, self.tam_vec)
     if ret:
         logger.debug("Esta en limites")
     else:
         logger.debug("No esta en limites")
     return ret
Exemplo n.º 9
0
    def register(cls):
        """ called by subclass to allow Input() constructor to find and return that subclass """
        if cls is Input:
            return None
        if not cls.subtypes:
            l_logger.error("A location must define its types: {}".format(cls.name))
            raise ValueError("{} has no 'types', unable to register".format(cls.name))
   
        if not is_sequence(cls.subtypes):
            cls.subtypes = (cls.subtypes, )
        for subtype in cls.subtypes:
            Input.types[subtype]= cls

        h_logger.info("Input: {} registered for {}".format(cls.__name__, cls.subtypes))
        return True
Exemplo n.º 10
0
 def dump(self, indent=0, max_level=100, sp_per_level=4):
     spaces = ' ' * (indent * sp_per_level)
     print(spaces + self._print_clase_hoja())
     spaces = ' ' * (indent * (sp_per_level + 1))
     if indent < max_level:
         for val in self.hijos:
             if is_sequence(val):
                 for v in val:
                     if not isinstance(val, str):
                         v.dump(indent + 1)
                     else:
                         print(spaces + val)
             else:
                 if not isinstance(val, str):
                     val.dump(indent + 1)
                 else:
                     print(spaces + val)
Exemplo n.º 11
0
    fetch_index = args.index
    aspera = args.aspera
    aspera_settings = args.aspera_settings

    if aspera or aspera_settings is not None:
        aspera = utils.set_aspera(aspera_settings)

    try:
        if utils.is_wgs_set(accession):
            if output_format is not None:
                sequenceGet.check_format(output_format)
            sequenceGet.download_wgs(dest_dir, accession, output_format)
        elif not utils.is_available(accession):
            sys.stderr.write('ERROR: Record does not exist or is not available for accession provided\n')
            sys.exit(1)
        elif utils.is_sequence(accession):
            if output_format is not None:
                sequenceGet.check_format(output_format)
            sequenceGet.download_sequence(dest_dir, accession, output_format, expanded)
        elif utils.is_analysis(accession):
            if output_format is not None:
                readGet.check_read_format(output_format)
            readGet.download_files(accession, output_format, dest_dir, fetch_index, fetch_meta, aspera)
        elif utils.is_run(accession) or utils.is_experiment(accession):
            if output_format is not None:
                readGet.check_read_format(output_format)
            readGet.download_files(accession, output_format, dest_dir, fetch_index, fetch_meta, aspera)
        elif utils.is_assembly(accession):
            if output_format is not None:
                assemblyGet.check_format(output_format)
            assemblyGet.download_assembly(dest_dir, accession, output_format, fetch_wgs, extract_wgs, expanded)
Exemplo n.º 12
0
    def detect_format(file):
        logger.debug(f"detect_format {file}")
        ff = {'data': None, 'file': None, 'header': None, 'dialect': None}

        try:
            samplelines = DataFileIO.readnlines(file, 3)
        except UnicodeDecodeError as e:
            ff['file'] = 'numpy'
            logger.debug(ff)
            return None, ff

        n_samplelines = len(samplelines)

        if n_samplelines in [0, 1]:
            if n_samplelines == 0 or samplelines[0].strip(' \t\n\r') == '':
                ff['file'] = 'empty'
                logger.debug(ff)
                return [], ff

        logger.debug(samplelines)
        if samplelines[0][0] in "[({":
            try:
                sample = ast.literal_eval(samplelines[0])
                logger.debug('here')
            except SyntaxError:
                logger.debug('here')
                if samplelines[0][1] in "[({":
                    sample = ast.literal_eval(samplelines[0][1:])
                    logger.debug(f'sample {sample}')
                else:
                    # file.seek(0)
                    sample = ast.literal_eval(file.read())
                    ff['file'] = 'multiLine'
                    ff['data'] = data_type(sample)
                    return sample, ff
            if n_samplelines == 1:
                ff['file'] = 'oneLine'
            else:
                ff['file'] = 'multiLine'

            if isinstance(sample, dict):
                ff['data'] = 'dict'
                itemsample = list(sample.values())[0]
                if utils.is_sequence(itemsample):
                    ff['data'] += 'OfLists'
                elif n_samplelines == 1:
                    ff['data'] += 'OfValues'
                else:
                    ff['data'] = 'someDicts'

            elif utils.is_sequence(sample):
                ff['data'] = 'list'
                try:
                    itemsample = sample[0]
                except IndexError:
                    ff['data'] += 'OfEmpty'
                else:
                    if isinstance(itemsample, dict):
                        ff['data'] += 'OfDicts'
                    elif utils.is_sequence(itemsample):
                        ff['data'] += 'OfLists'
                    else:
                        ff['data'] = 'someLists'

            else:
                raise TypeError(type(sample), sample)
        else:
            samplestr = ''.join(samplelines)
            logger.debug(f'samplestr {samplestr}')
            try:
                ff['dialect'] = csv.Sniffer().sniff(samplestr)
                logger.debug(f"dialect {ff['dialect']}")
            except csv.Error:
                logger.debug(f'csv Error')
                if n_samplelines > 1:
                    logger.debug(f"MORE THAN ONE LINE")
                    sample_without_header = ''.join(samplelines[1:])
                    try:
                        ff['dialect'] = csv.Sniffer().sniff(
                            sample_without_header)
                    except csv.Error:
                        pass
                    else:
                        ff['header'] = samplelines[0]
            logger.debug('CHECK HEADER')
            if not ff['header']:
                try:
                    hasheader = csv.Sniffer().has_header(samplestr)
                except csv.Error:
                    logger.debug(f'DOES NOT HAVE HEADER')
                    pass
                else:
                    logger.debug(f'HAS HEADER {hasheader}')
                    ff['header'] = samplelines[0] if hasheader else None

        if ff['file'] == 'oneLine':
            logger.debug((sample, ff))
            return sample, ff
        logger.debug((None, ff))
        return None, ff
Exemplo n.º 13
0
def test_is_sequence():
    assert utils.is_sequence((1, 2))
    assert utils.is_sequence([1, 2])
    assert not utils.is_sequence('12')
Exemplo n.º 14
0
 def fertilities(self, ferts):
     if not is_sequence(ferts):
         ferts = (ferts,)
     self.__fertilities = tuple(ferts)
Exemplo n.º 15
0
    if format not in allowed_formats:
        print ('Please select a valid format for this accession: ', allowed_formats)
        sys.exit(1)

if __name__ == '__main__':
    parser = set_parser()
    args = parser.parse_args()

    accession = args.accession
    format = args.format
    dest_dir = args.dest

    try:
        if utils.is_wgs_set(accession):
            download_wgs(dest_dir, accession, format)
        elif utils.is_sequence(accession) or utils.is_coding(accession):
            if not utils.is_available(accession):
                print ('Record does not exist or is not available for accession provided')
                sys.exit(1)
            if format == utils.MASTER_FORMAT:
                print ('Invalid format. master format only available for WGS sets')
                sys.exit(1)
            download_sequence(dest_dir, accession, format)
        else:
            print ('Error: Invalid accession. A sequence or coding accession or a WGS set (prefix or master accession) must be provided')
            sys.exit(1)
        print ('Completed')
    except Exception:
        utils.print_error()
        sys.exit(1)
Exemplo n.º 16
0
 def operador(self):
     if is_sequence(self.hoja):
         return self.hoja[0]
     return self.hoja