Esempio n. 1
0
def readRates( infile ):
    """read rates and G+C from a tab-separated file."""
    from rpy import r as R
    import rpy

    handle, name = tempfile.mkstemp()
    os.close(handle)
    outfile = open(name, "w")

    first = True
    headers = []
    for line in infile:
        if line[0] == "#": continue
        data = line[:-1].split("\t")
        if first:
            headers = data
            first = False
            continue

        outfile.write( line )
    outfile.close()

    assert len(headers) == 3, "malformatted file of rates, please supply id, g+c, rate"

    rpy.set_default_mode(rpy.NO_CONVERSION)
    matrix = R.read_table( name, na_string = ("NA", "na"), col_names=headers ) 
    rpy.set_default_mode(rpy.BASIC_CONVERSION)
    os.remove( name )
    return matrix, headers
Esempio n. 2
0
def readRates(infile):
    """read rates and G+C from a tab-separated file."""
    from rpy import r as R
    import rpy

    handle, name = tempfile.mkstemp()
    os.close(handle)
    outfile = open(name, "w")

    first = True
    headers = []
    for line in infile:
        if line[0] == "#":
            continue
        data = line[:-1].split("\t")
        if first:
            headers = data
            first = False
            continue

        outfile.write(line)
    outfile.close()

    assert len(
        headers) == 3, "malformatted file of rates, please supply id, g+c, rate"

    rpy.set_default_mode(rpy.NO_CONVERSION)
    matrix = R.read_table(name, na_string=("NA", "na"), col_names=headers)
    rpy.set_default_mode(rpy.BASIC_CONVERSION)
    os.remove(name)
    return matrix, headers
Esempio n. 3
0
 def cargar_texto(self, fichero, **opciones):
     """Carga los datos de un fichero de texto"""
     import os
     if not os.path.exists(fichero):
         from pyrqt.excepciones import FicheroNoExisteException
         raise FicheroNoExisteException(fichero)
     from rpy import r #pylint: disable=import-error
     datos = r.read_table(fichero, sep = opciones["delimitadoratrib"], \
             header = opciones["cabeceras"], na_strings="NA", dec=".", \
             strip_white = False)
     for nombre, columna in datos.items():
         import types
         milista = []
         if type(columna[0]) == types.IntType:
             self.ana_var(nombre, "Entero")
             for registro in columna:
                 if registro == -2147483648: #Valor nulo
                     resultado = None
                 else: 
                     resultado = int(registro)
                 milista.append(resultado)
         elif type(columna[0]) == types.StringType:
             #Es un Factor
             self.ana_var(nombre, "Factor")
             milista = columna
         elif type(columna[0]) == types.FloatType:
             self.ana_var(nombre, "Real")
             milista = columna
         else: 
             raise TypeError #R Devuelve un tipo desconocido
         for i in range(self.n_reg(), len(milista)):
             self.ana_reg()
         for i in range(self.n_reg()):
             self._portero.actual().registros()[i][nombre] = milista[i]