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
j = j - 1 #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")
#EBI URLS EBI_RUN_URL = "http://www.ebi.ac.uk/Tools/services/rest/emboss_water/run/" EBI_RESULT_URL = "http://www.ebi.ac.uk/Tools/services/rest/emboss_water/result/" REGEX = "(?<=\d )[AGVLYETDFQHICSMKPRNW\-]{1,50}" #EXAMPLE OF REQUEST data = {"email":"*****@*****.**", "matrix":"EBLOSUM62", "gapopen":"10.0", "gapext":"0.5", "endweight":"false", "endopen":"10.0", "endextend":"0.5", "format":"pair", "stype":"protein", "asequence":io.read_file("../inputs/default1.fasta"), "bsequence":io.read_file("../inputs/default2.fasta") } def get_alignment(string): """ summary: This fuctions receives a string returned by EBI and parses it to get just the two sequences aligned. return: An alignment object """ string = re.sub(re.compile("#.*?\n" ) ,"" ,string) ##removing all comments p = re.compile(REGEX) #getting the REGEX variable m = p.findall(string) #returns all list of strings that match with that regex string1 = m[0::2] #gets all the even itens on the list (i.e the first sequence)