def muscle_handler(cds, chromosome, est_contig,begin,end): handle2 = open("/home/mamun/Desktop/opuntia.fasta", "w") global value global value1 global chrome chrome=str(chromosome) print "+++++++++++++++++++++++++++++++++++++++\n" print chrome print "+++++++++++++++++++++++++++++++++++++++\n" # Step 1: # Open opuntia.fasta as temporary file # Write CDS and Chromosome one after another to that file handle2.write(">CDS") handle2.write("\n") handle2.write(cds) handle2.write("\n") handle2.write(">Chromosome") handle2.write("\n") handle2.write(chrome) handle2.write("\n") handle2.close() # Close the temporary file #calling muscle_aligner() from checker.py checker.muscle_aligner() # calling cds_handler 1st time # it returns CDS values after alignment message=cds_handler() value1="" value="" #TESTING validity # sample.func() # if beginning or end of the CDS contains any gap # then call checker.x_and_y - here, 0 argument means I am handling CDS # - for more details see checker.x_and_y # remove the beginning and end gaps from the CDS sequence # Then write the new CDS sequence, and Chromosome again to the temporary file # - here, temporary file is opuntia.fasta if(message[0]=="-" or message[:-1]=="-"): value1=checker.x_and_y(0) handle2 = open("/home/mamun/Desktop/opuntia.fasta", "w") #chromosome=str(value) handle2.write(">CDS") handle2.write("\n") handle2.write(cds) handle2.write("\n") handle2.write(">Chromosome") handle2.write("\n") print "Inside CDS and Chromosome" print value1 handle2.write(value1) handle2.close() # else there will be no change in the chromosome else: print "CDS and Chromosome part is done!\n" value1=chrome #calling check() function to insert est contig into fasta file value=checker.check(est_contig) #aligning with all three (CDS, Chromosome, and EST Contig) ## checker.muscle_aligner() print "\nHandler Number: 2\n" #time.sleep(4) # message1=cds_handler() # argument 1 means, we are handling EST Contig in checker.x_and_y # test=checker.x_and_y(1) print "*********************************\n" print "TESTing.........................\n" # print test #TESTING validity # sample.func() # if(message1[0]=="-" or message1[:-1]=="-"): #value=checker.x_and_y(1) print value os.remove("/home/mamun/Desktop/opuntia.fasta") # else: # print "Life goes on!" #time.sleep(3) handle2 = open("/home/mamun/Desktop/opuntia.fasta", "w") handle2.write(">CDS") handle2.write("\n") handle2.write(cds) handle2.write("\n") handle2.write(">Chromosome") handle2.write("\n") if (value1==""): handle2.write(str(chrome)) else: handle2.write(str(value1)) handle2.write("\n") handle2.write(">"+est_contig) handle2.write("\n") print "Inside EST part" print "Chrome......................" print value1 print "EST.........................." print value #Getting first occurane position of ATG if value.find('ATG'): position=value.find('ATG') temp_value=value[position:] handle2.write(str(temp_value)) value=str(temp_value) else: handle2.write(str(value)) handle2.close() checker.muscle_aligner() print "COMPLETE ALIGNMENT is DONE" message1=cds_handler() if(message1[0]=="-" or message1[:-1]=="-"): value=checker.x_and_y(1) print value print "Getting perfect EST\n" #time.sleep(5) handle2 = open("/home/mamun/Desktop/opuntia.fasta", "w") handle2.write(">CDS") handle2.write("\n") handle2.write(cds) handle2.write("\n") handle2.write(">Chromosome") handle2.write("\n") if (value1==""): handle2.write(str(chrome)) else: handle2.write(str(value1)) handle2.write("\n") handle2.write(">"+est_contig) handle2.write("\n") handle2.write(str(value)) handle2.close() checker.muscle_aligner() else: print "We are really done!\n" #time.sleep(3) ## Working with Amino Acid Alignment # End of iteration and alignment # Copying temp files to seperate Directory shutil.copy2('opuntia.fasta','/home/mamun/Desktop/Output/'+est_contig+'.fasta') shutil.copy2('opuntia.aln','/home/mamun/Desktop/Output/'+est_contig+'.aln') handle2 = open("/home/mamun/Desktop/opuntia.fasta", "w") coding_dna1 = Seq(cds, IUPAC.ambiguous_dna) handle2.write(">CDS") handle2.write("\n") handle2.write(str(coding_dna1.translate())) handle2.write("\n") handle2.write("\n") handle2.write(">Chromosome") handle2.write("\n") if (value1==""): coding_dna2 = Seq(chrome, IUPAC.ambiguous_dna) handle2.write(str(coding_dna2.translate())) handle2.write("\n") handle2.write("\n") else: coding_dna2 = Seq(value1, IUPAC.ambiguous_dna) handle2.write(str(coding_dna2.translate())) handle2.write("\n") handle2.write("\n") handle2.write(">"+est_contig) handle2.write("\n") coding_dna3 = Seq(value, IUPAC.ambiguous_dna) if (coding_dna3!=""): handle2.write(str(coding_dna3.translate())) else: handle2.write("") handle2.close() checker.muscle_aligner() # Copyting current file to system! shutil.copy2('opuntia.fasta','/home/mamun/Desktop/Output/'+est_contig+'_acid.fasta') shutil.copy2('opuntia.aln','/home/mamun/Desktop/Output/'+est_contig+'_acid.aln')
def main(): #print cds.translate(cds=True) #chrome=work(cds, dna) global cds global dna global chrome global CDS global CHROME global tracker_cds global tracker_dna path = "/home/mamun/Desktop/Output_test/" for infile in glob.glob( os.path.join(path, '*.fasta') ): handle1 = open(infile, "r") parsedfasta = SeqIO.parse(handle1, "fasta") for i in parsedfasta: if (i.id=="CDS"): cds = Seq(str(i.seq),IUPAC.ambiguous_dna) print "CDS is", cds elif (i.id=="Chromosome"): dna = Seq(str(i.seq), IUPAC.ambiguous_dna) print "DNA is", dna else: campoletis = Seq(str(i.seq), IUPAC.ambiguous_dna) print campoletis ## making empty list!! ## for the global variables!! tracker_cds = 0 tracker_dna = 0 # chrome = "" pos = 0 work(cds, dna) #if(chrome[-7:]!=(cds[-7:]) and (len(chrome)<len(cds))): # try: # pos = chrome[-7:].find(cds) # chrome += cds[pos:] # except: # pass print "New DNA", dna print "New Chromosome", chrome print "********************" print "current file is: " + infile print "** Working with ALIGNMENT file **" handle2 = open("opuntia1.fasta", "w") handle2.write(">CDS") handle2.write("\n") handle2.write(str(cds)) handle2.write("\n") handle2.write(">Chromosome") handle2.write("\n") handle2.write(str(chrome)) #handle2.write("\n") #handle2.write(">EST") #handle2.write("\n") #handle2.write(str(campoletis)) handle2.close() checker.muscle_aligner() ## Checking whether there is a stop codon or not ## at the very beginning of the EST Contig! ## My hypothesis is to check within the first 20 seq temp = Seq(str(campoletis), IUPAC.ambiguous_dna) i=0 while(i<3): temp1 = temp[i:].translate() value = temp1[0:20].find("*") if (value==-1): break else: i+=1 print CDS print chrome handle4 = open("manual.aln", "w") handle4.write(">CDS") handle4.write("\n") handle4.write(str(CDS)) handle4.write("\n") handle4.write(">Chromosome") handle4.write("\n") handle4.write(str(CHROME)) handle4.close() handle3 = open("opuntia2.aln", "w") handle3.write(">EST") handle3.write("\n") handle3.write(str(campoletis[i:])) handle3.close() print "About to end!!" ## Editing for profile-profile alignment os.system("muscle -profile -in1 manual.aln -in2 opuntia2.aln -out combinedAlignment.fasta -maxmb 15000") #muscle_cline=MuscleCommandline(input="opuntia1.fasta", out="opuntia1.afa") #print muscle_cline #align=os.system(str(muscle_cline)) #checker.muscle_aligner() shutil.copy2('combinedAlignment.fasta', infile+'.aln') #time.sleep(4) chrome = "" print "------------End of main---------------"