Thursday, May 9, 2013

try in a loop #R

If you know there could be and error use try

if it is in a loop and you need to keep going, next!

m <- try(read.table(f, head=FALSE, sep="\t"))
if(class(m) == "try-error") next

compare two files! #shell

Excellent!



#in file 1 but not in file 2 

diff --changed-group-format='%<' --unchanged-group-format='' file1 file2 > output 

#in file 2 but not in file 1
 
diff --changed-group-format='%>' --unchanged-group-format='' file1 file2 > output
 


#Common in both files
diff --changed-group-format='' --unchanged-group-format='%=' file1 file2 > output



From -> linux questions

Wednesday, May 8, 2013

bedtools

https://github.com/arq5x/bedtools/blob/master/docs/content/general-usage.rst

Tuesday, May 7, 2013

substring in list #python

if any("abc" in s for s in some_list):
    # whatever
 
 
to get all the items containing "abc", use
matching = [s for s in some_list if "abc" in s]
 
http://stackoverflow.com/questions/4843158/check-in-python-if-a-list-item-contains-a-string 

extract a group of fasta sequences from a file

extract a group of fasta sequences from a file
in python
http://www.biostars.org/p/1709/

from Bio import SeqIO

fasta_file = "fasta_file.fasta" # Input fasta file
wanted_file = "wanted_file.txt" # Input interesting sequence IDs, one per line
result_file = "result_file.fasta" # Output fasta file

wanted = set()
with open(wanted_file) as f:
    for line in f:
        line = line.strip()
        if line != "":
            wanted.add(line)

fasta_sequences = SeqIO.parse(open(fasta_file),'fasta')
with open(result_file, "w") as f:
    for seq in fasta_sequences:
        if seq.id in wanted:
            SeqIO.write([seq], f, "fasta")

grep OR AND etc

OR
grep -E 'pattern1|pattern2' filename
 
AND
 
grep -E 'pattern1.*pattern2' filename 
 
 
http://www.thegeekstuff.com/2011/10/grep-or-and-not-operators/ 

UniProtKB/Swiss-Prot

 UniprotKB Protein knowledgebase, consists of two sections:
  • Swiss-Prot, which is manually annotated and reviewed.
  • TrEMBL, which is automatically annotated and is not reviewed.
Includes complete and reference proteome sets.


UniProtKB/Swiss-Prot is the manually annotated and reviewed section of the UniProt Knowledgebase (UniProtKB).
documentation

Downloads > http://www.uniprot.org/downloads

 UniProt Knowledgebase (UniProtKB) Release 
2013_05 (01-May-2013)
UniProtKB/Swiss-Prot: 540,052 entries 
 
release notes 1st of May 2013 >
 ftp://ftp.uniprot.org/pub/databases/uniprot/relnotes.txt 
 
http://web.expasy.org/docs/relnotes/relstat.html