반응형

log 파일 작성 모듈 logging.

 

import logging

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('[%(levelname)s %(asctime)s] %(message)s',"%Y-%m-%d %H:%M:%S")

stream_handler = logging.StreamHandler()
stream_handler.setFormatter(formatter)
stream_handler.setLevel(logging.INFO)
logger.addHandler(stream_handler)

file_handler = logging.FileHandler(f'my.log')
file_handler.setFormatter(formatter)
file_handler.setLevel(logging.DEBUG)
logger.addHandler(file_handler)

logging.info(f'Read Database File')
logging.debug(f'Read Database File')

 

handler를 여러 개 만들어서 하나는 stdout 다른 하나는 my.log 파일로 만들고 level에 따라 출력 범위를 다르게 조절한다.

 

위의 예시에서는 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL', 중에 debug는 파일로만 생성되도록 설정되었다.

 

개발 단계에서는 stream_handler를 DEBUG로 놓고 진행하다가 개발 완료시 INFO로 수정하면 원하는 부분만 출력하도록 조정 가능하다.

 

a = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0].decode('UTF-8')
logging.debug(f'{cmd}\n{a}')

subprocess와 연결해서 command를 입력하고 나오는 출력물까지 debug로 한 번에 연결 할 수 있다.

반응형

'Computer Science > python' 카테고리의 다른 글

Progress bar 모듈 tqdm  (0) 2022.03.07
pandas 활용하기  (0) 2022.02.18
f-string을 활용한 regex 사용법  (0) 2022.02.15
Primer 서열 분석을 위한 python 코드  (0) 2021.08.17
String Format으로 길이 고정하기  (0) 2020.06.24
반응형

 

read 서열에서 error를 1이하로 허용하는 내에 BESTMATCH를 찾아 시작과 종료지점 그리고 매치되는 서열을 확인하는 코드. error는 mismatch, insertion, deletion을 의미한다.

 

import regex

primer_seq, read_seq

regex_primer_seq = fr'({primer_seq}{{e<=1}})'
match_object = regex.search(regex_primer_seq, read_seq, regex.BESTMATCH)

match_start, match_end = match_object.span()
match_seq = match_object.captures()
반응형

'Computer Science > python' 카테고리의 다른 글

pandas 활용하기  (0) 2022.02.18
logging 모듈 사용하기  (0) 2022.02.17
Primer 서열 분석을 위한 python 코드  (0) 2021.08.17
String Format으로 길이 고정하기  (0) 2020.06.24
python multi-level argparse  (0) 2019.07.12
반응형

anaconda의 버전 업데이트 후 아래와 같은 에러 발생

Collecting package metadata (current_repodata.json): failed

ProxyError: Conda cannot proceed due to an error in your proxy configuration.
Check for typos and other configuration errors in any '.netrc' file in your home directory,
any environment variables ending in '_PROXY', and any other system-wide proxy
configuration settings.

 

https://github.com/conda/conda/issues/9497 페이지에서 확인해보니 urllib3 의 버전 변경으로 인한 문제로 보임.

 

conda config --set ssl_verify False

위 명령어를 작성하면 .condarc 파일이 home directory 밑에 생성되는데 파일을 아래와 같이 수정한다

 

ssl_verify: False
proxy_servers:
  https: http://[PROXY]:[PORT]/

 

https: https: 에서 https: http로의 변경.

반응형

'Computer Science > linux' 카테고리의 다른 글

centos 8에 slurm 설치하기  (0) 2022.05.11
conda 채널 추가  (0) 2022.02.22
Jupyter notebook 설정  (0) 2020.11.03
Centos yum repo 변경  (0) 2020.08.03
github로 스크립트 관리하기 AtoZ  (0) 2020.07.29
반응형

NGS 데이터에서 adapter 서열과 primer 서열에 따른 read 분류.

 

아래는 pseudo code 이므로 적절한 변환이 필요하다.

import regex

#ambiguous base list
ambiguous_base_dic = {"N":"ATGC","R":"AG","Y":"TC","K":"GT","M":"AC","S":"GC","W":"AT","B":"CGT","D":"AGT","H":"ACT","V":"ACG"}

