def translate_image(self, image_name, x_units, y_units):

        input_image = cv2.imread(image_name, 1)

        file_name = "ReferenceImages/translation.jpg"

        translation = Translation()
        translated_image = translation.translate(input_image, y_units, x_units)

        cv2.imwrite(file_name, translated_image)
        rows, cols = translated_image.shape[0], translated_image.shape[1]

        return file_name, rows, cols
Beispiel #2
0
 def askTranslator(self):
     useropt = Validator.isValidAnswer(self, '1', '2')
     if useropt == '1':
         translator_obj = self.Translator()
         translated_phrase = translator_obj.translate(
             ReadandWrite.readFile(self),
             dest=LanguageFromCode.getLanguageCode(self))
         self.data = "\n%s \n\nOriginal Language was %s" % (
             translated_phrase.text, Translation.detectLanguage(self))
         return self.data
     elif useropt == '2':
         translator_obj = self.Translator()
         translated_phrase = translator_obj.translate(
             User.typing(self), dest=LanguageFromCode.getLanguageCode(self))
         self.data = "\n%s \n\nOriginal Language was %s" % (
             translated_phrase.text, Translation.detectLanguage(self))
         return self.data
Beispiel #3
0
 def loadExonSequences(self,axisSequenceRef,exons):
     numExons=len(exons)
     strand=self.strand
     for i in range(numExons):
         exon=exons[i]
         start=exon.begin
         length=exon.end-start
         exonSeq=axisSequenceRef[start:start+length]
         if(len(exonSeq)!=length):
             raise Exception("start="+str(start)+", length="+str(length)
                             +", but substrate "+self.substrate+
                             " ends at "+len(axisSequenceRef))
         if(strand=="-"):
             exonSeq=Translation.reverseComplement(exonSeq)
         exon.sequence=exonSeq
     return True
Beispiel #4
0
def parse_page(page, cfg):
    # Get raw page values.
    raw = page.get_all_values()

    translationsColumnId = int(cfg["TRANSLATION_COLUMN"]) - 1

    # Get list of languages.
    languagesRowId = int(cfg["LANGUAGES_ROW"]) - 1
    langRow = raw[languagesRowId]
    languagesNb = len(langRow)
    languages = []
    for columnId in range(translationsColumnId, languagesNb):
        languages.append(raw[languagesRowId][columnId])

    translationRowId = int(cfg["TRANSLATION_ROW"]) - 1
    # Comments column ids.
    commentKeyColumnId = int(cfg["COMMENT_KEY_COLUMN"]) - 1
    groupKeyColumnId = int(cfg["GROUP_KEY_COLUMN"]) - 1
    # Key column ids.
    androidKeyColumnId = int(cfg["ANDROID_KEY_COLUMN"]) - 1
    iosKeyColumnId = int(cfg["IOS_KEY_COLUMN"]) - 1

    # Parse translations.
    group_name_var = ''
    translations = []
    for rowId in range(0, len(raw)):
        # Skip non-translation rows.
        if rowId < translationRowId:
            continue
        tr = Translation()
        # Comment keys.
        comment = raw[rowId][commentKeyColumnId]
        tr.comment = comment if len(comment) else None
        group_key = raw[rowId][groupKeyColumnId]
        group_name_var = group_key if len(group_key) else group_name_var
        # print('parsed group name {}'.format(group_name_var))
        tr.group = group_name_var
        # Platform keys.
        androidKey = raw[rowId][androidKeyColumnId]
        tr.androidKey = androidKey if len(androidKey) else None
        ios_key = raw[rowId][iosKeyColumnId]
        tr.iosKey = ios_key if len(ios_key) else None
        # Get translations.
        for columnId in range(translationsColumnId, languagesNb):
            tr.translations.append(raw[rowId][columnId])
        translations.append(tr)
    return languages, translations
Beispiel #5
0
def translate(body, vector):
    from Translation import Translation
    return Translation(body, vector)
Beispiel #6
0
    ## check the gnome background dir for Xdg
    if not os.path.exists(gstyle_backgrounds_data_dir):
        os.makedirs(gstyle_backgrounds_data_dir, 0700)

    print "Gstyle Config ok"


## arg debug levels
LEVELS = {
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'warning': logging.WARNING,
    'error': logging.ERROR,
    'critical': logging.CRITICAL
}

if len(sys.argv) > 1:
    level_name = sys.argv[1]
    level = LEVELS.get(level_name, logging.NOTSET)
    logging.basicConfig(level=level)

## LOCALISATION
source_lang = "en"
rep_trad = "/usr/share/locale"
traduction = Translation(APP_NAME, source_lang, rep_trad)
gettext.install(APP_NAME)
gtk.glade.bindtextdomain(APP_NAME, rep_trad)
gettext.textdomain(APP_NAME)
_ = traduction.gettext
Beispiel #7
0
def get_translation(word):
    translation = Translation("proba", "test", 0)
    return translation
