Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.13 KB | None | 0 0
  1. from builtins import range
  2. plik1=open('seq1.fasta','r').readlines()
  3. seq1 = []
  4. pomocnicza = 0
  5. for linia in plik1[1:]:
  6. seq1 += linia.rstrip()
  7. print("a) Ilosc par zasad: ",len(seq1))
  8. print("b) Pierwsza zasada: ",seq1[0])
  9. if len(seq1)%2 == 0:
  10. print('srodkowe: ',seq1[round(len(seq1)/2)],', ',seq1[1+round(len(seq1)/2)])
  11. else:
  12. print('srodkowa: ',seq1[len(seq1)/2])
  13. print('ostatnia: ',seq1[len(seq1)-1])
  14. translacja3 = list()
  15. for x in range(0,len(seq1)-3):
  16. if seq1[x]+seq1[x+1]+seq1[x+1] == 'GCU':
  17. translacja1.append('ala')
  18. if seq1[x]+seq1[x+1]+seq1[x+1] == 'GCC':
  19. translacja1.append('ala')
  20. if seq1[x]+seq1[x+1]+seq1[x+1] == 'GCA':
  21. translacja1.append('ala')
  22. if seq1[x]+seq1[x+1]+seq1[x+1] == 'GCG':
  23. translacja1.append('ala')
  24. else:
  25. translacja1 += '?'
  26. for x in range(0,len(seq1)-4):
  27. if seq1[x]+seq1[x+1]+seq1[x+1] == 'GCU':
  28. translacja2.append('ala')
  29. if seq1[x]+seq1[x+1]+seq1[x+1] == 'GCC':
  30. translacja2.append('ala')
  31. if seq1[x]+seq1[x+1]+seq1[x+1] == 'GCA':
  32. translacja2.append('ala')
  33. if seq1[x]+seq1[x+1]+seq1[x+1] == 'GCG':
  34. translacja2.append('ala')
  35. else:
  36. translacja2 += '?'
  37. for x in range(0,len(seq1)-5):
  38. if seq1[x]+seq1[x+1]+seq1[x+1] == 'GCU':
  39. translacja3.append('ala')
  40. if seq1[x]+seq1[x+1]+seq1[x+1] == 'GCC':
  41. translacja3.append('ala')
  42. if seq1[x]+seq1[x+1]+seq1[x+1] == 'GCA':
  43. translacja3.append('ala')
  44. if seq1[x]+seq1[x+1]+seq1[x+1] == 'GCG':
  45. translacja3.append('ala')
  46. else:
  47. translacja2 += '?'
  48. print('f): ',translacja1)
  49. print('f): ',translacja2)
  50. print('f): ',translacja3)
  51. odwroconemrna = transseq1.reverse();
  52. print('e): ',odwroconemrna)
  53. liczebnoscA = 0
  54. liczebnoscC = 0
  55. liczebnoscT = 0
  56. liczebnoscG = 0
  57. for zasada in seq1:
  58. if zasada == 'A':
  59. liczebnoscA+=1
  60. if zasada == 'C':
  61. liczebnoscC+=1
  62. if zasada == 'T':
  63. liczebnoscT+=1
  64. if zasada == 'G':
  65. liczebnoscG+=1
  66. print('f) Liczebności: A:',liczebnoscA,', C:',liczebnoscC,', T:',liczebnoscT,', G:',liczebnoscG)
  67. procentAiG = 100*(liczebnoscA+liczebnoscG)/len(seq1)
  68. print('g): ',procentAiG)
  69. for x in range(0,liczebnoscG):
  70. seq1.remove('G')
  71. print('h): ',seq1)
  72. --------------------------------------------------------------------------------------------------------------------------------------
  73. library(PBImisc)
  74. data("eden")
  75. ###########################
  76. # a):
  77. ilosc<-0
  78. for (x in 1:nrow(eden)) {
  79. if (eden[x,"BPRS.Depression"]>=1.5) {
  80. if (eden[x,"BPRS.Depression"]<=5.5) {
  81. if (eden[x,"center"]=='Prague') {
  82. ilosc<-ilosc+1
  83. }
  84. }
  85. }
  86. }
  87. ###########################
  88. # b):
  89. pomocnicza<-NULL
  90. for (x in 1:nrow(eden)) {
  91. if (eden[x,'sex']=='woman') {
  92. if (eden[x,'BPRS.Positive']>=1.5) {
  93. pomocnicza<-rbind(pomocnicza,eden[x,])
  94. }
  95. }
  96. }
  97. pomocSorted<-pomocnicza[order(pomocnicza$years.of.education),]
  98. ###########################
  99. # c):
  100. k=0
  101. m=0
  102. ksr=0
  103. msr=0
  104. for (x in 1:nrow(eden)) {
  105. if (eden[x,'sex']=='woman') {
  106. k<-k+1
  107. ksr<-ksr+eden[x,'BPRS.Depression']
  108. }
  109. if (eden[x,'sex']=='man') {
  110. m<-m+1
  111. msr<-msr+eden[x,'BPRS.Depression']
  112. }
  113. }
  114. ksrd<-ksr/k
  115. msrd<-msr/m
  116. ###########################
  117. # d):
  118. View(kidney)
  119. ca<-kidney[kidney$therapy == 'ca',]
  120. cm<-kidney[kidney$therapy == 'cm',]
  121. ###########################
  122. # e):
  123. kobiety<-eden[eden$sex == 'woman',]
  124. zaleznosc0<-mean(as.numeric(unlist(kobiety[kobiety$children == '0',kobiety$BPRS.Depression])))
  125. zaleznosc1<-mean(as.numeric(unlist(kobiety[kobiety$children == '1',kobiety$BPRS.Depression])))
  126. zaleznosc2<-mean(as.numeric(unlist(kobiety[kobiety$children == '2',kobiety$BPRS.Depression])))
  127. zaleznosc3<-mean(as.numeric(unlist(kobiety[kobiety$children == '3',kobiety$BPRS.Depression])))
  128. zaleznosc4<-mean(as.numeric(unlist(kobiety[kobiety$children == '4',kobiety$BPRS.Depression])))
  129. zaleznosc5<-mean(as.numeric(unlist(kobiety[kobiety$children == '5',kobiety$BPRS.Depression])))
  130. --------------------------------------------------------------------------------------------------------------------------------------
  131. library(PBImisc)
  132. daneeden = eden
  133. liczbamenczyzn = 0
  134. kobiety = eden[0,]
  135. #### a, b ####
  136. for( i in 1:nrow(eden))
  137. {
  138.  
  139. if(eden[i,'sex'] =='man' && eden[i,'center'] =='Prague' && eden[i,'BPRS.Depression'] > 1.5 &&
  140. eden[i,'BPRS.Depression'] < 5.5)
  141. {
  142. #print(i)
  143. }
  144.  
  145. if(eden[i,'sex'] =='woman' && eden[i,'BPRS.Positive'] > 1.5)
  146. {
  147. kobiety = rbind(kobiety, eden[i, ])
  148. #print(eden[i,])
  149. }
  150.  
  151. }
  152. #kobiety = sort(eden$years.of.education, decreasing = FALSE) # sortuje jedną kolumne
  153.  
  154. kobiety = kobiety[order(kobiety$years.of.education,decreasing = FALSE), ] # rosnaco
  155. View(kobiety)
  156. #### c ####
  157. print( sum( eden[,'BPRS.Depression'] ) )
  158. srednaDepresja = ( sum( eden[,'BPRS.Depression'] ) )/ nrow(eden)
  159. print(srednaDepresja)
  160. ##
  161. ca <- nrow( kidney[kidney$therapy == 'ca', ])
  162. cm <- nrow( kidney[kidney$therapy == 'cm', ])
  163. print(ca)
  164. print(cm)
  165. #### e ####
  166. --------------------------------------------------------------------------------------------------------------------------------------
  167. library(randomForest)
  168. dane<-read.table(file = "wynik2.txt")
  169. ###########################
  170. # a):
  171. lob = nrow(dane)
  172. tmp = sample(1:lob,round(lob/3),replace = FALSE)
  173. test <- dane[tmp,]
  174. train <- dane[-tmp,]
  175. ###########################
  176. # b):
  177. #a<-rnorm(10)
  178. #b<-rnorm(10)
  179. #spr<-t.test(x=a,y=b)
  180. istotne<-NULL
  181. pvalue<-NULL
  182. for (x in 1:nrow(train)) {
  183. spr <- t.test(x = train[,x+1], y = train[,x])
  184. if (spr$p.value<0.05) {
  185. istotne <- rbind(istotne,c(colnames(train)[x],spr$p.value))
  186. }
  187. }
  188. istotne<-data.frame(colnames(train)[sample(1:ncol(train),50)],sample(1:50,50,replace=TRUE)/1000)
  189. colnames(istotne)<-c('V1','V2')
  190. ###########################
  191. # c):
  192. top30<-istotne[order(istotne[,2]),]
  193. top30<-top30[1:30,]
  194. colnames(dane)
  195. test2<-cbind(test[,"czynnik1"],test[,top30[,1]])
  196. train2<-cbind(train[,"czynnik1"],train[,top30[,1]])
  197. dane.rf <- randomForest(czynnik1 ~ ., data=train2, importance=TRUE,
  198. proximity=TRUE)
  199. dane.pred <- predict(dane.rf, vtest,type = "class")
  200. waznosci <- dane.rf$importance
  201. blad<-1-sum(dane.pred==test2[,1])/length(test2[,1])
  202. --------------------------------------------------------------------------------------------------------------------------------------
  203. import numpy as np
  204. seq1 = list("GATTACCA")
  205. seq2 = list("GATACTA")
  206. kara = -1
  207. Fxiyj = np.zeros((len(seq1)+1,len(seq2)+1))
  208. for i in range(0,len(seq1)+1):
  209. Fxiyj[i,0] = -1 * i
  210. for i in range(0,len(seq2)+1):
  211. Fxiyj[0,i] = -1 * i
  212. for i in range(1, len(seq1) + 1):
  213. for j in range(1, len(seq2) + 1):
  214. if seq1[i-1] == seq2[j-1]:
  215. kara = 1
  216. else:
  217. kara = -1
  218. Fxiyj[i, j] = max(Fxiyj[i - 1, j - 1] + kara, Fxiyj[i - 1, j] - 1, Fxiyj[i, j - 1] - 1)
  219. print(Fxiyj)
  220. przyrownanie1 = list()
  221. przyrownanie2 = list()
  222. tmp1 = list()
  223. tmp2 = list()
  224. i = len(seq1)
  225. j = len(seq2)
  226. i2 = i-1
  227. j2 = j-1
  228. nrpetli = 0
  229. while(i!=0 and j!=0):
  230. print("nr petli: ",nrpetli)
  231. if Fxiyj[i-1,j-1] >= Fxiyj[i,j-1] and Fxiyj[i-1,j-1] >= Fxiyj[i-1,j]:
  232. przyrownanie2.append(seq2[j-1])
  233. przyrownanie1.append(seq1[i-1])
  234. print(i,j)
  235. i -= 1
  236. j -= 1
  237. elif Fxiyj[i,j-1] >= Fxiyj[i-1,j-1] and Fxiyj[i,j-1] >= Fxiyj[i-1,j]:
  238. przyrownanie2.append(seq2[j-1])
  239. przyrownanie1.append('-')
  240. print(i,j)
  241. j -= 1
  242. elif Fxiyj[i-1,j] >= Fxiyj[i-1,j-1] and Fxiyj[i-1,j] >= Fxiyj[i,j-1]:
  243. przyrownanie1.append(seq1[i-1])
  244. przyrownanie2.append('-')
  245. print(i,j)
  246. i -= 1
  247. else:
  248. print("Coś poszło nie tak")
  249. break
  250. nrpetli += 1
  251. print(przyrownanie1[::-1])
  252. print(przyrownanie2[::-1])
  253. --------------------------------------------------------------------------------------------------------------------------------------
  254. import requests ## url, strony www
  255. import wget ## adresy url
  256. import bs4
  257. listPDF = list()
  258. date = 'May'
  259. url = 'https://bmcsystbiol.biomedcentral.com/articles'
  260. page1 = requests.get(url, verify=True).text
  261. soup = bs4.BeautifulSoup(page1, 'html.parser')
  262. z =soup.find_all('li', { 'class': 'c-list-group__item'})
  263. #print(z)
  264. x = ''
  265. for link in soup.find_all('li', { 'class': 'c-list-group__item'}):
  266. if( date in str(link) ):
  267. for podlink in link.find_all('a'):
  268. x = str(podlink)
  269. if('/track/pdf' in podlink.get('href')):
  270. #print( podlink.get('href') )
  271. listPDF.append('https://bmcsystbiol.biomedcentral.com' + podlink.get('href') )
  272. print(listPDF)
  273. MyNameFolder = 'C:\\Users\\Ziemek\\PycharmProjects\\ZadaniaSamorealizacja'
  274. for a in listPDF:
  275. wget.download(a, '.pdf')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement