Example #1
0
class CounterCompositionNucleotides(Counter):

    headers = SequenceProperties.SequencePropertiesNA().getHeaders()

    def __init__(self, *args, **kwargs):
        Counter.__init__(self, *args, **kwargs)
        self.result_class = SequenceProperties.SequencePropertiesNA
        assert self.fasta, "Counter requires a genomic sequence"

    def count(self, bed):
        s = self.fasta.getSequence(bed.contig, "+", bed.start, bed.end)
        self.result = self.result_class()
        self.result.loadSequence(s)

    def __str__(self):
        return str(self.result)
Example #2
0
class CounterCompositionCpG(CounterCompositionNucleotides):
    '''compute CpG frequencies as well as nucleotide frequencies.

    Note that CpG density is calculated across the merged exons of a
    transcript. Thus, there might be difference between the CpG on a
    genomic level and on the transrcipt level depending on how many
    genomic CpG are lost across an intron-exon boundary or how many
    transcript CpG are created by exon fusion.

    '''

    headers = SequenceProperties.SequencePropertiesCpg().getHeaders()

    def __init__(self, *args, **kwargs):
        CounterCompositionNucleotides.__init__(self, *args, **kwargs)
        self.result_class = SequenceProperties.SequencePropertiesCpg

    def count(self, bed):

        s = self.fasta.getSequence(bed.contig, "+", bed.start, bed.end)
        self.result = self.result_class()
        self.result.loadSequence(s)
Example #3
0
    def getCounter(section):

        if options.seqtype == "na":
            if section == "length":
                s = SequenceProperties.SequencePropertiesLength()
            elif section == "sequence":
                s = SequenceProperties.SequencePropertiesSequence()
            elif section == "hid":
                s = SequenceProperties.SequencePropertiesHid()
            elif section == "na":
                s = SequenceProperties.SequencePropertiesNA()
            elif section == "gaps":
                s = SequenceProperties.SequencePropertiesGaps(
                    options.gap_chars)
            elif section == "cpg":
                s = SequenceProperties.SequencePropertiesCpg()
            elif section == "dn":
                s = SequenceProperties.SequencePropertiesDN()
            # these sections requires sequence length to be a multiple of 3
            elif section == "aa":
                s = SequenceProperties.SequencePropertiesAA()
            elif section == "degeneracy":
                s = SequenceProperties.SequencePropertiesDegeneracy()
            elif section == "codon-bias":
                s = SequenceProperties.SequencePropertiesBias(reference_codons)
            elif section == "codons":
                s = SequenceProperties.SequencePropertiesCodons()
            elif section == "codon-usage":
                s = SequenceProperties.SequencePropertiesCodonUsage()
            elif section == "codon-translator":
                s = SequenceProperties.SequencePropertiesCodonTranslator()
            else:
                raise ValueError("unknown section %s" % section)
        elif options.seqtype == "aa":
            if section == "length":
                s = SequenceProperties.SequencePropertiesLength()
            elif section == "sequence":
                s = SequenceProperties.SequencePropertiesSequence()
            elif section == "hid":
                s = SequenceProperties.SequencePropertiesHid()
            elif section == "aa":
                s = SequenceProperties.SequencePropertiesAminoAcids()
            else:
                raise ValueError("unknown section %s" % section)
        return s