Example #1
0
 def cached_seq(self, padding_pos5, padding_pos3, strand='+'):
     """
     Returns the cached sequence in the positive strand direction.
     
     @param padding_pos5  The amount of padding (left) in the 5' end
                          on the positive strand
     @param padding_pos3  The amount of padding (right) on the 3' end
                          on the positive strand
     """
     # TODO unit test
     if padding_pos5 > self.seq_padding_pos5:
         padding_pos5 = self.seq_padding_pos5
     
     if padding_pos3 > self.seq_padding_pos3:
         padding_pos3 = self.seq_padding_pos3
     
     start_idx = self.seq_padding_pos5 - padding_pos5
     end_idx = -1*(self.seq_padding_pos3 - padding_pos3) or None # if 0, then None-- pass into idx
     
     if self.negative_sequence:
         seq = reverse_complement(self.negative_sequence)
     else:
         seq = self.positive_sequence
     
     substr = seq[start_idx:end_idx]
     if strand == '+':
         return substr
     else:
         return reverse_complement(substr)
Example #2
0
    def manual(self):
        c.assay_name = "Manual Entry"
        seq = self.form_result['sequence']
        c.amplicon_width = len(seq)
        c.prefix_width = 0
        c.suffix_width = 0
        
        enzymes = self.__enzymes_from_form()
        c.form = h.LiteralForm(
            value = {'enzyme': ''},
            option = {'enzyme': [('','--')]+[(e.cutseq, e.name) for e in enzymes]}
        )
        
        # TODO helper function for later (shared with sequence)
        c.prefix_pct = 0
        c.amplicon_pct = 100
        c.suffix_pct = 0
        c.amplicon_offset_pos = c.prefix_width
        c.amplicon_offset_neg = c.suffix_width
        c.positive_sequence = seq
        c.negative_sequence = reverse_complement(seq)
        c.found_sequence = True
        c.left_padding = 0
        c.right_padding = 0
        c.assay_id = ''
        c.enzymes = self.form_result['enzymes']

        c.form = h.LiteralForm(
            value = {'enzymes': ''},
            option = {'enzymes': [('','--')]+[(e.cutseq, e.name) for e in enzymes]}
        )
        return render('/cutter/sequence.html')
Example #3
0
 def _observed_complement(cls, observed):
     """
     Returns the reverse complement of observed bases, excluding deletions.
     
     @param observed The observed column from the snp table row.
                     Assumes format '[-ACTG][/ACTG]*'
     """
     return [reverse_complement(base) for base in cls._observed(observed)]
Example #4
0
    def __add_sequence_primer_display_attrs(self, seq, **kwargs):
        assay = kwargs.get("assay", None)
        if assay:
            primer_fwd = assay.primer_fwd
            primer_rev = assay.primer_rev
            probe_seq = assay.probe_seq
        else:
            primer_fwd = kwargs.get("primer_fwd", None)
            primer_rev = kwargs.get("primer_rev", None)
            probe_seq = kwargs.get("probe_seq", None)

        posq = seq.amplicon.positive_strand_sequence
        negq = seq.amplicon.negative_strand_sequence

        posf = posq.find(primer_fwd)
        posn = posq.find(reverse_complement(primer_rev))

        if posf != -1:
            posq = "%s%s%s" % (posq[: len(primer_fwd)], posq[len(primer_fwd) : posn].lower(), posq[posn:])
            negq = negq.lower()
        else:
            negf = negq.find(primer_fwd)
            negn = negq.find(reverse_complement(primer_rev))

            negq = "%s%s%s" % (negq[: len(primer_fwd)], negq[len(primer_fwd) : negn].lower(), negq[negn:])
            posq = posq.lower()

        if probe_seq:
            posp = posq.upper().find(reverse_complement(probe_seq))
            negp = negq.upper().find(reverse_complement(probe_seq))

            if posp != -1:
                # raise Exception, posq
                posq = "%s|%s|%s" % (posq[:posp], posq[posp : posp + len(probe_seq)], posq[posp + len(probe_seq) :])
            elif negp != -1:
                negq = "%s|%s|%s" % (negq[:negp], negq[negp : negp + len(probe_seq)], negq[negp + len(probe_seq) :])

        seq.positive_display_sequence = posq
        seq.negative_display_sequence = negq[::-1]
        return seq
Example #5
0
    def sequence_variant(self, sequence, mutation, strand="+"):
        """
        Return the possible mutation(s) in the sequence due to
        the sequence.  For now, return the original sequence.
        # TODO: probably not return the original sequence
        """
        # first step: get positive string, standardizing so it's
        # easier for me to think about
        if sequence.strand == "-":
            seq = sequence.reverse_complement()
        else:
            seq = sequence

        if mutation["observed"] == "lengthTooLong":
            # raise UnknownMutationError, "Could not read the variants for %s SNP %s at chr%s:%s-%s" % (mutation['class'], mutation['name'], mutation['chrom'], mutation['chromStart'], mutation['chromEnd'])
            sequences = []
            dup = self.__class__.duplicate(sequence)
            dup2 = self.__class__.duplicate(sequence, name=mutation["name"])

            xform = TransformedGenomeSequence.replace(
                dup2,
                mutation["chromStart"],
                mutation["chromEnd"],
                "?" * (mutation["chromEnd"] - mutation["chromStart"] + 1),
            )
            sequences.append(dup)
            sequences.append(xform)

        else:
            klass = mutation["class"].lower().replace("-", "")
            sequences = getattr(self.__class__, "_%s_sequence_variant" % klass, self.__class__._unknown_variant)(
                seq, mutation
            )

        if strand == "-":
            return [reverse_complement(s) for s in sequences]
        else:
            return sequences