Exemplo n.º 1
0
def write(data, file):
  file_existed = True if exists(file) else False
  io.write_file(
    data,
    io.absolute_path(file, __dirname),
  )
  return file_existed
Exemplo n.º 2
0
def main():
    def add_arguments(parser):
        parser.add_argument('-d', '--delim', default="\t")
        parser.add_argument('infile', type='readable_file')
        parser.add_argument('termfile', type='readable_file')
        parser.add_argument('outfile', type='writeable_file', nargs='?', default=None)
    ns = parse(add_arguments)
    
    with open(ns.infile, 'rU') as f: 
        s = f.read()
    
    for find, repl in csv_to_table(ns.termfile, ns.delim):
        s = re.sub(find, repl, s)
    
    outfile = ns.outfile or ns.infile
    write_file(outfile, s)
Exemplo n.º 3
0
def main():
    def add_arguments(parser):
        parser.add_argument('-d', '--delim', default="\t")
        parser.add_argument('infile', type='readable_file')
        parser.add_argument('termfile', type='readable_file')
        parser.add_argument('outfile',
                            type='writeable_file',
                            nargs='?',
                            default=None)

    ns = parse(add_arguments)

    with open(ns.infile, 'rU') as f:
        s = f.read()

    for find, repl in csv_to_table(ns.termfile, ns.delim):
        s = re.sub(find, repl, s)

    outfile = ns.outfile or ns.infile
    write_file(outfile, s)
Exemplo n.º 4
0
def translate(**kwargs):
    # Another way to do this is like:
    # source = 'en'
    # try:
    #     source = kwargs['source']
    # except KeyError:
    #     pass
    source = "en" if "source" not in kwargs else kwargs["source"]
    dest = "es" if "dest" not in kwargs else kwargs["dest"]
    file = None if "file" not in kwargs else kwargs["file"]
    text = None if "text" not in kwargs else kwargs["text"]
    if not text and not file:
        source = input("Enter the source language: ")
        dest = input("Enter the destination language: ")
        text = input("Enter a text to translate: ")
    elif file:
        if isinstance(file, str) and not Path(file).is_file():
            raise TranslateException("Please provide a valid path to a file")
        if isinstance(file, str) and Path(file).suffix != ".txt":
            raise TranslateException("Only .txt files are allowed")
        text = read_file(file)
    translated_text = ""
    try:
        translated_text = Translator().translate(text,
                                                 dest=dest,
                                                 source=source).text
    except ValueError as verror:
        raise TranslateException(
            "The source or destination language is invalid.") from verror
    except Exception as ex:
        raise ApiException(
            "An error ocurred while connecting with the API") from ex
    else:
        if file:
            output_file = ("data/output.txt"
                           if "output" not in kwargs else kwargs["output"])
            write_file(translated_text, output_file)
        return translated_text
Exemplo n.º 5
0
    #Revertendo a String
    alignedseq1 = alignedseq1[::-1]
    alignedseq2 = alignedseq2[::-1]

    return alignedseq1, alignedseq2


if __name__ == '__main__':
    #Definicoes dos parametros
    par = Parameters(gapopen=-10, gap=-0.5, matrix='BLOSUM62', stype='protein')

    #Sequencias
    seq1 = io.read_fasta(io.read_file("../inputs/default1.fasta"))
    seq2 = io.read_fasta(io.read_file("../inputs/default2.fasta"))

    #Matriz de apontadores
    M, Ix, Iy = global_align(seq1, seq2, par)

    #Sequencias alinhadas
    leftalignedseq1, leftalignedseq2 = traceback_left(M, Ix, Iy, seq1, seq2,
                                                      par)
    upalignedseq1, upalignedseq2 = traceback_up(M, Ix, Iy, seq1, seq2, par)

    result = Alignment(leftalignedseq1, leftalignedseq2, "LEFT")
    result.calculate_mat_mis_gaps()
    io.write_file("../outputs/locally_global_affine_output.txt", str(result))

    result = Alignment(upalignedseq1, upalignedseq2, "UP")
    result.calculate_mat_mis_gaps()
    io.append_file("../outputs/locally_global_affine_output.txt", str(result))
Exemplo n.º 6
0
def set_state(data):
  return io.write_file(
    data,
    io.absolute_path('state', __dirname, True),
  )
Exemplo n.º 7
0
        if M[i][j] == M[i][j - 1] + Parameters.gap:
            #if M[i][j-1] is not 0:
            alignedseq1 = alignedseq1 + '-'
            alignedseq2 = alignedseq2 + seq2[j - 1]
            j = j - 1
            continue

    #Revertendo a String
    alignedseq1 = alignedseq1[::-1]
    alignedseq2 = alignedseq2[::-1]

    return alignedseq1, alignedseq2


if __name__ == '__main__':

    #Definicoes dos parametros
    par = Parameters(gap=-10, matrix='BLOSUM62', stype='dna')

    seq1 = io.read_fasta(io.read_file("../inputs/default1.fasta"))
    seq2 = io.read_fasta(io.read_file("../inputs/default2.fasta"))

    matrix, i, j = local_align(seq1, seq2, par)

    alignedseq1, alignedseq2 = traceback(matrix, seq1, seq2, i, j, par)

    result = Alignment(alignedseq1, alignedseq2, "DEFAULT")
    result.calculate_mat_mis_gaps()

    io.write_file("../outputs/locally_local_linear_output.txt", str(result))
Exemplo n.º 8
0
    LOG.info("----------\n")

    # RUN
    LOG.info("[{0}] Requesting the URL = {1}...".format(datetime.now(),EBI_RUN_URL))
    r = requests.post(EBI_RUN_URL,data)
    LOG.info("[{0}] Request made and the code returned was {1}".format(datetime.now(),r.status_code))
    LOG.info("Nome do job gerado = {}".format(r.text))

    #RESULT
    LOG.info("[{0}] Requesting the URL = {1}...".format(datetime.now(),EBI_RESULT_URL))
    #Addind the jobid
    result = requests.get(EBI_RESULT_URL+"{jobID}/aln".format(jobID=r.text))
    
    #Trying again until 200 is returned
    while (result.status_code is not 200):
        LOG.info("[{0}] Result not ready yet...".format(datetime.now()))
        LOG.info("[{0}] Requesting the URL = {1}...".format(datetime.now(),EBI_RESULT_URL))
        result = requests.get(EBI_RESULT_URL+"{jobID}/aln".format(jobID=r.text))
    
    LOG.info("[{0}] Results got = {1}...".format(datetime.now(),result.text))

    alignment = get_alignment(result.text)

    io.write_file("../outputs/ebi_local_output.txt",str(alignment))
    
    #print(str(alignment))