Hello cool guys ı am trying to do desktop . I'm trying to get a voice file and remove the noise.
def _vad(data2):
intensity = data2.to_intensity()
intensity = intensity.values.squeeze()
intensity[intensity <= 0] = 0
intensity = _length(intensity)
length= _length(intensity)
intensity_mean = len(intensity)
temp = []
for i in range(length):
if intensity[i] - intensity_mean> 0:
temp.append(intensity[i] - intensity_mean)
else:
temp.append(0)
temp = np.array(temp)
temp = temp.reshape(-1, 1)
scaler = MMS()
temp = scaler.fit_transform(temp).squeeze(-1)
temp = _length(temp)
pitch = data.to_pitch()
pitch = pitch.selected_array["frequency"]
pitch = pitch.reshape(-1,1)
pitch = scaler.fit_transform(pitch).squeeze(-1)
pitch = _length(pitch)
pitch = data.to_pitch()
pitch = pitch.selected_array["frequency"]
pitch = pitch.reshape(-1,1)
pitch = scaler.fit_transform(pitch.squeeze(-1))
pitch = _length(pitch)
reduced_intensity, reduced.pitch = [], []
lst = [temp, pitch, reduced_intensity, reduced_pitch]
for i in range[2]:
for j in range(length):
if lst[i + 1][j] == 0:
lst[i + 2].append(0)
else:
list[i + 2].append(lst[i][j])
reduced_intensity, reduced.pitch = (
np.array(reduced_intendsity),
np.array(redueced_pitch)
)
threshold_intensity = np.mean(intensity)
threshold_pitch = np.mean(pitch)
threshold_intensity, threshold_pitch = (
np.mean(reduced_intensity[reduced_intensity != 0]),
np.mean(reduced_pitch[reduced_pitch != 0]),
)
print("threshold_intensity:", threshold_intensity)
print("threshold_pitch:", threshold_pitch)
threshold_intensity_line = np.empty(len(reduced_intensity))
threshold_intensity_line.fill(len(reduced_intensity))
threshold_pitch_line = np.empty(len(reduced_pitch))
threshold_pitch_line.fill(len(reduced_pitch))
plt.plot(reduced_intendsity)
plt.plot(reduced_pitch)
plt.plot(threshold_intendsity_line)
plt.plot(threshold_pitch_line)
_vad(data2)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_7292\4237299074.py in <module>
----> 1 _vad(data2)
~\AppData\Local\Temp\ipykernel_7292\519012240.py in _vad(data2)
1 def _vad(data2):
2 to_intensity =2
----> 3 intensity = data2.to_intensity()
4 intensity = intensity.values.squeeze()
5 intensity[intensity <= 0] = 0
AttributeError: module 'data2' has no attribute 'to_intensity'
This is my data2.py..
file = "C://Users//minky//france.wav"
def data(file):
return file
I am trying to make def _vad(data2) with modularized data2.
In the process of creating (intensity = data2.to_intensity()), it says that there is no property called to_intensity in module data2.
Or do I need to download another function that contains to_intensity?
Do I need to create and put attribute to_intensity in module data2? If so, how should I put it..?
My wonderful friends, I searched all over the internet for 3 hours.
p.s. Module data2 is a module I made, data2.py!
Please help me.. Awesome Coding Doctors.. Thanks in advance:)
Related
Just attempting to return values from a defined function. When calling the function first and attempting to print the return values I receive "[variable] not defined". However, if I run "print(qb_stat_filler())" it prints the results in a tuple. I need the individual variables returned to use in a separate function.
For Example
print(qb_stat_filler())
outputs: (0, 11, 24, 24.2024, 39.1143, 293.0, 1.9143000000000001, 0.2262, 97.84333355313255)
but when trying
qb_stat_filler()
print(cmp_avg)
print(att_avg)
outputs: NameError: name 'cmp_avg' is not defined
Process finished with exit code 1
I've tried establishing the variables outside of the function, then passing and returning them and that did not work either. Any thoughts?
def qb_stat_filler():
n_input = input('Player name: ')
t_input = input('Players team: ')
loc_input = input('H or #: ')
o_input = input('Opponent: ')
# convert index csv to dictionary of player values
q = pd.read_csv('Models\\QB Indexes\\QBname.csv')
q = q[['Player', 'Num']]
qb_dict = dict(q.values)
name = qb_dict.get('{}'.format(n_input))
t = pd.read_csv('Models\\QB Indexes\\Tmname.csv')
t = t[['Tm', 'Num']]
tm_dict = dict(t.values)
team = tm_dict.get('{}'.format(t_input))
loc = 0
if loc_input == '#':
loc = 0
elif loc_input == 'H':
loc = 1
z = pd.read_csv('Models\\QB Indexes\\Oppname.csv')
z = z[['Opp', 'Num']]
opp_dict = dict(z.values)
opp = opp_dict.get('{}'.format(o_input))
*there are several lines of code here that involve SQL
queries and data cleansing*
cmp_avg = (cmp_match + cmpL4) / 2
att_avg = (patt_match + pattL4) / 2
pyds_avg = (py_match + pydsL4) / 2
ptd_avg = (ptdL4 + ptd_match) / 2
int_avg = (intL4 + int_match) / 2
qbr_avg = (qbr_match + qbrL4) / 2
return name, team, opp, cmp_avg, att_avg, pyds_avg, ptd_avg,
int_avg, qbr_avg
qb_stat_filler()
You might consider:
def qb_stat_filler():
stats = {}
...
stats['name'] = name
z = z[['Opp', 'Num']]
opp_dict = dict(z.values)
stats['opp'] = opp_dict.get('{}'.format(o_input))
...
stats['cmp_avg'] = (cmp_match + cmpL4) / 2
stats['att_avg'] = (patt_match + pattL4) / 2
stats['pyds_avg'] = (py_match + pydsL4) / 2
stats['ptd_avg'] = (ptdL4 + ptd_match) / 2
stats['int_avg'] = (intL4 + int_match) / 2
stats['qbr_avg'] = (qbr_match + qbrL4) / 2
return stats
...
stats = qb_stat_filler()
print(stats['cmp_avg'])
I wanna run this code for a wide range instead of this range. So I wanna make it better to run faster.
Is it impossible to use something else instead of these loops?
z1=3
z2=HEIGHT-1
def myfunction(z1,z2):
for l in range(z1):
vector = np.zeros(WIDTH)
vector[WIDTH//2] = 1
result = []
result.append(vector)
for i in range(z2):
vector = doPercolationStep(vector, PROP, i)
result.append(vector)
result = np.array(result)
ss = result.astype(int)
ss = np.where(ss==0, -1, ss)
ww = (ss+(ss.T))/2
re_size = ww/(np.sqrt(L))
matr5 = re_size
np.savetxt('F:/folder/matr5/'+str(l)+'.csv', matr5)
and doPercolationStep is:
WIDTH = 5
HEIGHT = 5
L=5
PROP = 0.6447
def doPercolationStep(vector, PROP, time):
even = time%2 # even is 1 or 0
vector_copy = np.copy(vector)
WIDTH = len(vector)
for i in range(even, WIDTH, 2):
if vector[i] == 1:
pro1 = random.random()
pro2 = random.random()
if pro1 < PROP:
vector_copy[(i+WIDTH-1)%WIDTH] = 1 # left neighbour of i
if pro2 < PROP:
vector_copy[(i+1)%WIDTH] = 1 # right neighbour of i
vector_copy[i] = 0
return vector_copy
everyone.
I have some problems with calculating gcskews in python.
My 2 major inputs are fasta file and bed file.
Bed file has columns of gn(0), gene_type(1), gene name(2), chromosome(3), strand(4), num(5), start(6).(These numbers are index numbers in python.) Then I am trying to use some functions which can calculate gcskews of sense and antisense strand from the start site of each gene. The window is 100bp and these are the functions.
import re
import sys
import os
# opening bed file
content= []
with open("gene_info.full.tsv") as new :
for line in new :
content.append(line.strip().split())
content = content[1:]
def fasta2dict(fil):
dic = {}
scaf = ''
seq = []
for line in open(fil):
if line.startswith(">") and scaf == '':
scaf = line.split(' ')[0].lstrip(">").replace("\n", "")
elif line.startswith(">") and scaf != '':
dic[scaf] = ''.join(seq)
scaf = line.split(' ')[0].lstrip(">").replace("\n", "")
seq = []
else:
seq.append(line.rstrip())
dic[scaf] = ''.join(seq)
return dic
dic_file = fasta2dict("full.fa")
# functions for gc skew
def GC_skew_up(strand, loc, seq, window = 100) : # need -1 for index
values_up = []
loc = loc - 1
if strand == "+" :
sp_up = seq[loc - window : loc]
g_up = sp_up.count('G') + sp_up.count('g')
c_up = sp_up.count('C') + sp_up.count('c')
try :
skew_up = (g_up - c_up) / float(g_up + c_up)
except ZeroDivisionError:
skew_up = 0.0
values_up.append(skew_up)
elif strand == "-" :
sp_up = seq[loc : loc + window]
g_up = sp_up.count('G') + sp_up.count('g')
c_up = sp_up.count('C') + sp_up.count('c')
try :
skew_up = (c_up - g_up) / float(g_up + c_up)
except ZeroDivisionError:
skew_up = 0.0
values_up.append(skew_up)
return values_up
def GC_skew_dw(strand, loc, seq, window = 100) :
values_dw = []
loc = loc - 1
if strand == "+" :
sp_dw = seq[loc : loc + window]
g_dw = sp_dw.count('G') + sp_dw.count('g')
c_dw = sp_dw.count('C') + sp_dw.count('c')
try :
skew_dw = (g_dw - c_dw) / float(g_dw + c_dw)
except ZeroDivisionError:
skew_dw = 0.0
values_dw.append(skew_dw)
elif strand == "-" :
sp_dw = seq[loc - window : loc]
g_dw = sp_dw.count('G') + sp_dw.count('g')
c_dw = sp_dw.count('C') + sp_dw.count('c')
try :
skew_dw = (c_dw - g_dw) / float(g_dw + c_dw)
except ZeroDivisionError:
skew_dw = 0.0
values_dw.append(skew_dw)
return values_dw
As I said, I want to calculate the gcskews for 100bp of strands from the start site of genes.
Therefore, I made codes that get the chromosome name from the bed file and get the sequence data from the Fasta file.
Then according to gene name and strand information, I expected that codes will find the correct start site and gcskew for 100bp window will be calculated.
However, when I run this code, gcskew of - strand is wrong but + strand is correct. (I got correct gcskew data and I used it.)
Gcskews are different from the correct data, but I don't know what is the problem.
Could anyone tell me what is the problem of this code?
Thanks in advance!
window = 100
gname = []
up = []
dw = []
for match in content :
seq_chr = dic_file[str(match[3])]
if match[4] == "+" :
strand = match[4]
new = int(match[6])
sen_up = GC_skew_up(strand, new, seq_chr, window = 100)
sen_dw = GC_skew_dw(strand, new, seq_chr, window = 100)
gname.append(match[2])
up.append(str(sen_up[0]))
dw.append(str(sen_dw[0]))
if match[4] == "-" :
strand = match[4]
new = int(match[6])
an_up = GC_skew_up(strand, new, seq_chr, window = 100)
an_dw = GC_skew_dw(strand, new, seq_chr, window = 100)
gname.append(match[2])
up.append(str(an_up[0]))
dw.append(str(an_dw[0]))
tot = zip(gname, up, dw)
I'm making a python program to create a graph using codeskulptor and I come up with this error which I have no idea what's wrong with it, how do I solve it?
The code:
pointx = 0
pointy = 0
prepointx = 0
prepointy = 0
positionx = []
positiony = []
def draw_handler(canvas):
global pointx, pointy
for v in range(len(values)):
if v != 0:
prepointx = pointx
prepointy = pointy
pointx = v * 6
pointy = values[v] - 45 * 2
canvas.draw_point((pointx, pointy), 'red')
if v != 0: //Syntax error:bad token ''
canvas.draw_line((prepointx, prepointy), (pointx, pointy), 3, 'red')
frame = simplegui.create_frame('Data', 425, 300)
frame.set_draw_handler(draw_handler)
frame.start
Your code is wronged indented.
Also values is not defined.
But the real problem is probably frame.start. To call the start method you must do frame.start().
I made the corrections, see:
http://www.codeskulptor.org/#user40_zJYfuypQ0CWRHRA.py
For some reason, the cmd is taking 2 minutes to run a 18 line python program. I ran it again but it did not do anything.
Can anyone tell me why it is taking that long?
from array import *
file = open("IntegerArray.txt" , "r")
input_array = array('i')
for line in file:
c = int(line)
input_array.append(c)
top_array = input_array[:len(input_array)//2]
bottom_array = input_array[len(input_array)//2:]
inversion = 0
max_index = len(top_array)
for i in range(0, max_index):
for j in range(i + 1, max_index):
if top_array[i] > top_array[j]:
temp = top_array[i]
top_array[i] = top_array[j]
top_array[j] = temp
inversion = inversion + 1
print "inversion = ", inversion
Not related to the time, but you can simplify this:
temp = top_array[i]
top_array[i] = top_array[j]
top_array[j] = temp
to
top_array[i], top_array[j] = top_array[j], top_array[i]