ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/PrimerMatch/sts_io.cc
Revision: 1.1.1.1 (vendor branch)
Committed: Wed Dec 22 21:37:18 2004 UTC (11 years, 5 months ago) by nje01
Branch: MAIN
CVS Tags: HEAD, RELEASE-20041222, HEAD
Changes since 1.1: +0 -0 lines
Log Message:
Initial primer_match import

Line File contents
1 /**************************************************************************
2 * This code is part of the supporting infrastructure for ATA Mapper.
3 * Copyright (C) 2002,2003,2004 Applera Corporation. All rights reserved.
4 * Author: Nathan Edwards
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received (LICENSE.txt) a copy of the GNU General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *************************************************************************/
20
21
22 #include "sts_io.h"
23 #include <ctype.h>
24 #include <iostream>
25 #include <assert.h>
26 #include "util.h"
27
28 #if !defined(NO_STD_NAMESPACE)
29 using namespace std;
30 #endif
31
32 void sts_entry::read(istream & is) {
33 // 8K buffer sufficient for a single line? Hope so.
34 static unsigned long BUFLEN = 1024*8;
35 static char *buffer = new char[BUFLEN];
36 static char *buffer1 = new char[BUFLEN];
37 std::string size;
38 is.getline(buffer,BUFLEN-2,'\n');
39 if (is.gcount() >= BUFLEN-2) {
40 timestamp("STS line too long!\n");
41 exit(1);
42 }
43 buffer[is.gcount()] = '\0';
44 istrstream iss(buffer);
45 iss >> id_
46 >> forward_primer_
47 >> reverse_primer_
48 >> size
49 >> acc_
50 >> chrom_
51 >> altacc_;
52 std::string::size_type p;
53 if ((p=size.find("-"))!=std::string::npos) {
54 sizelb_ = atoi(size.substr(0,p).c_str());
55 sizeub_ = atoi(size.substr(p+1).c_str());
56 } else {
57 sizelb_ = sizeub_ = atoi(size.c_str());
58 }
59 // scoop up rest of line...
60 iss.getline(buffer1,BUFLEN-1,'\n');
61 assert(iss.gcount() < BUFLEN-1);
62 buffer1[iss.gcount()] = '\0';
63 species_ = buffer1;
64 }
65
66 void sts_entry::write(ostream & os) const {
67 os << id_ << '\t'
68 << forward_primer_ << '\t'
69 << reverse_primer_ << '\t';
70 if (sizelb_ == sizeub_) {
71 os << sizelb_ << '\t';
72 } else {
73 os << sizelb_ << "-" << sizeub_ << '\t';
74 }
75 os << acc_ << '\t'
76 << chrom_ << '\t'
77 << altacc_ << '\t'
78 << species_ << endl;
79 }
80
81 void sts_entry::uppercase() {
82 for (int i=0;i<forward_primer_.length();i++) {
83 if (forward_primer_[i] >= 'a' && forward_primer_[i] <= 'z') {
84 forward_primer_[i] = toupper(forward_primer_[i]);
85 }
86 }
87 for (int i=0;i<reverse_primer_.length();i++) {
88 if (reverse_primer_[i] >= 'a' && reverse_primer_[i] <= 'z') {
89 reverse_primer_[i] = toupper(reverse_primer_[i]);
90 }
91 }
92 }
93
94 void sts_entry::lowercase() {
95 for (int i=0;i<forward_primer_.length();i++) {
96 if (forward_primer_[i] >= 'a' && forward_primer_[i] <= 'z') {
97 forward_primer_[i] = toupper(forward_primer_[i]);
98 }
99 }
100 for (int i=0;i<reverse_primer_.length();i++) {
101 if (reverse_primer_[i] >= 'a' && reverse_primer_[i] <= 'z') {
102 reverse_primer_[i] = toupper(reverse_primer_[i]);
103 }
104 }
105 }
106
107 ostream & operator<<(ostream & os, sts_entry const & fe) {
108 fe.write(os);
109 return os;
110 }
111 istream & operator>>(istream & is, sts_entry & fe) {
112 fe.read(is);
113 return is;
114 }