Example #1
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
Example #2
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))




Example #3
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()