예제 #1
0
파일: Jaspar.py 프로젝트: olgabot/biopython
def read(handle, format):
    alphabet = IUPAC.unambiguous_dna
    counts = {}
    if format=="pfm":
        # reads the motif from Jaspar .pfm file
        letters = "ACGT"
        for letter, line in zip(letters, handle):
            words = line.split()
            #if there is a letter in the beginning, ignore it
            if words[0]==letter:
                words = words[1:]
            counts[letter] = map(float, words)
        motif = Motif(alphabet, counts=counts)
    elif format=="sites":
        # reads the motif from Jaspar .sites file
        instances = []
        for line in handle:
            if not line.startswith(">"):
                break
            # line contains the header ">...."
            # now read the actual sequence
            line = handle.next()
            instance = ""
            for c in line.strip():
                if c==c.upper():
                   instance += c
            instance = Seq(instance, alphabet)
            instances.append(instance)
        motif = Motif(alphabet, instances=instances)
    else:
        raise ValueError("Unknown format %s" % format)
    motif.set_mask("*"*motif.length)
    return motif
예제 #2
0
class AlignAceConsumer:
    """
    The general purpose consumer for the AlignAceScanner (DEPRECATED).

    Should be passed as the consumer to the feed method of the AlignAceScanner. After 'consuming' the file, it has the list of motifs in the motifs property.

    This class is DEPRECATED; please use the read() function in this module
    instead.
    """
    def __init__(self):
        import warnings
        warnings.warn(
            "Bio.Motif.Parsers.AlignAce.AlignAceConsumer is deprecated; please use the read() function in this module instead.",
            Bio.BiopythonDeprecationWarning)
        self.motifs = []
        self.current_motif = None
        self.param_dict = None

    def parameters(self, line):
        self.param_dict = {}

    def parameter(self, line):
        par_name = line.split("=")[0].strip()
        par_value = line.split("=")[1].strip()
        self.param_dict[par_name] = par_value

    def sequences(self, line):
        self.seq_dict = []

    def sequence(self, line):
        seq_name = line.split("\t")[1]
        self.seq_dict.append(seq_name)

    def motif(self, line):
        self.current_motif = Motif()
        self.motifs.append(self.current_motif)
        self.current_motif.alphabet = IUPAC.unambiguous_dna

    def motif_hit(self, line):
        seq = Seq(line.split("\t")[0], IUPAC.unambiguous_dna)
        self.current_motif.add_instance(seq)

    def motif_score(self, line):
        self.current_motif.score = float(line.split()[-1])

    def motif_mask(self, line):
        self.current_motif.set_mask(line.strip("\n\c"))

    def noevent(self, line):
        pass

    def version(self, line):
        self.ver = line

    def command_line(self, line):
        self.cmd_line = line
예제 #3
0
class AlignAceConsumer(object):
    """
    The general purpose consumer for the AlignAceScanner (DEPRECATED).

    Should be passed as the consumer to the feed method of the AlignAceScanner. After 'consuming' the file, it has the list of motifs in the motifs property.

    This class is DEPRECATED; please use the read() function in this module
    instead.
    """
    def __init__(self):
        import warnings
        warnings.warn("Bio.Motif.Parsers.AlignAce.AlignAceConsumer is deprecated; please use the read() function in this module instead.", Bio.BiopythonDeprecationWarning)
        self.motifs=[]
        self.current_motif=None
        self.param_dict = None
    
    def parameters(self,line):
        self.param_dict={}

    def parameter(self,line):
        par_name = line.split("=")[0].strip()
        par_value = line.split("=")[1].strip()
        self.param_dict[par_name]=par_value
        
    def sequences(self,line):
        self.seq_dict=[]
        
    def sequence(self,line):
        seq_name = line.split("\t")[1]
        self.seq_dict.append(seq_name)
        
    def motif(self,line):
        self.current_motif = Motif()
        self.motifs.append(self.current_motif)
        self.current_motif.alphabet=IUPAC.unambiguous_dna
        
    def motif_hit(self,line):
        seq = Seq(line.split("\t")[0],IUPAC.unambiguous_dna)
        self.current_motif.add_instance(seq)
        
    def motif_score(self,line):
        self.current_motif.score = float(line.split()[-1])
        
    def motif_mask(self,line):
        self.current_motif.set_mask(line.strip("\n\c"))

    def noevent(self,line):
        pass
        
    def version(self,line):
        self.ver = line
        
    def command_line(self,line):
        self.cmd_line = line
예제 #4
0
class AlignAceConsumer:
    """
    The general purpose consumer for the AlignAceScanner.

    Should be passed as the consumer to the feed method of the AlignAceScanner. After 'consuming' the file, it has the list of motifs in the motifs property.
    """

    def __init__(self):
        self.motifs = []
        self.current_motif = None
        self.param_dict = None

    def parameters(self, line):
        self.param_dict = {}

    def parameter(self, line):
        par_name = line.split("=")[0].strip()
        par_value = line.split("=")[1].strip()
        self.param_dict[par_name] = par_value

    def sequences(self, line):
        self.seq_dict = []

    def sequence(self, line):
        seq_name = line.split("\t")[1]
        self.seq_dict.append(seq_name)

    def motif(self, line):
        self.current_motif = Motif()
        self.motifs.append(self.current_motif)
        self.current_motif.alphabet = IUPAC.unambiguous_dna

    def motif_hit(self, line):
        seq = Seq(line.split("\t")[0], IUPAC.unambiguous_dna)
        self.current_motif.add_instance(seq)

    def motif_score(self, line):
        self.current_motif.score = float(line.split()[-1])

    def motif_mask(self, line):
        self.current_motif.set_mask(line.strip("\n\c"))

    def noevent(self, line):
        pass

    def version(self, line):
        self.ver = line

    def command_line(self, line):
        self.cmd_line = line
예제 #5
0
class AlignAceConsumer:
    """
    The general purpose consumer for the AlignAceScanner.

    Should be passed as the consumer to the feed method of the AlignAceScanner. After 'consuming' the file, it has the list of motifs in the motifs property.
    """
    def __init__(self):
        self.motifs = []
        self.current_motif = None
        self.param_dict = None

    def parameters(self, line):
        self.param_dict = {}

    def parameter(self, line):
        par_name = line.split("=")[0].strip()
        par_value = line.split("=")[1].strip()
        self.param_dict[par_name] = par_value

    def sequences(self, line):
        self.seq_dict = []

    def sequence(self, line):
        seq_name = line.split("\t")[1]
        self.seq_dict.append(seq_name)

    def motif(self, line):
        self.current_motif = Motif()
        self.motifs.append(self.current_motif)
        self.current_motif.alphabet = IUPAC.unambiguous_dna

    def motif_hit(self, line):
        seq = Seq(line.split("\t")[0], IUPAC.unambiguous_dna)
        self.current_motif.add_instance(seq)

    def motif_score(self, line):
        self.current_motif.score = float(line.split()[-1])

    def motif_mask(self, line):
        self.current_motif.set_mask(line.strip("\n\c"))

    def noevent(self, line):
        pass

    def version(self, line):
        self.ver = line

    def command_line(self, line):
        self.cmd_line = line
예제 #6
0
def read(handle):
    """read(handle)"""
    record = Record()
    line = handle.next()
    record.version = line.strip()
    line = handle.next()
    record.command = line.strip()
    for line in handle:
        line = line.strip()
        if line == "":
            pass
        elif line[:4] == "Para":
            record.parameters = {}
        elif line[0] == "#":
            seq_name = line.split("\t")[1]
            record.sequences.append(seq_name)
        elif "=" in line:
            par_name, par_value = line.split("=")
            par_name = par_name.strip()
            par_value = par_value.strip()
            record.parameters[par_name] = par_value
        elif line[:5] == "Input":
            record.sequences = []
        elif line[:5] == "Motif":
            words = line.split()
            assert words[0] == "Motif"
            number = int(words[1])
            instances = []
        elif line[:3] == "MAP":
            motif = Motif(IUPAC.unambiguous_dna, instances)
            motif.score = float(line.split()[-1])
            motif.number = number
            motif.set_mask(mask)
            record.motifs.append(motif)
        elif len(line.split("\t")) == 4:
            seq = Seq(line.split("\t")[0], IUPAC.unambiguous_dna)
            instances.append(seq)
        elif "*" in line:
            mask = line.strip("\r\n")
        else:
            raise ValueError(line)
    return record
