2016-05-19 5 views
0

これはループの繰り返し処理、関数の呼び出し、ループへの戻り、繰り返し処理に問題があります。今のところ2回しか実行されません。私はそれがループの中の関数をどのように呼び出すのかと関係する方法があると考えています。私が紛失しているものはありますか?Forループ正しく呼び出されない関数で反復処理されません

#!/usr/bin/python 
# -*- coding: utf-8 -*- 

import os, csv, xlrd, sys 
import pandas as pd 
import numpy as np 
from openpyxl import load_workbook 

def PosFinder(): 

    with open('FinalMutations.csv', 'w') as csvf: 
     writer = csv.writer(csvf, delimiter=' ') 
     csvf.close() 

    MutFinder() 

def MutFinder(): 
    df = pd.read_csv('mutation-table.csv', sep=None) 

    MutationList = df['Seq ID'] 

    Positions = list(set(MutationList)) 

    n = len(Positions) 

    for i in (0, n): 
     print(i) 
     MutationPos=Positions[i] 
     MutationFound=df[df['Seq ID'].str.contains(MutationPos)] 
     FreqCheck(MutationFound) 
     i+=1 


    print('Program Complete!') 


def FreqCheck(MutationFound): 

    PFreqs=MutationFound.ix[:,3] 
    PFreqs=PFreqs.str.strip('%') 
    Freqs= PFreqs.astype(float) 

    if len(MutationFound)==1: 
     Check = all(i<10.0 for i in Freqs) 
     if Check in [False, 'False']: 
      ToExcel(MutationFound) 
    else: 
      Check = all(i<10.0 for i in Freqs) 

      if Check in [False, 'False']: 
       ConstantFreq(MutationFound) 


def ConstantFreq(MutationFound):   

    PFreqs=MutationFound.ix[:,3] 
    PFreqs=PFreqs.str.strip('%') 
    Freqs= PFreqs.astype(float) 
    Flag= all(x==Freqs[0] for x in Freqs) 

    if Flag in [False, 'False']: 
     RangeCheck(MutationFound, Freqs) 

def RangeCheck(MutationFound, Freqs): 

    minFreq= Freqs.min() 
    maxFreq= Freqs.max() 
    netFreq= maxFreq-minFreq 

    if netFreq>10: 
     ToExcel(MutationFound) 


def ToExcel(MutationFound): 

    with open('FinalMutations.csv', 'a') as csvf: 

     writer = csv.writer(csvf, delimiter=' ') 
     for row in MutationFound:  
       writer.writerow(row) 


###Start Program### 
PosFinder() 
+0

が再びあなたのコードをフォーマットしてください取得するrange(n)

変更。そして 'open()as'の中に' .close() 'を書く必要はありません... –

答えて

0

ループのためのザ・は現在、2つの値0nのリストだけである、(0, n)をとります。読者が読みために容易になりますので、すべての値01、...、n-1

関連する問題