2016-12-20 15 views
3

パブされた記事を保存して読むのに問題があります。私はこのページでhereを見ましたが、特殊なファイルタイプがいくつかありますが、そのうちのどれも私のために働いていませんでした。データを取得するためにキーを使用し続けることができるように、それらを保存します。私はテキストファイルとして保存すれば可能かどうかわかりません。私のコードは、このいずれかになります。pubmed記事をダウンロードして読み込む方法は?

import sys 
from Bio import Entrez 
import re 
import os 
from Bio import Medline 
from Bio import SeqIO 

'''Class Crawler is responsable to browse the biological databases 
from DownloadArticles import DownloadArticles 
c = DownloadArticles() 
c.articles_dataset_list 
''' 
class DownloadArticles(): 
    def __init__(self): 
     Entrez.email='[email protected]' 
     self.dataC = self.saveArticlesFilesInXMLMode('pubmed', '26837606') 

    '''Metodo 4 ler dado em forma de texto.''' 
    def saveArticlesFilesInXMLMode(self,dbs, ids): 
     net_handle = Entrez.efetch(db=dbs, id=ids, rettype="medline", retmode="txt") 
     directory = "/dataset/Pubmed/DatasetArticles/"+ ids + ".fasta" 
     # if not os.path.exists(directory): 
     # os.makedirs(directory) 
     # filename = directory + '/' 
     # if not os.path.exists(filename): 
     out_handle = open(directory, "w+") 
     out_handle.write(net_handle.read()) 
     out_handle.close() 
     net_handle.close() 
     print("Saved") 
     print("Parsing...") 
     record = SeqIO.read(directory, "fasta") 
     print(record) 
     return(record.read()) 

私はこのエラーを取得しています:ValueError: No records found in handle ピーズの誰かが私を助けることができますか?


今私のコードは次のようであるあなたがやったように、私は.fastaに保存する機能をやろうとしています。そして、上記の答えのようなファイル.fastaを読んでください。

import sys 
from Bio import Entrez 
import re 
import os 
from Bio import Medline 
from Bio import SeqIO 

def save_Articles_Files(dbName, idNum, rettypeName): 
    net_handle = Entrez.efetch(db=dbName, id=idNum, rettype=rettypeName, retmode="txt") 
    filename = path + idNum + ".fasta" 
    out_handle = open(filename, "w") 
    out_handle.write(net_handle.read()) 
    out_handle.close() 
    net_handle.close() 
    print("Saved") 
enter code here 

Entrez.email='[email protected]' 
dbName = 'pubmed' 
idNum = '26837606' 
rettypeName = "medline" 
path ="/run/media/Dropbox/codigos/Codes/"+dbName 
save_Articles_Files(dbName, idNum, rettypeName) 

しかし、私の機能は機能していません。何か助けてください!

答えて

3

2つのコンセプトが混在しています。

1)Entrez.efetch()は、NCBIにアクセスするために使用されます。あなたのケースでは、Pubmedから記事をダウンロードしています。あなたがnet_handle.read()から取得した結果は次のようになります。

PMID- 26837606 
OWN - NLM 
STAT- In-Process 
DA - 20160203 
LR - 20160210 
IS - 2045-2322 (Electronic) 
IS - 2045-2322 (Linking) 
VI - 6 
DP - 2016 Feb 03 
TI - Exploiting the CRISPR/Cas9 System for Targeted Genome Mutagenesis in Petunia. 
PG - 20315 
LID - 10.1038/srep20315 [doi] 
AB - Recently, CRISPR/Cas9 technology has emerged as a powerful approach for targeted 
     genome modification in eukaryotic organisms from yeast to human cell lines. Its 
     successful application in several plant species promises enormous potential for 
     basic and applied plant research. However, extensive studies are still needed to 
     assess this system in other important plant species, to broaden its fields of 
     application and to improve methods. Here we showed that the CRISPR/Cas9 system is 
     efficient in petunia (Petunia hybrid), an important ornamental plant and a model 
     for comparative research. When PDS was used as target gene, transgenic shoot 
     lines with albino phenotype accounted for 55.6%-87.5% of the total regenerated T0 
     Basta-resistant lines. A homozygous deletion close to 1 kb in length can be 
     readily generated and identified in the first generation. A sequential 
     transformation strategy--introducing Cas9 and sgRNA expression cassettes 
     sequentially into petunia--can be used to make targeted mutations with short 
     indels or chromosomal fragment deletions. Our results present a new plant species 
     amenable to CRIPR/Cas9 technology and provide an alternative procedure for its 
     exploitation. 
