vic zai 2020-05-03 17:49 采纳率: 28.6%
浏览 1059

求助!!!所有网上方法都试过没用。在pycharm中运行py文件没有输出结果只显示Process finished with exit code 0?

在pycharm中运行py文件没有输出结果只显示Process finished with exit code 0
1.程序没报错,运行程序中也有print,解释器和终端方面已验证没问题。
2.我将网上例子的代码输入能正常输出结果(https://blog.csdn.net/weixin_42554337/article/details/103626958?ops_request_misc=&request_id=&biz_id=102&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0 "")

我的代码如下:

class DeterministicMotifFinding:
    def __init__(self, size=6, seqs=None):
        self.botif_size = size
        if seqs is not None:
            self.seqs = seqs
            self.alphabet = seqs[0].alphabet()
        else:
            self.seqs = []

    def __len__(self):
        return len(self.seqs)

    def __getitem__(self, n):
        return self.seqs[n]

    def seq_size(self, i):
        return len(self.seqs[i])

    def read_file(self, fic, t):
        for s in open(fic, "r"):
            self.seqs.append(MySeq(s.strip().upper(), t))
        self.alphabet = self.seqs[0].alphabet()

    def create_motif_from_indexes(self, indexes):
        global subseq
        pseqs = []
        res = [[0] * self.motif_size for i in range(len(self.alphabet))]  # type: List[Union[List[int], Any]]
        for i, ind in enumerate(indexs):  # type: [int, object]
            subseq = self.seqs[i][ind:(ind + self.motif_size)]  # type: object
        for i in range(self.motif_size):
            for k in range(len(self.alphabet)):
                if subseq[i] == self.alphabet[k]:
                    res[k][i] = res[k][i] + 1
        return res

    def score(self, s):
        score = 0
        mat = self.create_motif_from_indexes(s)
        for j in range(len(mat[0])):
            maxcol = mat[0][j]  # type: Union[int, Any]
            for i in range(1, len(mat)):
                if mat[i][j] > maxcol:
                    maxcol = mat[i][j]
            score += maxcol
        return score

    def score_multiplicative(self, s):
        score = 1.0  # type: float
        mat = self.create_motif_from_indexes(s)
        for j in range(len(mat[0])):
            maxcol = mat[0][j]
            for i in range(1, len(mat)):
                if mat[i][j] > maxcol:
                    maxcol = mat[i][j]
            score *= maxcol
        return score

    def next_solution(self):
        next_sol = [0] * len(s)  # type: List[int]
        pos = len(s) - 1  # type: int
        while pos >= 0 and s[pos] == self.seq_size(pos) - self.motif_size:
            pos -= 1
        if pos < 0:
            next_sol = None
        else:
            for i in range(pos):
                next_sol[i] = s[i]
            next_sol[pos] = s[pos] + 1
            for i in range(pos + 1, len(s)):
                next_sol[i] = 0
        return next_sol

    def exhaustive_search(self):
        best_score = -1  # type: int
        res = []
        s = [0] * len(self.seqs)
        while s is not None:
            sc = self.score(s)
            if sc > best_score:
                best_score = sc
                res = s
            s = self.next_solution
        return res

    def next_vertex(self, s):
        res = []
        if len(s) < len(self.seqs):
            for i in range(len(s)):
                res.append(s[i])
            res.append(0)
        else:
            pos = len(s) - 1
            while pos >= 0 and s[pos] == self.seq_size(pos) - self.motif_size:
                pos -= 1
            if pos < 0:
                res = None
            else:
                for i in range(pos):
                    res.append(s[i])
                res.append(s[pos] + 1)
        return res

    def bypass(self, s):
        res = []
        pos = len(s) - 1
        while pos >= 0 and s[pos] == self.seq_size(pos) - self.motif_size:
            pos -= 1
        if pos < 0:
            res = None
        else:
            for i in range(pos):
                res.append(s[i])
            res.append(s[pos] + 1)
        return res

    def branch_and_bound(self):
        best_score = -1
        best_motif = None
        size = len(self.seqs)
        s = [0] * size
        while s is not None:
            if len(s) < size:
                optimum_score = self.score(s) + (size - len(s)) * self.motif_size
                if optimum_score < best_score:
                    s = self.bypass(s)
                else:
                    s = self.next_vertex(s)
            else:
                sc = self.score(s)
                if sc > best_score:
                    best_score = sc
                    best_motif = s
                s = self.next_vertex(s)
        return best_motif

    def heuristic_consensus(self):
        res = [0] * len(self.seqs)  # type: List[int]
        max_score = -1
        partial = [0, 0]
        for i in range(self.seq_size(0) - self.motif_size):
            for j in range(self.seq_size(1) - self.motif_size):
                partial[0] = i
                partial[1] = j
                sc = self.score(partial)  # type: int
                if sc > max_score:
                    max_score = sc
                    res[0] = i
                    res[1] = j
        for k in range(2, len(self.seqs)):
            partial = [0] * (k + 1)
            for j in range(k):
                partial[j] = res[j]
            max_score = -1
            for i in range(self.seq_size(k) - self.motif_size):
                partial[k] = i
                sc = self.score(partial)
                if sc > max_score:
                    max_score = sc
                    res[k] = i
        return res
def test():
    seq1 = MySeq("ATAGAGCTGA", "dna")
    seq2 = MySeq("ACGTAGATGA", "dna")
    seq3 = MySeq("AAGATAGGGG", "dna")
    mf = DeterministicMotifFindigg(3, [seq1, seq2, seq3])
    print ("Exhaustive:")
    sol = mf.exhaustive_search
    print ("Solution: ", sol)
    print ("Score: ", mf.score(sol))
    print ("\nBranch and Bound:")
    sol2 = mf.branch_and_bound
    print ("Solution: ", sol2)
    print ("Score:", mf.score(sol2))
    print ("\nHeuristic consensus: ")
    sol3 = mf.heuristic_consensus  # type: list1 = List
    print ("Solution: ", sol3)
    print ("Score:", mf.score(sol3))

def test2():
    mf = DeterministicMotifFinding()
    mf.read_file("fic.txt", "dna")
    print ("Branch and Bound:")
    sol = mf.branch_and_bound
    print ("Solution: ", sol)
    print ("Score:", mf.score(sol))
    print ("\nHeuristic consensus: ")
    sol2 = mf.heuristic_consensus
    print ("Solution: ", sol2)
    print ("Score:", mf.score(sol2))

请各位解答!!!

  • 写回答

1条回答 默认 最新

  • mollpppp 2020-05-03 19:57
    关注

    你没调用啊,没实例化类,也没调用方法,没有输出结果的。

    评论

报告相同问题?

悬赏问题

  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 如何提取csv文件中需要的列,将其整合为一篇完整文档,并进行jieba分词(语言-python)
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置