└── convert.php /convert.php: -------------------------------------------------------------------------------- 1 | _genetic_map = array( ); 11 | $this->_genetic_map_name = ""; 12 | $this->_cytoBand_hg19 = array( ); 13 | $this->_knownGene_hg19 = array( ); 14 | $this->_kgXref_hg19 = array( ); 15 | $this->resources_dir="resources"; 16 | } 17 | public function _load_genetic_map_HapMapII_GRCh37($filename){ 18 | $genetic_map = array( ); 19 | $archive = new PharData($filename); 20 | foreach($archive as $file) { 21 | if (strpos("genetic_map",$file["name"])===true){ 22 | $df = array( ); 23 | if (($handle = fopen($file, "r")) !== FALSE) { 24 | while (($data = fgetcsv($handle,"\t")) !== FALSE) { 25 | $df["Position(bp)"]=$data["pos"]; 26 | $df["Rate(cM/Mb)"]=$data["rate"]; 27 | $df["Map(cM)"]=$data["map"]; 28 | } 29 | fclose($handle); 30 | } 31 | $start_pos = strpos($file["name"],"chr") + 3; 32 | $end_pos = strpos($file["name"],"."); 33 | $genetic_map[substr($file["name"],$start_pos,$end_pos)] = $df; 34 | } 35 | } 36 | $genetic_map["X"] = array_merge( 37 | $genetic_map["X_par1"], $genetic_map["X"], $genetic_map["X_par2"] 38 | ); 39 | $genetic_map["X_par1"]=array( ); 40 | $genetic_map["X_par2"]=array( ); 41 | return $genetic_map; 42 | } 43 | 44 | public function _download_file($url, $filename, $compress=False, $timeout=30){ 45 | if(strpos($url, "ftp://") !== false) { 46 | $url=str_replace($url,"ftp://", "http://"); 47 | } 48 | if ($compress && substr($filename,strlen($filename)-3,strlen($filename)) != ".gz"){ 49 | $filename = $filename+".gz"; 50 | } 51 | $destination = join($this->resources_dir, $filename); 52 | 53 | if (!mkdir($destination)){ 54 | return ""; 55 | } 56 | if (file_exists($destination)){ 57 | $file_url = $destination; 58 | header('Content-Type: application/octet-stream'); 59 | header('Content-Description: File Transfer'); 60 | header('Content-Disposition: attachment; filename=' . $filename); 61 | header('Expires: 0'); 62 | header('Cache-Control: must-revalidate'); 63 | header('Pragma: public'); 64 | header('Content-Length: ' . filesize($file_url)); 65 | readfile($file_url); 66 | 67 | // if $compress 68 | // $this->_write_data_to_gzip(f, data) 69 | // else 70 | // f.write(data) 71 | } 72 | return $destination; 73 | } 74 | 75 | 76 | public function get_all_resources(){ 77 | $resources = array( ); 78 | $resources[ 79 | "genetic_map_HapMapII_GRCh37" 80 | ] = $this->get_genetic_map_HapMapII_GRCh37(); 81 | $resources["cytoBand_hg19"] = $this->get_cytoBand_hg19(); 82 | $resources["knownGene_hg19"] = $this->get_knownGene_hg19(); 83 | $resources["kgXref_hg19"] = $this->get_kgXref_hg19(); 84 | return $resources; 85 | } 86 | public function download_example_datasets(){ 87 | return [ 88 | $this->_download_file( 89 | "https://opensnp.org/data/662.23andme.340", 90 | "662.23andme.340.txt.gz", 91 | $compress=True 92 | ), 93 | $this->_download_file( 94 | "https://opensnp.org/data/662.ftdna-illumina.341", 95 | "662.ftdna-illumina.341.csv.gz", 96 | $compress=True 97 | ), 98 | $this->_download_file( 99 | "https://opensnp.org/data/663.23andme.305", 100 | "663.23andme.305.txt.gz", 101 | $compress=True 102 | ), 103 | $this->_download_file( 104 | "https://opensnp.org/data/4583.ftdna-illumina.3482", 105 | "4583.ftdna-illumina.3482.csv.gz" 106 | ), 107 | $this->_download_file( 108 | "https://opensnp.org/data/4584.ftdna-illumina.3483", 109 | "4584.ftdna-illumina.3483.csv.gz" 110 | ), 111 | ]; 112 | } 113 | } 114 | 115 | ?> 116 | --------------------------------------------------------------------------------