FAU - Zhang, Bin 
AU - Zhang B 
AD - Chongqing Engineering Research Centre for Floriculture, Key Laboratory of 
     Horticulture Science for Southern Mountainous Regions, Ministry of Education, 
     College of Horticulture and Landscape Architecture, Southwest University, 
     Chongqing 400716, China. 
FAU - Yang, Xia 
AU - Yang X 
AD - Chongqing Engineering Research Centre for Floriculture, Key Laboratory of 
     Horticulture Science for Southern Mountainous Regions, Ministry of Education, 
     College of Horticulture and Landscape Architecture, Southwest University, 
     Chongqing 400716, China. 
FAU - Yang, Chunping 
AU - Yang C 
AD - Chongqing Engineering Research Centre for Floriculture, Key Laboratory of 
     Horticulture Science for Southern Mountainous Regions, Ministry of Education, 
     College of Horticulture and Landscape Architecture, Southwest University, 
     Chongqing 400716, China. 
FAU - Li, Mingyang 
AU - Li M 
AD - Chongqing Engineering Research Centre for Floriculture, Key Laboratory of 
     Horticulture Science for Southern Mountainous Regions, Ministry of Education, 
     College of Horticulture and Landscape Architecture, Southwest University, 
     Chongqing 400716, China. 
FAU - Guo, Yulong 
AU - Guo Y 
AD - Chongqing Engineering Research Centre for Floriculture, Key Laboratory of 
     Horticulture Science for Southern Mountainous Regions, Ministry of Education, 
     College of Horticulture and Landscape Architecture, Southwest University, 
     Chongqing 400716, China. 
LA - eng 
PT - Journal Article 
PT - Research Support, Non-U.S. Gov't 
DEP - 20160203 
PL - England 
TA - Sci Rep 
JT - Scientific reports 
JID - 101563288 
SB - IM 
PMC - PMC4738242 
OID - NLM: PMC4738242 
EDAT- 2016/02/04 06:00 
MHDA- 2016/02/04 06:00 
CRDT- 2016/02/04 06:00 
PHST- 2015/09/21 [received] 
PHST- 2015/12/30 [accepted] 
AID - srep20315 [pii] 
AID - 10.1038/srep20315 [doi] 
PST - epublish 
SO - Sci Rep. 2016 Feb 3;6:20315. doi: 10.1038/srep20315. 

2)SeqIO.read()FASTA filesを読み、解析するために使用されます。これはシーケンスの保存に使用されるフォーマットです。 FASTA形式のシーケンスは、一連の行として表されます。 FASTAファイルの最初の行は、 ">"(より大きい)記号で始まります。最初の行(シーケンスの固有の記述に使用される)の後には、実際のシーケンス自体が標準の1文字コードで表示されます。

ご覧のとおり、Entrez.efetch()(私が上に貼り付けたもの)から返された結果はFASTAファイルのようには見えません。したがってSeqIO.read()は、ファイルにシーケンスレコードが見つからないというエラーを返します。

+0

どうすればこの出力を得ることができますか? – user2535338

+0

あなたはすでにこの出力を得るためのすべてのコードを持っています。私が書いたように、それは 'net_handle.read()'の出力です。 – BioGeek

+0

net_handle.read()を使ってこの出力を得るには – user2535338

関連する問題