#if ambiguous base occured, change to regular expression format
for word, initial in ambiguous_dic.items():
	primer_f = primer_f.replace(word, "["+initial+"]")
    
#index sequences are allowed one mismatch
primer = r"(^{0})".format(primer_f)+"{e<=1}"

#if primer sequence is inside sequence, print out.
if regex.findall(primer, sequence):
	print(sequence)

 

 

 

반응형

'Computer Science > python' 카테고리의 다른 글

logging 모듈 사용하기  (0) 2022.02.17
f-string을 활용한 regex 사용법  (0) 2022.02.15
String Format으로 길이 고정하기  (0) 2020.06.24
python multi-level argparse  (0) 2019.07.12
python 파일 입출력  (0) 2019.07.12
반응형

$jupyter notebook --no-browser --port=8888

명령어로 jupyter notebook 실행. 아래 화면으로 정상 실행됨과 포트를 확인.

 

$ jupyter notebook --no-browser --port=8888
[I 16:25:24.807 NotebookApp] Serving notebooks from local directory: 
[I 16:25:24.807 NotebookApp] Jupyter Notebook 6.1.4 is running at:
[I 16:25:24.807 NotebookApp] http://localhost:8888/
[I 16:25:24.807 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

 

1. PuTTY

 

2. XShell

 

수신대상서버의 port = jyupter 실행 port

remote 서버의 port = 사용자 pc에서의 port

 

위와 같은 설정이라면 브라우져에서 http://localhost:8889 일때 실행 가능함.

 

jupyter notebook 실행시 나오는 링크는 8888로 설정되어있기 때문에 두 포트 넘버를 같게 하는게 편함.

 

 

반응형

'Computer Science > linux' 카테고리의 다른 글

conda 채널 추가  (0) 2022.02.22
conda proxy 에러 해결방법  (0) 2022.02.07
Centos yum repo 변경  (0) 2020.08.03
github로 스크립트 관리하기 AtoZ  (0) 2020.07.29
Linux hosts 파일 변경  (0) 2020.07.14
반응형

local 설치를 위해서 또는 공유되는 폴더에 설치하기 위해서 perl module 다운로드시 CPAN의 install dir 설정을 변경하고 PERL5LIB이 이 폴더를 잡도록 설정한다.

 

$ cpan
cpan[3]> o conf init
cpan[4]> o conf makepl_arg INSTALL_BASE=/DIR/To/INSTALL/PERL
cpan[5]> exit

 

export PERL5LIB=/DIR/To/INSTALL/PERL/lib/perl5:$PERL5LIB

 

CPAN으로 모듈을 install 하면 자동으로 인식함.

반응형
반응형

국내 미러사이트 중 하나인 daum으로 변경하는 법.

 

현재 적용중인 repolist 확인.

yum repolist

 

기존 repolist는 압축하여 사용 안하도록 설정.

bzip2 /etc/yum.repos.d/CentOS-*.repo 

 

/etc/yum.repos.d/Daum.repo 생성하기.

[base]
name=CentOS-$releasever - Base
baseurl=http://ftp.daumkakao.com/centos/$releasever/os/$basearch/
gpgcheck=0
[updates]
name=CentOS-$releasever - Updates
baseurl=http://ftp.daumkakao.com/centos/$releasever/updates/$basearch/
gpgcheck=0
[extras]
name=CentOS-$releasever - Extras
baseurl=http://ftp.daumkakao.com/centos/$releasever/extras/$basearch/
gpgcheck=0
반응형

'Computer Science > linux' 카테고리의 다른 글

conda proxy 에러 해결방법  (0) 2022.02.07
Jupyter notebook 설정  (0) 2020.11.03
github로 스크립트 관리하기 AtoZ  (0) 2020.07.29
Linux hosts 파일 변경  (0) 2020.07.14
hostname 변경  (0) 2020.07.14
반응형

우선 당연하게도 https://github.com 에서 신규 가입을 해야한다.

모든 데이터를 저장/불러오기 할 때 Username과 Email이 필요하기때문에 본인임을 확인할 수 있는 계정으로 생성한다.

https://github.com

 

계정이 생성되면 저장소(repository)를 생성해야한다. 동시에 여러 개의 저장소를 만들 수 있기 때문에 규모가 크다면 프로젝트별로, 작다면 하나의 저장소 안에 폴더를 나누어 저장하는 것이 좋다.

 

Repository name이 앞으로 사용할 저장소 이름이다.

 

외부 인원이 접근하지 못하도록 Private로 설정하고 필요에 따라 README 파일 생성에 체크를 하도록 한다.

 

위와 같이 README가 포함된 저장소가 생성되었다.

 

저장소가 생성되었으니 리눅스 서버에서 스크립트를 저장하는 방법을 설명하겠다.

 

 

테스트를 위해 임의의 디렉토리 test를 생성하였다.

$ mkdir /test
$ cd /test
$ pwd
/test

 

생성된 폴더를 git 저장소로 사용하기위해 git init 명령어를 입력한다. 앞으로 해당 폴더 내에서 이뤄지는 변경사항을 저장할 수 있게 되었다. 그리고 테스트를 위한 새로운 파일 test.txt를 생성하였다.

$ git init
/test/.git/
$ touch test.txt
$ ll
total 0
-rw-r--r-- 1 root root 0 Jul 29 14:32 test.txt

 

git add test.txt는 test.txt 파일을 commit기위해 선별하는 과정이다. 저장소에 디렉토리내의 모든 파일을 저장하는 것이 아니고 선택된 파일들만 저장하기때문에 단계가 나뉘어져있다. 

 

불편해 보일 수 있지만 github의 장점이 버전관리임을 생각하면 매 번 모든 파일을 업데이트하는것은 오히려 불필요하다는 것을 알 수 있다. 물론 원한다면 -a 옵션을 사용하요 한 번에 모두 업데이트 할 수 있다.

 

git commit -m "test"는 add 명령어로 선택된 파일들을 하나의 패키지로 묶어준다. -m 은 묶음에 메모를 남기는 것이다.

$ git add test.txt
$ git commit -m "test"
[master (root-commit) 6c12673] test
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test.txt
$ git status
# On branch master
nothing to commit, working directory clean

 

저장소에 대한 업데이트가 필요하다. 앞으로 사용되는 "test" 라는 변수는 아래의 주소를 가리키게 될 것이다.

저장소를 새롭게 만들때마다 아래와 같은 작업이 최소 1회 필요하다.

git remote add test https://github.com/[UserName]/test

 

업로드를 하기 전에 git pull을 먼저 해야한다. 기존 저장소의 파일과 동기화가 이루어져야 업로드 할 수 있기 때문이다.

이 과정을 무시하고 싶다면 push과정에서 -f로 강제로 업로드 하는 방법이 있지만 추천하지 않는다.

$ git pull test master
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 README.md | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 README.md

 

이제 test.txt파일을 포함하고있는 commit을 웹 저장소에 올려보자. git push test를하면 위에서 정의한 test 저장소에 commit을 업로드 한다.

git push test

 

test.txt파일이 업로드 된 것을 확인할 수 있다.

 

반응형

'Computer Science > linux' 카테고리의 다른 글

Jupyter notebook 설정  (0) 2020.11.03
Centos yum repo 변경  (0) 2020.08.03
Linux hosts 파일 변경  (0) 2020.07.14
hostname 변경  (0) 2020.07.14
Google Cloud SDK linux 설치  (0) 2020.05.26
반응형

/etc/hosts 파일 내에서 변경.

 

127.0.0.1 localhost.localdomain localhost 
::1 localhost6.localdomain6 localhost6 
8.8.8.8 testhost

 

파일 수정 후 곧 바로 적용된다.

 

ssh testhost 처럼 입력해도 ip 8.8.8.8 로 접속하게 된다.

반응형
반응형
#CentOS 6 
[root@localhost ~]# vi /etc/sysconfig/network 
HOSTNAME=myhost 

#CentOS 7 
[root@localhost ~]# hostnamectl set-hostname myhost

변경 후 ssh 재접속.

반응형

+ Recent posts