Beispiel #8
0
#filename="/home/bmajoros/1000G/assembly/BRCA1-NA19782.fasta";
filename="/Users/bmajoros/python/test/data/subset.fasta"
print(FastaReader.getSize(filename))

[defline,seq]=FastaReader.firstSequence(filename)
print(len(seq))

#filename="/home/bmajoros/1000G/assembly/test.fasta"
filename="/Users/bmajoros/python/test/data/subset.fasta"
hash=FastaReader.readAllAndKeepDefs(filename)
for key in hash.keys():
    [defline,seq]=hash[key]
    print(defline)
    [id,attrs]=FastaReader.parseDefline(defline)
    print("id="+id)
    for key,value in attrs.items():
        print(key+"="+value)

writer=FastaWriter()
writer.writeFasta(">ABCD","ATCGATCGTAGCTAGTCTGCGCGTATCGTCAGTCTCTATCGATCGTACTGCGATCTAGCTAGCTGATCGTAGCTTCTATGACTGCTAGTCATCTAGCTAGCTGATCGTAGCTGCGCGCGATATATTGCATCTATGCTATCATTGCATGCTAGCTCTAGCTAGTCGATGCTATCTTAGCTAC","test1.fasta")

writer.appendToFasta(">XYZ","GATTACA","test1.fasta")

print(Translation.translate(seq))
print("forward:",seq)
print("revcomp: ",Translation.reverseComplement(seq))




Beispiel #9
0
 def trimUTR(self,axisSequenceRef):
     self.adjustOrders()
     stopCodons=self.stopCodons
     sequence=self.sequence
     strand=self.strand
     numExons=self.numExons()
     startCodon=self.startCodon
     if(not startCodon):
         raise Exception("can't trim UTR, because startCodon is not set")
     for j in(numExons):
         exon=self.getIthExon(j)
         length=exon.getLength()
         if(length<=startCodon):
             self.deleteExon(j)
             numExons-=1
             j-=1
             startCodon-=length
             self.adjustOrders() ### 4/1/03
         else:
             if(strand=="+"):
                 exon.trimInitialPortion(startCodon)
                 self.begin=exon.begin
             else:
                 exon.trimInitialPortion(startCodon)### ???
                 self.end=exon.end
             exon.type="initial-exon" if numExons>1 else "single-exon"
             self.startCodon=0
             break
     
     # Find in-frame stop codon
     codonIterator=CodonIterator(self,axisSequenceRef,stopCodons)
     stopCodonFound=False
     while(True):
         codon=codonIterator.nextCodon()
         if(not codon): break
         if(stopCodons.get(codon.triplet,None)):
             exon=codon.exon
             coord=codon.absoluteCoord
             trimBases=0
             if(strand=="+"): trimBases=exon.end-coord-3
             else: trimBases=coord-exon.begin-3
             if(trimBases>=0):
                 exon.trimFinalPortion(trimBases)
                 exon.type="single-exon" if exon.order==0 else "final-exon"
                 j=numExons-1
                 while(j>exon.order):
                     self.deleteExon(j)
                     j-=1
                 stopCodonFound=True
                 break
             else: # codon is interrupted; trim the next exon
                 nextExon=self.getSuccessor(exon)
                 if(not nextExon):
                     raise Exception("exon successor not found")
                 nextExon.trimFinalPortion(nextExon.getLength()+trimBases)
                 nextExon.type="final-exon"
                 j=numExons-1
                 while(j>nextExon.order):
                     self.deleteExon(j)
                     j-=1
                 stopCodonFound=True
                 break	
     if(not stopCodonFound):
         ### sometimes the GFF coords don't include the stop codon...
         numExons=self.numExons()
         lastExon=self.getIthExon(numExons-1)
         lastExonEnd=lastExon.getEnd()
         seq=axisSequenceRef
         if(strand=="+"):
             stopCodonBegin=lastExonEnd
             stopCodon=seq[stopCodonBegin:stopCodonBegin+3]
             if(stopCodon!="TAG" and stopCodon!="TAA" and stopCodon!="TGA"):
                 print("Warning!  No stop codon found for",
                       self.transcriptId,self.strand,
                       "strand , unable to trim UTR")
         else: # strand="-"
             stopCodonBegin=lastExon.getBegin()-3
             stopCodon=seq[stopCodonBegin,stopCodonBegin+3]
             stopCodon=Translation.reverseComplement(stopCodon)
             if(stopCodon!="TAG" and stopCodon!= "TAA" and stopCodon!="TGA"):
                 print("Warning!  No stop codon found for",
                       self.transcriptId,self.strand,
                       "strand , unable to trim UTR")
     self.recomputeBoundaries()