Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import numpy as np import random rnstart = random.randint(0, 10) print(rnstart)

ID: 3880741 • Letter: I

Question

import numpy as np

import random

rnstart = random.randint(0, 10)

print(rnstart)


x = np.ones((10,2))
for row in x:
row[0] = rnstart
row[1] = rnstart + 100
rnstart = random.randint(0, 10)   
print(x)

fastaSeq = ('')
fasta = open('15small22.fasta', 'r').readlines()
dna = ('')

for line in fasta:
if not line.startswith('>'):
dna += line


#print(list(dna))

dna = list(dna)
print(dna)
y = np.ones((10,2))
#
for i in range(0,5):
np.append(y, dna[x[i,0]:x[i,1]], axis=int)
print(y)
#

#a = np.array([[i]*2 for i in range(10)])
#for i in x:
# for e in i:
# e[i]= rnstart
  

#a[1] = rnstart + 100
  
  
#x = np.ones((10,2)) # need to make this first number (row) 10k, row will be randint, randint + 100
#print(x)
#
#for row in x:
# for e in row:
# e[0] = rnstart
# e[1] = rnstart + 100
#

#
#for i in range(len(x)):
# for j in range(len(x[i])):
# print(j)
# #print(x[i][j])

#x[0] = rnstart
#x[1] = rnstart + 100
#for i, element in range[0::1]:
# enumerate(x):
# for element in x:
# element [0] = rnstart
# element [1] = rnstart + 100
#
##for i, element in enumerate(x):
# # element [0] = rnstart
# # element [1] = rnstart + 100

#print(x)
#print(x[0])
#for i in range(100):
# array = np.array(rnstart, rnstart + 100)
# print(array)


#print(numpy.arange(value, ,100, dtype=None))

Usage Here you can get help of any object by pressing Cmd+ in front of it, either on the Editor or the Console. Help can also be shown automatically after writing a left Variable explorer File explorer IPython console O Console 1/A O > -> A Traceback most recent call last): U/File intentEcba 394d02, line, in smodule Cunfile(/users/jordanzehr/Documents/ComputationalGenomics/DNAoutput.py', wie Users/ordanzehr/Documents/ComputationalGenomics File:215 onizer/Encor das ih ptions.0/5tepeckges/spyder/uta 15/5ate :Andes. /', line 10, in runfile execfile(filename, namespace) File:Sornzhr/anaconda3 Python 56/8e-packages/spyderiutats/Sate EN DA, line 10', in exectile exec(compile (f.read(0, filename, 'exec'), namespace) FAle Eerstod unzehr/Documents/Computational Genomics/DNA output.pytine 48, in codules np.append(y, fastaseg lx[1,8] 1x[1,1]], axisint), Aunor slice indices must be integers or None or have an _index_method In 1261: In 138): MacBook Pro PAR

Explanation / Answer

By observing the error screenshot:

there is problem with the syntax of append method that we used

np.append(y, dna[x[i,0]:x[i,1]], axis=int) - in this axis = int is the error because according to python documentation the axis argument takes integer numbers as its argument but here we give string as argument so we are getting the error.

if we replace axis with either 1 or 0 we get out required output:

example:

np.append(y, dna[x[i,0]:x[i,1]], axis=0)

if we replace the np.append code in our program as above we can run our program sucussfully with out any errors.

where axis = 0 means it indicate rows

axis = 1 means it indicate column

we have to chage the axis based on our requirement i.e., how we want to append the elements.