Exemplo n.º 1
0
def IntermLineCompile(template_filename, primer_sense, primer_antisense,
                      interest_regions):
    """
	Merges input of primer sequences with the gene template; returns  FP, RP, Template 	that is to be fed into the VirtualPCR; 
	"""
    template = open(template_filename)
    Outflank = re.findall('\d+', template_filename.split('_')[1])[0]
    outflank = int(Outflank)
    template.readline()
    #read entire FASTA sequence as one string (includes hang
    gene_seq_h = [seqs.replace('\n', '') for seqs in template.readlines()]
    gene_seq_h = ''.join(gene_seq_h)
    template.close()
    #gene_seq excludes the hang:
    if outflank != 0:
        gene_seq = gene_seq_h[outflank:-outflank]
        #gene_seg_f is formatted, combining the hangs as small caps
        gene_seq_f = gene_seq_h[:outflank].lower(
        ) + gene_seq + gene_seq_h[-outflank:].lower()
    else:
        gene_seq = gene_seq_h
        gene_seq_f = gene_seq
    #translate codon sequence to AA sequence w numbers
    aa_seq = VirtualPCR.SeqToAA(gene_seq)
    #visualize the target relativet o entire aa sequence; basically, scan the aa sequence, draw it as a ---, replace teh dash w the aa target name if it matches.
    if interest_regions != ['']:
        aa_viz = ['*'] * aa_seq.count('_')
        for region in interest_regions:
            for aa in aa_seq.split('_'):
                #if there is a perfect match, return them in uppercase
                if aa == region.strip():
                    aa_viz[aa_seq.split('_').index(aa)] = aa.upper()
                #if just numbers match, return in lowercase
                elif re.findall('\d+',
                                aa) == re.findall('\d+', region.strip()):
                    aa_viz[aa_seq.split('_').index(aa)] = aa
                else:
                    next
        aa_viz = ''.join(aa_viz)
    #if no target region is specified, translate entire aa sequence
    else:
        aa_viz = aa_seq
    #if outflanked, add '-' to the ends
    aa_viz = outflank / 3 * '-' + aa_viz + outflank / 3 * '-'
    #find the positions of the sense and anti-sense primers relative to template; if not found, return (No exact match)
    sense_postest = re.search(primer_sense, gene_seq, flags=0)
    if sense_postest == None:
        sense_pos = "Not in range"
    else:
        sense_pos = sense_postest.span()
    #Note: use the reverse comp for the antisense check
    antisense_postest = re.search(VirtualPCR.CompRev(primer_antisense),
                                  gene_seq,
                                  flags=0)
    if antisense_postest == None:
        antisense_pos = "Not in range"
    else:
        antisense_pos = antisense_postest.span()
    #open the input file, read in the primer sequences
    InputLineData = [
        gene_seq_f, aa_viz, primer_sense, primer_antisense, sense_pos,
        antisense_pos
    ]
    InputLineDataStr = MakeString(InputLineData)
    return (InputLineDataStr)