예제 #7
0
def read(handle):
    """read(handle)"""
    record = Record()
    line = handle.next()
    record.version = line.strip()
    line = handle.next()
    record.command = line.strip()
    for line in handle:
        line = line.strip()
        if line == "":
            pass
        elif line[:4] == "Para":
            record.parameters = {}
        elif line[0] == "#":
            seq_name = line.split("\t")[1]
            record.sequences.append(seq_name)
        elif "=" in line:
            par_name, par_value = line.split("=")
            par_name = par_name.strip()
            par_value = par_value.strip()
            record.parameters[par_name] = par_value
        elif line[:5] == "Input":
            record.sequences = []
        elif line[:5] == "Motif":
            words = line.split()
            assert words[0] == "Motif"
            number = int(words[1])
            instances = []
        elif line[:3] == "MAP":
            motif = Motif(IUPAC.unambiguous_dna, instances)
            motif.score = float(line.split()[-1])
            motif.number = number
            motif.set_mask(mask)
            record.motifs.append(motif)
        elif len(line.split("\t")) == 4:
            seq = Seq(line.split("\t")[0], IUPAC.unambiguous_dna)
            instances.append(seq)
        elif "*" in line:
            mask = line.strip("\r\n")
        else:
            raise ValueError(line)
    return record
예제 #8
0
def read(handle):
    """read(handle)"""
    record = Record()
    line = handle.next()
    record.version = line.strip()
    line = handle.next()
    record.command = line.strip()
    for line in handle:
        line = line.strip()
        if line == "":
            pass
        elif line[:4] == "Para":
            record.parameters = {}
        elif line[0] == "#":
            seq_name = line.split("\t")[1]
            record.sequences.append(seq_name)
        elif "=" in line:
            par_name, par_value = line.split("=")
            par_name = par_name.strip()
            par_value = par_value.strip()
            record.parameters[par_name] = par_value
        elif line[:5] == "Input":
            record.sequences = []
        elif line[:5] == "Motif":
            current_motif = Motif()
            current_motif.alphabet = IUPAC.unambiguous_dna
            record.motifs.append(current_motif)
        elif line[:3] == "MAP":
            current_motif.score = float(line.split()[-1])
        elif len(line.split("\t")) == 4:
            seq = Seq(line.split("\t")[0], IUPAC.unambiguous_dna)
            current_motif.add_instance(seq)
        elif "*" in line:
            current_motif.set_mask(line.strip("\n\c"))
        else:
            raise ValueError(line)
    return record
예제 #9
0
파일: AlignAce.py 프로젝트: BingW/biopython
def read(handle):
    """read(handle)"""
    record = Record()
    line = handle.next()
    record.version = line.strip()
    line = handle.next()
    record.command = line.strip()
    for line in handle:
        line = line.strip()
        if line=="":
            pass
        elif line[:4]=="Para":
            record.parameters={}
        elif line[0]=="#":
            seq_name = line.split("\t")[1]
            record.sequences.append(seq_name)
        elif "=" in line:
            par_name, par_value = line.split("=")
            par_name = par_name.strip()
            par_value = par_value.strip()
            record.parameters[par_name]=par_value
        elif line[:5]=="Input":
            record.sequences=[]
        elif line[:5]=="Motif":
            current_motif = Motif()
            current_motif.alphabet=IUPAC.unambiguous_dna
            record.motifs.append(current_motif)
        elif line[:3]=="MAP":
            current_motif.score = float(line.split()[-1])
        elif len(line.split("\t"))==4:
            seq = Seq(line.split("\t")[0],IUPAC.unambiguous_dna)
            current_motif.add_instance(seq)
        elif "*" in line:
            current_motif.set_mask(line.strip("\n\c"))
        else:
            raise ValueError(line)
    return record